Debug & Error Handling

This week in GIS Programming we learned about the basics of debugging and error handling in Python. For the assignment, I debugged and handled errors in three different scripts that were associated with an ArcGIS file, TravisCountyAustinTx.aprx, which includes spatial data on various features in this region:  parks, bike routes, facilities, and the county.

For the first script, I debugged it to print a list of field names from park.shp.


For the second script, I debugged it to print a list of layers in each of the project's data frames:

With the third script, I handled errors in Part A by including a try-except statement, which essentially allowed Part B to run correctly (it contained no errors, only Part A did):

This flow chart shows the steps necessary in executing this script, including importing arcpy, printing an opening statement, and then adding a try and except statement so that the script can run even though an error is included (an error in the path of the project file).  At the end of Part A an error statement is printed (the reason why the try-except statement was included).  Part B of the script is correct, and it runs to print an opening statement, the name, data source, and spatial reference of four different layers in the TravisCountyAustinTx.aprx file.  It concludes with the statement “Part B successfully completed.”


I found this module helpful in reinforcing some of the previous knowledge learned in this class regarding Python and GIS programming, along with learning some basic principles of debugging and error handling.

While I felt slightly overwhelmed at the start of this module, by the end I was pleasantly surprised,  however, that I was able to complete the tasks assigned and able to run all the scripts correctly.


Comments

Popular posts from this blog

Surfaces: TINs and DEMs

Computer Cartography!

GIS Portfolio