Monday, June 13, 2016

GIS5103 - Module 5 - Geoprocessing in ArcGIS

"Geoprocessing in ArcGIS allows you to perform spatial analysis and modeling as well as automate GIS tasks".   This module showed us how to use geoprocessing tools but the main focus was how to make using geoprocessing tools easier.   Batch processing can be used to run the same geoprocessing tool on different inputs.  Model Builder can be used to create a model that runs a sequence of geoprocessing tools through a visual interface.  Model elements such as variables, tools, and connectors are used to build a model that can be run and produce results.  Scripting can also be used to run geoprocessing tools in sequence.  Scripting with the Python programming language is more advantageous than using a model when more advanced programming logic is required.  Scripts can also be run outside of ArcGIS and be scheduled to run without user intervention.

In Part 1 of the assignment we used Model Builder to create a model that used two provided data layers (soils and basin).  First, however, we had to create a Toolbox because models have to be saved within a Toolbox.  The new model used the Clip tool to clip the soils feature to the basin feature.   After running the model the output result was then used as input to the Select tool in order to select soils features that were classified only as "Not prime farmland".   The output selection result was then used by the Erase tool as the erase feature to remove from the original basin layer.   The resulting output is shown below.  The dark blue outline represents the basin boundary.  The soils features that are within the basin boundary that are not classified as "Not prime farmland" are shown in lime green.


    Basin feature shapefile with Soils features that are "not prime farmland" removed
















    We then exported our model to create a Python script.  In order for this script to run stand-alone we had to make some modifications.   We had to insert code to "overwrite" existing output filenames.  Below is a flowchart of the Python script.
    Flowchart for Module 5 script



    Next we created a script tool from our script.  A custom script tool is a way to integrate Python scripts directly into ArcGIS.   The tool can then be used or called again.

    Finally, we shared our custom Toolbox containing our model and script tool.   We had to create a zip file that compressed together the Toolbox and the actual Module 5 Python script.

    I encountered a few hiccups in this assignment.  When initially creating my model I realized I had to run each tool prior to using its output as input for another tool.  

    In Part 1 Step 3 I had saved my model but forgot to save it after setting variables as Model Parameters.   When I exported the model as Python script I did not have the “if” statements in script because I had failed to save the model first.
    I was unable to compress together the entire Scripts folder and the Toolbox located in the Module5\Results folder so I had to place a copy of the Module 5 Python script file in the Results folder so the zip file would contain both.

    UPDATE:  I moved my Toolbox to S:\GISProgramming\Module5 and then recreated my script tool as it could no longer find my python script.  I then was able to successfully compress together the Module5\Scripts folder with my Toolbox. 

    No comments:

    Post a Comment