Monday, June 10, 2024

GIS 5103 Module 4 - Geoprocessing with ModelBuilder and Python

Module 4 of GIS Programming was another opportunity to dive deeper into the Python programming language and its many applications in Geographic Information Systems spatial data analysis.  The first part of the exercise was utilizing the ModelBuilder tool that is included in the ArcGIS software platform. Previously, I had no experience with this tool, but immediately realized its potential in the automation of GIS data processing. Below is an example of what the tool looks like [I used files from work not related to our assignment to avoid giving the assignment's answer away to other students.] As seen below, the model looks like a flowchart where the blue input elements are used as parameters to run the intersect tool [tool elements are yellow in ModelBuilder], and the output of the intersect tool is a new feature class shown as a green element. In this particular case, the Poles_Intersect feature class will contain all points from the IEC AUXILLARY POLES feature class that lie within the zone feature class's boundary. This can all be achieved by simply clicking the 'Run' button after the model is built. The model built for the weekly assignment was to use the clip tool to single out soil areas that lie within a polygonal feature class named 'basin'. Once this was accomplished, we were to select out and delete areas that were categorized 'Not Prime Farmland'. Essentially, this provided areas within the basin that were suitable for farming. 

These are very simple examples of ModelBuilder models, but more complex models can be viewed by a simple Google search. Another great feature of ModelBuilder is the option to export the model directly to a Python script file. This can be very helpful when the complexity of the model exceeds the Python knowledge base of the user. A model can be built, validated, and exported to a script file; the resulting code can be examined by the user to discover how to reach the same result by utilizing the Python programming language.


The second half of the assignment was to create a Python script [from scratch] that executes three ArcGIS geoprocessing tools.  The flowchart of this script is very linear, as shown below:


As the flowchart illustrates, the script takes a feature class named hospitals, adds geographic x- and y- coordinates to each point of the feature class [the coordinates will be added to the attribute table, in fields that are created by the Add XY Data tool]. Next, the script will create a buffer around each point [hospital] that has a 1000-meter radius. Finally, the dissolve tool was run on the newly created buffers to merge them all into a singular, polygonal feature class. Printed messages were created to inform the user what process was being ran, and the ArcGIS GetMessage() function was added to show statistics related to each of the three functions ran. The results of the script can be shown below.

 
After the script was ran, the results were examined in the ArcGIS interface. As shown below, each point represents a hospital, that lies within the buffer feature class, which has been dissolved together into a singular, continuous polygonal area. Also, the X- and Y-coordinates can be seen in the two furthest right-side columns of the attribute table.


Once again, this exercise was a great opportunity to learn more about Python scripting and the automation of geoprocessing workflow. I did not encounter any major problems working through this exercise, other than a few punctuation errors that were easily fixed. Other than these minor issues, the whole process was seamless. Although there are only two modules left in this class, I am truly excited to apply this knowledge at work to see how many redundant processes I can automate utilizing ModelBuilder and / or Python scripts.

No comments:

Post a Comment

GIS 5935 Module 2.2 - Surface Interpolation

  Post in progress - please check back soon...