Sunday, May 29, 2022

GIS 4102 - Module 2 - Debug/Error Handling

 For this weeks module 2 we were tasked with analyzing three provided scripts and troubleshooting them in order to locate and fix errors. Errors present themselves in python when the program compiler detects syntax errors that interfere with the script from running. The error message display indicates the syntax error that occurred. Checking for errors in python is relatively straightforward. Syntax can be quickly checked by looking at the code analysis on the left side of the code for error ! symbols. Syntax can also be quickly checked by running the script and observing the console results. Another final way syntax can be checked is by quickly running the debugger located on the spyder toolbar.

The first part of the assignment involved editing file-path and capitalization errors in script 1 in order to run a script that displays the names of  all fields  on  the  Module2/Data/parks.shp  attribute  table. Here is a screenshot of the spyder console successfully running the script.

The second part of the assignment also involved correcting file-paths, spelling errors, and functions. Once all errors were correct the script printed the names of all layers in the project file, TravisCountyAustinTX.aprx. Here is a screenshot of the spyder console successfully running the script.


The final part of the assignment involved successfully implementing a try-except statement. I added a try-except statement in the following places of the code in order to allow the script to run and print an error message. Adding the try statement to line 12 and the except statement to line 24 incorporated the bulk of the code where the error occurred. The except statement indicated the error message by print displaying the error statement, “The error is '__init__() missing 1 required positional argument: 'aprx_path''. After correcting another file-path error in part B the entire script was able to run error free. The result of the script displays the prints of part A indicating the try-except statement and the results of part B indicating name, data source, and the spatial reference of  each layer in the project file. Here is another screenshot of the spyder console successfully running parts A & B of the script.


Monday, May 23, 2022

GIS 4102 - Module 1 - Python basics

 For the summer semester of 2022 I have enrolled in GIS 4102 to better understand the ins and outs of programming in GIS. We began interacting with python code in the IDE spyder. This software allows us to visualize and edit the code directly. Our first task was to run a provided script that creates all of the folders that we will be using throughout the semester directly into the designated S drive. After establishing the folders the assignment could begin. Opening the module template revealed some provided code. The first step of the assignment involved creating a string that involved our full name and then splitting that string into individual names. Using indexing I used a print function to display only my last name. The next step of the assignment was to correct two errors present in the provided dice game code. This was where I ran into my first hurdle. The first error was simple, correct the case of the x variable, the second error was tricky. I finally figured out that string values can only be added to other string values and not integers + strings which was the situation I had going on.The next steps involved creating a random generated list of twenty integers, 0-10, that when generated detects for an unlucky number. If this unlucky number is detected the number is removed and a print statement indicates how many times the unlucky number was removed. If the unlucky number is not detected a print statement indicates that the unlucky number was not in the list. These steps of the module took the longest. I ran into another issue involving correct parentheses usage that was solved after thorough contemplation and help from the UWF GIS youtube channel. Going forward this module has equipped me with the basic knowledge to read, understand, and interact with python coding. Paying close attention to syntax is key to achieving success in programming. 

Here is a screenshot of the full script ran from the sypder console.


Spring 2023 semester wrap up

 The spring 2023 semester at UWF has been an eventful one in which I finalized the requirements for my bachelors of science in natural scien...