Module 4 was the first module I truly felt like the concepts of Python coding for ArcGIS Pro were truly starting to click. I genuinely had fun challenging myself during this assignment.
This module focused on two ways to utilize Geoprocessing tools within ArcGIS Pro and the arcpy package: ModelBuilder and Python scripts made in Notebooks.
First, I was tasked with building a model in ModelBuilder that would clip a shapefile to another, select features of the clipped area based on a specific attribute, and then erase those selected features from the clip. I found this process interesting as it a great way to batch processes and streamline data manipulation. I also enjoy that utilizing ModelBuilder is much like creating a flowchart for a script of code, however it can create results in real-time.
The most challenging aspect of this module was by far creating a script for a series of geoprocessing tools using Python in Notebooks. This was the first time I have been asked to write a relatively complex script from scratch without any sort of template. The parameters for this script were as follows:
1) Add XY coordinates to a shapefile
2) Create a 1000m. buffer around this shapefile (originally a point feature file)
3) Dissolve the buffer into a separate, single feature
4) Print messages after the completion of each tool function
I made quick work of this task, which is not something I can see for previous modules in this course. Thus, I am quite proud to provide a screenshot below with the shapefile results from the script I wrote:
Here are my notes on my thoughts regarding how I tackled this script:
1
I began by importing the arcpy package, while I know this is not
necessary for running my script in Notebooks, I want to get in the habit of
writing scripts that can be run in both Notebooks and an IDE, such as IDLE.
2
I then set the environment by using a similar line of code to the
one I learned in the Module 4 exercise. This allowed me to path the data folder
to the script and work with the shapefile via syntax much easier.
3
I then knew I wanted to try writing the entire script in one go
instead of testing each individual tool. I felt this would allow me to both
test my skills as well as keep me from getting lost and making more errors. I
wanted to write the script, edit and debug from there.
4
For each of the three desired outcomes, I wrote a separate block
of code. I kept it clean and organized. Before attempting to write each block,
I carefully examined the syntax and properties for each tool on ESRI’s website from
the links provided. This was crucial as the XY coordinate tool was not covered
in the exercise like the Buffer Analysis tool was.
5
Once I successfully wrote the block for the XY coordinate tool, I
carefully read the directions and realized that I would not be able to write
the code for the Buffer Analysis exactly like I practiced in the exercise. In
the exercise, the buffer code cell included syntax to allow a dissolve option.
This would be problematic as the directions asked for a completion message for
each step in the script. If I did not break up the processes, I would only get
two completion messages. I also needed two separate shapefiles. So again, I leaned heavily on the ESRI website to
follow correct syntax for the Dissolve tool.
6
I am unsure if I can import multiple environments, and rather than
trying and creating a confusing mess of errors I elected to simply list the
file path of my input for the Dissolve function. Matter of fact, when I initially
wrote the code block for the Dissolve function, I tried to list the input as just
the name of the buffer shapefile I had created in the previous code block and
was confused when met with an ExecuteError. After some critical thinking, I
corrected the issue.
7
Once I finished the script, ran it, and realized it worked as
intended, I attempted to use the GetMessages function. I set the severity as 0
as this would print all messages upon running the tool. My first attempt I put just
one GetMessages function at the end of the script to see if it would print the
completion message for all the tools I ran in one go. When I realized that this
did not work, I added one of these code lines after every tool. I wanted to
clean it up so I added custom strings to print before the completion messages
as well as a print(“\n”) string to add a line space between each message.
This concludes my work for Module 4. With this newfound sense of confidence, I am looking forward to closing out this last leg of the course!

Comments
Post a Comment