Tuesday, June 14, 2016

Geoprocessing in ArcGIS

GIS Programming - Mod 5


This week we learned about geoprocessing tools, models and scripts. We started out creating a new toolbox then, within that, creating a model using ModelBuilder.  Our task was to clip the soils layer to the extent of the basin layer and remove from that selection those soils that were classified "Not prime farmland."  To do this I dragged the soil and basin layers from the table of contents to the model and the Clip tool from the Toolbox menu, added the parameters to the Clip tool and ran the model.  As soon as I clicked run I realized I hadn’t set my workspace and scratch environments or adjusted the path for my Output Feature Class so I had to delete the output from the geodatabase of a previous lesson, set the workspace and scratch place environments to the correct one, verify the Overwrite option was selected, then rerun the model. 

With that portion working correctly I dragged Select to the model and added the output of my clip as the input, defined the output and created an SQL expression to select only the specified attributes to add to the selection set.  Using the results of the Select tool I used Erase to remove those attributes from the Clip output.  Before running this step I right clicked on the output and selected Add to Display so my output would show up in the table of contents and I could check the attribute table to make sure the selection worked correctly.  The above shows I did it right so I was able to export the model as a Python script and moved on to the next part of the assignment.

Exporting a model to Python allows the script to work within ArcMap, but in order for it to work outside of ArcMap as a stand-alone script a few things need to be changed.  Because the input files came directly from the map's table of content they didn't have a path associated with them.  In order for the script to stand alone the path needed to be added to those variables.  The next change was telling the script to overwrite the output since that had been set within the map workspace, not the model.

 Now my script was able to stand alone as though I had written the whole thing from the beginning. From this script I was able to create a script tool within the toolbox.

No comments:

Post a Comment