Lab 3 [GIS5103]: Debugging and Error Handling

In this week's lab we examined the templates for three separate Python scripts to identify syntax errors and exceptions and how best to locate these using Spyder. The output from the first script that prints out the names of fields from a shapefile is shown here:


Identifying the syntax errors within this script emphasized the importance of consistency with variable naming and the correct format for iterating with a for loop.

The second script was designed to display a more complete set of items from an ArcGIS project file, including spatial reference information and layer information, as shown here:


Systematically identifying the syntax errors in this script emphasized the importance of file path naming and consistency with variable name capitalization, as well as understanding the relevance of correctly formatting and spelling method names.
A third and final script provided training in using the try-except statement, as shown in the following flowchart:

The goal of this part of the lab was to correctly format the try-except statement to ensure that Part B would be executed following an attempt to execute Part A, with a meaningful message displayed for any exceptions in running Part A. The output of this script is shown here:


This script was the most complex we studied, where Part A scripting turned on labels and visibility for a specific layer within an ArcGIS project file. Following this, Part B scripting printed the names, data sources, and spatial reference of each layer within the same ArcGIS project file.

Additional highlights in the practice exercises this week included hands-on training in using the built-in debugger in Spyder. This tool can be used to help identify errors by allowing you to step through the code one step at a time. Breakpoints can be set to advance to specific stop points within the code. Once a breakpoint is reached, line-by-line stepping can continue and/or additional breakpoints can be set.

Comments

Popular posts from this blog

Lab 2 [GIS5935]: Data Quality Standards

Lab 5 [GIS5935]: Surface Interpolation

Final Project [GIS6005]: Conservation in the State of Florida: Preserving Key Habitats of the Striped Burrfish