# The Architecture of an Agricultural Data Aggregation and Conversion Model for Smart Farming
## 3 Data Aggregation and Conversion Model
The platform architecture is supplemented with a component for the formation of a unified data structure. The component, upon receiving a new data file, forms a _DataFrame_ object into which it calculates the necessary data, transforms its structure, and arranges it in order. The component performs data transformation using mathematical models capable of detecting data which are of the required type but structurally different, using the Python Pandas library (for agro-data manipulation and the grouping and processing of _DataFrame_ objects). Aggregated and transformed  
Figure 1: Agricultural data exchange scheme. DataFrame objects are each placed in their allocated space in a separate database, thus ensuring that all data are used in a unified format for further calculations. The source code (Figure 2a) provides an example of how to determine the type of work from an uploaded file based on the formats provided by different manufacturers. The format change uses the _Python_ programming language [36] and its libraries, which provide the ability to read, write, and process vectors and, if required, raster geographic data. In a particular case, the built-in Python function _\"enumerate\"_ is used to begin iterating and to keep track of activity conducted while iterating through the data array. In a given code part, an _\"if\"_ cycle performs iterations through sowing, fertilizing, spraying, or harvest according to variables _seed, fort, chem_, and _grain_, respectively. A few cycles are created that individually check if the action can be assigned to a farm operation (_seed, fort, chem_, and _grain_). After matching the data from the different data arrays, the work and logic assignment cycle is completed. Otherwise, a further check is conducted to see if the job remains unassigned. The database is supplemented with processed information from external data sources. One of the external sources is represented by satellite data, which are processed before being placed in the database. From the multispectral data collected by the satellite, various vegetation indexes are calculated such as NDVI, MCARI, and LAI [37]. The indexes are generated using the raster data processing library of the _Python_ programming language and the GDAL spatial data processing library. Figure 2: Parts of source code for (**a**) setting the working type of the uploaded file (where seed, fort, chem, and grain are variables representing agricultural operating materials; sowing, fertilizing, spraying, and harvest are variables representing agriculture processes; and w is a variable representing the volume, mass, and flow rate of an agricultural operating material); (**b**) field spatial analysis (where schema represent the initial geometry data of the field; input_crs represents the tractor/machine indicator; driver represents the driver/operator indicator; new_schema represents the updated geometry of the field; k and v represent the field’s geometrical parameters; float, str, and date represent the field coverage, saturation, and operation date, respectively). The data in the database are used to build and further develop data analysis models. These developed models generate reports for farmers as well as maps for farmers. Using maps uploaded by farmers, a temporal analysis of the fields is carried out and a report is generated. The temporal analysis is performed using _PostGIS_ spatial analysis functions as follows: the perimeters of areas and fields are subtracted, collecting fields in the same area that were created at different times. The _\"fiona\"_ module in _Python_ is used to interface geographic information systems (GISs) with a _web user interface_ (Figure 2b). First, the directory is opened, and data are imported (_scheme, input_, and _driver_). A new geometric scheme is created based on these data. Then, a _\"for\"_ cycle is initiated for each imported element, which creates a new map element and set the following parameters of the map element: float, str, and date.