Friday, June 26, 2015

Module 6 - Python Goeprocessing

This week in GISProgramming we were challenged to write a standalone Python script in PythonWin for our lab. The script needed to add XY coordinates to a point shapefile, create a 1000 meter buffer around each point, and then dissolve the buffer areas into a single feature. We were given directions to use the AddXY Tool, the Buffer Tool, and the Dissolve Tool even though the dissolve portion could be done with optional parameters in the Buffer Tool.

 After completing the weekly exercise this task was not as daunting as I first thought it would be. The biggest challenge for me was syntax. I used psuedocode to establish my game plan for how to write the script and then I looked up the Python script example associated with each tool in the ArcGIS help area. The example scripts helped me understand how to write out the parameters for each tool because while they may be similar, not everything is exactly the same. I wrote out the script but expected errors so I "commented out" everything but the first tool and tried to run it. There were errors. A spelling problem and then an issue with a filepath but they didn't stump me for long. Once the first tool ran properly I "uncommented out" the second tool and worked through it. I found I had the same type of filepath issues so I decided to use full filepaths where the errors arose instead of the shortened versions that should have linked to my declared workspace. After that fix the Buffer Tool worked without a problem and I moved on to the last tool. I fixed the filepath problem for the input values on the Dissolve Tool before I tried to run it so when I did finally run the whole script it had no issues. My script results are in the graphic below.
One of the most important parts of this script was setting the environments and geoprocessing options. Since I had issues with my workspace and some of the filepaths that followed I ran the script a bunch of times. This means the same file was created over and over again. Turning on the overwrite option in ArcGIS's geoprocessing options was essential to completing this script.

When the script ran successfully I was still a little doubtful that the desired shapefiles turned out right so I opened up a map and checked them before calling the script a success.

No comments:

Post a Comment