GIS 5103 - Module 3





Debugging: In this module, three scripts are provided with pre-existing errors. I corrected the errors using Spyder's debugging tools, correcting syntax, and using try-except statements. 


Issues and Notes:
In this modules, I encountered some errors I had to research a bit to learn how to deal with them and what they mean, I encountered some formatting issues that had to be dealt with before corrected code would work, and I had to use logical thinking to understand first what the process was attempting to do, how it was doing it, and where adjustments or additions were needed to make the code work. 



Part 1: Correcting errors
In this part, the code is intended to print the field names in a shapefile. The code contains multiple syntax errors. I was able to identify the errors and correct them.
The steps are as follows:
1) Look at code, lines with errors will be indicated on the right with note on what the error is.
2) I could catch these errors just by looking at it. They included incorrect field names, such as capitalization and extra or missing letters.
3) I ran the code just to insure there was nothing I was missing. The code ran correctly.

Please see flowchart and output of successfully run code below:

Part 1 flowchart: Correcting errors


Part 1 output: Correcting errors


Part 2: Debug tool in Spyder
In this part, the code is attempting to find and print the spatial reference of a map, and the layers contained in it. It it encountering 8 errors that must be identified and corrected. 
The steps are as follows:
1) I corrected visible errors
2)I ran the script through the Spyder debugging tool to identify which lines were encountering errors. 
3) I modified the script to account for those errors, as I saw them. Some error types I had to research how to adjust them. 
4) Run modified script. 

Please see flowchart and output of successfully run code below:
Part 2 flowchart: Debugging tool in Spyder


Part 2 output: Debugging tool in Spyder



Part 3: By-passing errors using try-except statement
In part 3, the code is broken into two parts: the first part turns on labels and visibility for selected layers. The second part prints information for the layers, including layer names, data source, and spatial reference. The first part contains an error, and using a try-except statement, I was able to by-pass this part of the code to move on to the second part, which was error free. 
The steps are as follows:
1) Set the proper data path. The default path to the map file was consistent with my files. 
2) Attempt to run code to identify error present. The error was a TypeError and the line number and error type were identified in the output from the error message. 
3) Insert try statement above line where error had occured. 
4) Insert except statement beneath the area of code where the first part would otherwise complete. Include print statement to indicate that an error had occured.
5) Adjust indents
6) Run code, code will work. 

Please see flowchart and output of successfully run code below:
Part 3 Flowchart: By-passing errors using try-except statement



Part 3 output: By-passing errors using try-except statement

Comments

Popular posts from this blog

GIS6005 - Module 1 San Francisco Bay Area, Point of Interest

GIS 5100 Module 2

GIS 5100 Module 6