An ASAE Meeting Presentation Paper Number: 053012
Programming ArcGIS to Generate Crop Model Input Files for Spatial Simulations K. R. Thorp, Graduate Research Assistant W. D. Batchelor, Professor J. O. Paz, Assistant Scientist 124 Davidson Hall Iowa State University Ames, IA 50011
[email protected]
Written for presentation at the 2005 ASAE Annual International Meeting Sponsored by ASAE Tampa Convention Center Tampa, Florida 17 - 20 July 2005 Abstract. In order to use crop model simulations for studying precision management of crop production inputs, model input parameters must be defined uniquely for each management zone in the field. Since some fields can be split into hundreds or thousands of management zones, productivity can be limited by the time required to manually manipulate geospatial data within a geographic information system (GIS), extract necessary model parameters for each management zone, and develop model input files for spatial simulations. In this work, several software tools were generated to accomplish these tasks automatically. Tools were created within the Visual Basic for Applications (VBA) environment of the ArcMap component of ArcGIS using ArcObjects, the ArcGIS component object model. The tools allow a user to establish a management zone grid over a field area, clip digital soil surveys and yield monitor data according to the management zone grid, and print soil and yield information for each management zone in the proper format for interpretation by the crop model. The software effectively reduces the amount of time necessary to generate crop model input files for simulations on the sub-field-level scale. The authors are solely responsible for the content of this technical presentation. The technical presentation does not necessarily reflect the official position of the American Society of Agricultural Engineers (ASAE), and its printing and distribution does not constitute an endorsement of views which may be expressed. Technical presentations are not subject to the formal peer review process by ASAE editorial committees; therefore, they are not to be presented as refereed publications. Citation of this work should state that it is from an ASAE meeting paper. EXAMPLE: Author's Last Name, Initials. 2005. Title of Presentation. ASAE Paper No. 05xxxx. St. Joseph, Mich.: ASAE. For information about securing permission to reprint or reproduce a technical presentation, please contact ASAE at
[email protected] or 269-429-0300 (2950 Niles Road, St. Joseph, MI 49085-9659 USA).
Keywords. crop modeling, geographic information systems, spatial variation
The authors are solely responsible for the content of this technical presentation. The technical presentation does not necessarily reflect the official position of the American Society of Agricultural Engineers (ASAE), and its printing and distribution does not constitute an endorsement of views which may be expressed. Technical presentations are not subject to the formal peer review process by ASAE editorial committees; therefore, they are not to be presented as refereed publications. Citation of this work should state that it is from an ASAE meeting paper. EXAMPLE: Author's Last Name, Initials. 2005. Title of Presentation. ASAE Paper No. 05xxxx. St. Joseph, Mich.: ASAE. For information about securing permission to reprint or reproduce a technical presentation, please contact ASAE at
[email protected] or 269-429-0300 (2950 Niles Road, St. Joseph, MI 49085-9659 USA).
Introduction Crop growth models are useful tools for analyzing daily plant growth within homogeneous areas, and they have been successfully utilized on both field-level and regional scales. With the advent of precision farming, efforts have focused on strategies for utilization of crop models on a sub-field-level scale (Batchelor et al., 2002). For example, several studies have investigated the use of crop models for developing economically optimum prescriptions for crop production inputs (Paz et al., 1999; Paz et al., 2001; Paz et al., 2003). To facilitate this practice, Batchelor et al. (2004) have developed the Apollo decision support system for implementing the DSSAT family of crop growth models to generate recommendations for site-specific management of crop production inputs. The Apollo system initiates crop model simulations separately for unique management zones within the field, each of which can have varying soil properties, management strategies, and yield history. Thus, model input parameters must be defined uniquely for each management zone in the field. Since some fields can potentially be split into hundreds or thousands of management zones, a large amount of time is typically required in order to manually organize crop model input data, manipulate spatial data within a geographic information system (GIS), and prepare crop model input files for spatial simulations. Automation of this process is necessary to eliminate the monotony of manual crop model input file creation. In this work, several software tools were generated to manipulate spatial data within ArcGIS 9 and to output crop model input files automatically. The tools allow a user to establish a management zone grid over the field area, clip digital soil surveys and yield monitor data according to management zone boundaries, and print soil and yield information for each management zone in the proper format for interpretation by the Apollo system. The software effectively reduces the amount of time necessary to generate crop model input files for simulations on the sub-field-level scale.
Materials and Methods The software tools were developed using the Visual Basic for Applications (VBA) platform contained within ArcMap, a component of ArcGIS 9. ArcObjects is the software development platform for the ArcGIS family of GIS software, and it is based on Microsoft’s Component Object Model (COM). With an understanding of ArcObjects, COM, and the VBA programming language, a third-party programmer can access the basic functionality of the ArcGIS software to customize applications for geospatial data processing. Specifically, the software tools designed in this work were written to automatically manipulate geospatial data layers for an agronomic field, extract appropriate geospatial information from the data layers, and print crop model input files for use with Apollo to make crop model simulations for precision agriculture applications.
Crop Growth Models The DSSAT crop growth models are a series of computer programs that simulate growth, development, and yield for a variety of crop species. Typical crop models utilize carbon, nitrogen, and water balance principles to simulate the processes that occur during the growth and development of plants within an agricultural system. Model simulations occur over homogeneous areas on a daily time step. Inputs required for model execution include management practices (plant genetics, plant population, row spacing, planting and harvest dates, and fertilizer application amounts and dates), environmental factors (soil type, drained upper limit, lower limit, saturated hydraulic conductivity), and weather conditions (daily minimum and maximum temperature, solar radiation, and precipitation). Because crop models operate over homogeneous areas, model simulations in the context of precision agriculture must be 2
executed independently for each management zone across the field. Given that many attributes of agricultural systems display observable spatial variability, model inputs can potentially be unique for each management zone. Since agricultural fields can be divided into hundreds or thousands of management zones, the use of crop models for precision agriculture applications can be hampered by the time commitment required to manage geospatial data and develop the appropriate input files for independent model simulations within each zone.
Apollo In spite of the time commitment for manual processing of geospatial data, the output of crop model simulations has been useful for answering questions in regards to precision management of crop production inputs. For this reason, researchers at Iowa State University have recently developed a new decision support software called Apollo (Batchelor et al., 2004). Apollo is a Visual Basic application that interfaces with the DSSAT crop models to automate model simulations for solving various problems in precision agriculture. Apollo can be used for calibration and validation of the DSSAT crop models on the sub-field-level scale. Up to ten model input parameters can be optimized automatically for several hundred management zones. To calibrate the model, an optimization algorithm has been implemented to solve for the parameter set that minimizes root mean squared error between measured and simulated yield in each management zone. The software utilizes the model calibration results in each zone to generate nitrogen and plant population prescriptions, to forecast yields, and to explain the causes of yield spatial variability across agricultural fields.
ArcGIS Before implementing Apollo for automating crop model simulations in a precision agriculture context, crop model input files must be prepared such that Apollo can feed the appropriate inputs to the model for independent simulations in each management zone. In the past, this has been accomplished by manually manipulating measured model parameters with GIS software and preparing crop model input files in a text editor. The aim of this work was to automate this process within ArcGIS. ArcGIS is a collection of software for building, manipulating, and maintaining a GIS. The software is maintained and distributed by the Environmental Systems Research Institute (ESRI). Included within ArcGIS are several software components, such as ArcMap, ArcCatalog, and ArcToolbox, designed for performing specific tasks associated with geospatial data. ArcMap provides functionality for creating, maintaining, editing, and analyzing maps of geospatial data. ArcCatalog provides data management tools for organizing geospatial data within a geodatabase. ArcToolbox provides functionality for common data conversion and geoprocessing tasks. These three components of ArcGIS offer many built-in functions for managing and manipulating geospatial data. However, when a complex series of data processing tasks must be performed or when certain processing tasks must be completed repetitively, the limitations of the built-in ArcGIS functions are quickly reached. In this case, it is essential to employ the VBA macro environment contained within ArcMap or ArcCatalog to customize geospatial data processing (Razavi, 2002).
ArcObjects and COM ArcObjects is the software development platform and technological framework of ArcGIS, and it is based on Microsoft’s Component Object Model (COM). The COM is a methodology for software development that facilitates software reuse; it is a protocol for developing selfcontained and reusable software components in binary language. Software components are typically stored in either dynamic link libraries (DLLs) or executable files. As a result, they offer
3
two advantages: programming language independence and location transparency. Programming language independence means that the functionality of a software component can be accessed from a variety of different programming languages. Location transparency means the software components can be accessed regardless of their location. Because ArcObjects is based on COM technology, it can be used within any COM-compliant development language, such as VBA, Visual Basic, and Visual C++, to develop custom ArcGIS applications. By understanding ArcObjects coding, a third-party programmer can access the full functionality contained within ArcGIS without needing access to the program’s source code. ESRI provides an object model diagram in the Unified Modeling Language (UML) for visualization of the objects, classes, relationships between classes, class interfaces, and interface details that are available within ArcObjects (Zeiler, 2001a; Zeiler, 2001b). Familiarity with this UML diagram is essential for learning how to properly access ArcObjects software components for developing custom geospatial data processing algorithms within VBA in ArcMap.
Software Tools The software tools developed in this work allow a user to establish a management zone grid over the field area, clip digital soil surveys and yield monitor data according to the management zone grid, and print soil and yield information for each management zone in the proper format for use with Apollo. Creating a management zone grid is the initial step for subdividing a study area into a user-defined number of equally-sized rectangular grids. This tool outputs a polygon shapefile to define grid-based management zones across the field. A clipping tool was created to subdivide layers of spatial data according to the management zone grid. For example, the clipping tool can be used to determine, from a digital soil survey, the soil type that dominates each management zone grid. The print tool takes the information from clipped layers and uses it to format a text file that can be interpreted by the Apollo software to feed unique model input parameters for each management zone into the crop model. The software tools become available on an ArcMap toolbar by opening the ArcMap template file in which the tools were created.
Management Zone Grid Creation Tool What methodology should be used for definition of management zones for precision agricultural applications? This is an intriguing question that has not yet been fully answered. To many researchers, precision agriculture means dividing the field into many smaller areas using a gridbased scheme. Others have considered using soil type, soil fertility, or topographic information to define management zones across the field. If a grid-based scheme is to be used, another research question of interest involves the optimum size and number of grids. Typically, in gridbased studies, the size and number of grids are assigned arbitrarily with no agronomic basis for this assignment. Crop modeling techniques can be used to study the effect of grid size on crop production, and this endeavor can be facilitated with the creation of a GIS tool to rapidly change the size of management zone grids and recomputed model input parameters accordingly. The Management Zone Grid Creation Tool (Figure 1) can be used for arbitrarily subdividing a study area into a user-defined number of equally-sized rectangular grids. Four steps are required to be completed by the user to accomplish grid creation. In Step 1, the user selects the reference layer from the list of layers currently open in ArcMap. This step is important for assigning a projection to the grid layer that will be created. If a user is working in a projected coordinate system, the projection of the reference layer will be assigned as the projection of the management zone grid layer. Clicking “Set Layer” after selecting the reference layer will advance the user to Step 2. In Step 2, the user is required to enter two integers to define the grid dimensions, or the number of rows and number of columns of grid zones. To properly 4
count grids in this work, a user must be advised that the term “grid” refers to the areas between grid boundaries rather than the intersection points of grid boundaries. Clicking the “Set Dimensions” button after entering the grid dimensions advances the user to Step 3. In Step 3, the user must define the upper left and lower right geographic coordinates of the management zone grid. There are several options for completing this task. By clicking “Get From Map”, the
Figure 1. The Management Zone Grid Creation Tool user interface map window in ArcMap is prepared such that the user can draw a rectangle on the screen, and the required geographic coordinates are extracted from the rectangle drawn. By clicking “Get From Layer”, the user is allowed to select from the existing layers currently open in ArcMap, and the required geographic coordinates are extracted from the outer bounds of the selected layer. Also, the user can input the required geographic coordinates manually in the textboxes provided. Then, the “Draw Grid” command button implements the user inputs for grid dimensions and corner coordinates to draw the management zone grid in the ArcMap window, and the tool advances to Step 4. After inspecting the management zone grid drawn in ArcMap, the user can click the “Create Shapefile” button in Step 4 to convert the grid to a polygon shapefile with separate polygons for each management zone. The polygon shapefile can then be added to list of layers in ArcMap and used for subsequent processing of geospatial data. 5
Field Data Clipping Tool Often field data collection occurs over the entire field area with no regard to management zone boundaries. For example, when using a yield monitor on a grain combine, the machine is typically restricted to traveling in parallel swaths across the entire field length. In a production crop setting, it would be inconvenient to require that the machine be driven such that grain is harvested in each management zone independently. Given that a large amount of information can be rapidly collected with modern crop sensing systems, an easier method for obtaining measurements within management zones is to collect the data without regard to the management zone boundaries and to use post-processing techniques within a GIS software to split the data by zone. The Field Data Clipping Tool (Figure 2) allows a user to split polygon and point layers according to management zone boundaries, assuming the management zones are defined as a polygon layer in ArcMap. Essentially, the tool uses the management zone layer as a cookie cutter to clip other layers of data that are open in ArcMap. Upon initialization, this tool lists the available polygon and point layers currently open in ArcMap in a list box. In Step 1, the user selects the
Figure 2. The Field Data Clipping Tool user interface polygon and points layers to be clipped and clicks the “Setup Fields” command button. This action opens the “Define Field Names” window (Figure 3), and the user is asked to select the name of the field in the attribute table of the layer to be clipped that corresponds to the data to be outputted to the clipped layer. For example, when clipping a layer of yield data, the field
6
containing the yield information is selected. When clipping a soil type layer, the field containing the soil type name or number is selected. The tool loops through all layers selected for clipping until the user has selected a field of interest for each layer. Then, it advances the user to Step 2. In Step 2, the user must select the polygon layer that defines the management zone boundaries to be used as a cookie cutter for clipping. For example, if management zones are to be defined by soil type boundaries, the digital soil survey layer can be selected, or perhaps the
Figure 3. Interface to define the field containing the data of interest for each layer to be clipped user wishes to use a grid-based management zone layer previously created with the Management Zone Grid Creation Tool. The user must then click “Setup Fields” and select the field that corresponds to a unique zone identifier for each management zone. This zone identifier is used within the crop model input files to associate model input data with the appropriate management zone, and so the polygon layer used for clipping must contain a unique identifier for each polygon. After selecting the appropriate field and pressing “OK”, the tool will advance the user to Step 3. In Step 3, the clipping of layers will commence and clipped data of interest, as defined by previously selecting the appropriate field names, will be outputted to a new polygon shapefile. For clipping polygon layers, the algorithm computes the feature that covers the largest area within each management zone and assigns that feature to the entire zone. For example, when clipping a digital soil survey, the algorithm determines the soil type that covers the largest area within each management zone and assigns that soil type to the entire zone. For clipping point layers, the algorithm averages the values for all the points contained within management zone boundaries and assigns this value to the entire zone. For example, when clipping data from a yield monitor, all the yield measurements contained within a management zone are averaged, and this value is assigned as the final yield for the zone. In
7
this way, crop model parameters can be defined such that the model’s limiting assumption of homogeneity is satisfied within each management zone.
Create Model Input Files The DDSAT family of crop models obtain model inputs from model input files that are written in a very specific format. Files necessary for operating crop model simulations using Apollo include the soil file (soil.sol), the yield files (*.mza), the management files (*.mzx), and the weather files (*.wth). For applications with Apollo, the soil file contains unique blocks of text in the specified DSSAT format to define the necessary soil properties for each management zone. Important soil properties required for model simulations include bulk density (g cm-3), permeability (cm d-1), drained upper limit (cm cm-3), lower limit (cm cm-3), organic carbon (%), and pH in water. Yield files for individual growing seasons contain the average measured yield for each management zone for use in model calibration and validation within Apollo. Calibration occurs by adjusting model input parameters to minimize the root mean squared error between measured and simulated yield in each management zone. The management files contain information pertaining to the producer’s management practices. Since the producer at the study site for this work typically does not use site-specific management, a GIS tool for creating the management file was not necessary in this work. However, a separate application has been prepared in Visual Basic for facilitating user entry of management information and printing management files to disk. To date, spatial variability in weather has not been incorporated into our model input files, because variability in weather patterns would be difficult to measure across the field. In this work, ArcGIS software tools were written to prepare the soil file and the yield files for sitespecific crop model simulations in Apollo. After clipping a digital soil survey and yield monitor data according to management zones using the Field Data Clipping Tool, soil and yield files can be created. The user interface for creating the soil file (Figure 4) is initiated by clicking “Create
Figure 4. The user interface for creating the soil.sol file for use with Apollo
8
Soil.sol” on the main toolbar. In Step 1, the user is asked to select the layer that was previously created by clipping a digital soil survey according to management zones using the Field Data Clipping Tool. When the clipped layer is selected, the available fields within the layer are listed in a list box, and the user is asked to select the field containing the soil type information for each management zone. After selecting the appropriate field, clicking “OK” advances the user to Step 2, and all the soil types across the study area are displayed in the Step 2 list box. These are the soil types for which the user must input required information. To complete Step 2, the use must alternatively select each soil type and click “Define Properties”. A new window will open in which the user can enter values for soil properties in individual soil layers (Figure 5). Most of the required values can be obtained from a soil survey. However, since values for drained upper limit and lower limit are not contained in Iowa soil surveys, the software provides
Figure 5. Interface for user input of soil properties a combo box for selected the soil texture in a particular soil layer. The soil texture is then used to assign values for drained upper limit and lower limit based on the results of Ratliff et al. (1983). The soil properties for each soil type can also be saved to and opened from a text file, such that the information does not have to be reentered when a soil type is reencountered in a different study. After entering soil properties for each soil type present over the study area, the user can click “OK” to advance the tool to Step 3. In Step 3, the user has the option of entering other information. This information is optional. Clicking “OK” in Step 3 takes the user to Step 4 in which the algorithm prints soil information to a text file that can be interpreted by the Apollo
9
decision support software. The user interface for creating yield files (Figure 6) is initiated by clicking “Create FILEA/FILET” on the main toolbar. In Step 1, the user is asked to select the layer that was previously created by clipping yield monitor data according to management zones using the Field Data Clipping Tool. When the clipped layer is selected, the available fields within the layer are listed in a list box, and the user is asked to select the field containing the yield information in each management zone for the growing season of interest. Also, since the crop models must have yield information in units of kg ha-1, the user must select the radio button to perform the appropriate conversion of yield data to these units. Clicking “OK” advances the user to Step 2. In Step 2, the user is asked to enter required information for the header of the yield file, and clicking “OK” advances the user to Step 3 in which the algorithm prints yield information in the FILEA format, FILET format, or both. Apollo requires yield files to be printed in the FILEA format.
Figure 6. User interface for creating yield files for use with Apollo
10
Conclusion The Apollo decision support software has been useful for automating crop model simulations to study precision management of various crop production inputs. Development of VBA algorithms using ArcObjects within the ArcMap component of ArcGIS has increased productivity in our lab by reducing the time necessary to prepare crop model input files for use with the Apollo software. These GIS tools can be made available to any interested party upon request. For others who desired to utilize ArcObjects for customizing their own GIS applications, there may be a substantial learning curve for inexperienced programmers who are unfamiliar with the ArcObjects object model diagram and the concepts of object-oriented programming. ArcObjects reference books (Zeiler, 2001a; Zeiler, 2001b) and the ArcObjects documentation and user forums on the ESRI webcite were most helpful for learning how to customize ArcGIS applications in this work. Since the Apollo software and the GIS tools currently exist as separate entities, future work will focus on incorporating the GIS tools directly into Apollo’s Visual Basic application. This would allow a user to input field information, perform geoprocessing tasks, develop crop model input files, and automate crop model simulations all within the confines of a single management decision support system. Such a task may require significant modification of the existing Apollo software, such that the GIS environment can be included. Since Apollo is written as a stand-alone Visual Basic application, the GIS environment for Apollo cannot be created using the VBA environment within ArcMap. We have investigated the use of MapObjects, an ActiveX GIS control available for use within Visual Basic, as an alternative; however, this may require slight modification of the algorithms for the GIS tools developed in this work.
References Batchelor, W. D., B. Basso, and J. O. Paz. 2002. Examples of strategies to analyze spatial and temporal yield variability using crop models. European Journal of Agronomy. 18(2):141158. Batchelor, W.D., J. O. Paz, and K. R. Thorp. 2004. Development and evaluation of a decision support system for precision agriculture. In Proceedings of the 7th International Conference on Precision Agriculture. Madison, WI, USA: ASA-CSSA-SSSA. Paz, J. O., W. D. Batchelor, B. A. Babcock, T. S. Colvin, S. D. Logsdon, T. C. Kaspar, and D. L. Karlen. 1999. Model-based technique to determine variable rate nitrogen for corn. Agricultural Systems. 61(1):69-75. Paz, J. O., W. D. Batchelor, and G. L. Tylka. 2001. Method to use crop growth models to estimate potential return for variable-rate management in soybeans. Transactions of the ASAE. 44(5):1335-1341. Paz, J. O., W. D. Batchelor, and J. W. Jones. 2003. Estimating potential economic return for variable soybean variety management. Transactions of the ASAE. 46(4):1225-1233. Ratliff, L.F., J.T. Ritchie, and D.K. Cassel. 1983. Field-measured limits of soil water availability as related to laboratory-measured properties. Soil Science of America Journal. 47:770775. Razavi, A.H. 2002. ArcGIS Developer’s Guide for VBA. Clifton Park, NY: Delmar Learning. Zeiler, M. 2001a. Exploring ArcObjects Volume 1: Applications and Cartography. Redlands, CA, USA: ESRI. Zeiler, M. 2001b. Exploring ArcObjects Volume 2: Geographic Data Management. Redlands, CA, USA: ESRI.
11