Model Builder is a visual representation of inputs/outputs and tools used to complete geoprocessing in an ArcGIS environment. Model Builder is an extremely useful tool for completing several geoprocessing steps in succession rather than one at a time. It is possible to visually create inputs that are run through a tool, and then have the outputs used as the new inputs for the next tool. This process is what we worked on this week. We were given various data and asked to create a model that would Clip, Select and then Erase certain data from a shapefile.
Once the model was completed in the ArcGIS environment, we were required to export the model as a stand-alone Python script that could be shared using the script itself and a toolbox from ArcGIS. Though a model runs successfully in ArcGIS, the exported Python script will not run successfully without setting parameters and some additional settings. Mainly, file paths have to be checked for accuracy, the workspace environment has to be re-specified (this is done in ArcGIS but does not translate to the script), and the script must also be told to "overwrite existing." That last part gave me fits that I'll explain later.
Pictured above is the result of my model and subsequent Python script. The shapefile of interest is the soils_Clip_Erase (grey). It is the product of clipping the provided soils.shp to the area of the basin.shp showed in pink, Selecting "Not prime farmland", and then Erasing the selection. The result is a subset of the soils shapefile that covers the same area as the basin and only contains areas suitable for farming. These files are the result of the Python script, not the model. The original files created by the model were overwritten by design when the Python script was run. The following is the flowchart I used to help guide the process of creating the model and script.
And this leads me to the major lesson I learned from the module. Adding a print "Success" statement to the end of the code that is meant to overwrite existing files is EXTREMELY useful. I ran the script countless times not realizing it was succeeding because the file names weren't changing and I wasn't getting any messages from the interactive PythonWin window. It was working, but I just couldn't tell. Once I added the print "Success" statement and ran the script again, Success printed to the interactive window I knew I was good to go.