Module 6 - Geoprocessing with Python
This week we used Python scripting to run geoprocessing tasks. All of the functionality of geoprocessing tools in ArcGIS can be accessed through Python using the ArcPy site package.
Some of the topics we covered in detailed this week included importing ArcPy, using tools and the two ways of "calling" them, using classes and their appropriate syntax, setting up environment settings, and working with tool messages -- all with an emphasis in writing a stand-alone Python script. Additionally, we got a nice use out of ArcGIS Desktop Help. Some of the great things about ArcGIS Help in writing Python code is that it shows you the proper syntax for every single geoprocessing tool, explains what all of the parameters are for, explains what each tool does and how it should be used, and gives you code examples of Python scripts in both a stand-alone mode, and in the ArcGIS Python interactive window mode.
For our lab assignment, we were tasked to write a stand-alone Python script performing three geoprocessing functions. Specifically, my script adds XY coordinates to an existing shapefile (called "hospitals" located in my student drive) using the Add XY tool, then it creates a 1,000 meter buffer around the hospital features using the Buffer tool, and finally dissolves the hospitals' buffers into a separate, single feature using the Dissolve tool. As part of my assignment's deliverable, I had to make sure I printed the messages from each tool after it was ran using the GetMessages() function. Additionally, I had to make sure I enabled the overwriting of created outputs so that my script can be ran more than once. I was able to create a successfully-running script by making sure to import necessary modules, classes, and setting my environment workspace. As you can see from the screenshot above, the script runs in less than 8 seconds.
Comments
Post a Comment