Tuesday, June 25, 2024

GIS Programming - Module 6 - Working with Geometries

Module 6 for GIS Programming tasked us with writing a script that gathered geographic data from a river shapefile and writing the data to a TXT file. This required us to build upon what we have learned utilizing a search cursor to iterate over the river shapefile geometries, using nested loops, with the end goal being a populated TXT file containing the name, x,y, coordinates, OID, and the number of vertices for each row of the features in the rivers shapefile.

The increased complexity of this assignment was a little intimidating and I found that sticking to the template and flowchart was crucial for success. I got off track a few times and ended up making some mistakes that required me to back track. I thought that I was finished on a few occasions but found I had overlooked some crucial details. One of these was that my nested for loops were incorrect and another was that my TXT file was not being saved in my results folder. 

Overall, this was a challenging module and a great finish to the course. I have certainly learned a lot in a short time period and look forward to continuing to build upon what I have learned. Below is my flowchart and a snippet from the resulting TXT file.












Tuesday, June 18, 2024

GIS Programming - Module 5 - Exploring & Manipulating Data

 The topic for Module 5 for GIS Programming was exploring and manipulating data. In this module we covered a lot of ground. Some of the major outcomes were learning how to work with different types of cursors to manipulate data, working with list and describe functions, as well as creating and population dictionaries. Another useful topic we covered was how to use search cursors with SQL expressions.

Our task for our lab assignment was to create a script that created and populated a new file geodatabase followed by creating and populating a dictionary containing the names and population of the cities in new Mexico that are county seats.

The initial steps of the task went pretty smooth but I did get hung up when I forgot to update my environment after creating the new file geodatabase. Another thing that gave me some temporary issues was creating my SQL expression in the search cursor. I was able to get through with some help from the exercise document and ESRI documentation and much trial and error. I also I had some issues placing the \n character to create proper space between messages but after more trial and error I was able to things where I wanted them. I finished adding my print statements and GetMessages which gave me a few minor issues but again with trial and error and some tips from the discussion board I was able to get them where I wanted for the most part.

Below are the screenshots of my script output and a flowchart I created to guide myself through the creation of my script.





Overall, this was a really challenging task and I spent a ton of time trying to complete it. There was a lot of trial and error but through the process I can say that I am starting see Python on a more holistic level.








Monday, June 10, 2024

GIS Programming - Module 4 - Geoprocessing

In module 4 we were challenged with two different tasks that utilized skills we have gained over the past few weeks using ModelBuilder and Python to perform geoprocessing tasks. In the initial task we were asked to create a model and script tool using ModelBuilder. This model needed to accomplish three geoprocessing tasks. Using provided data this model needed to clip a provided soil shapefile to the parameters of a basin shapefile. Next it needed to select all soils that were classified as "Not prime farmland" using an SQL expression. Finally, it needed to erase the "Not prime farmland" soil selection from the basin polygon. The output of this model seen below shows soils suitable for farming.


Our second task was completed in Notebook within ArcGIS Pro. This consisted of writing a Python geoprocessing script that accomplished three tasks on a hospitals shapefile. The first task was to add XY coordinates to the shapefile which I accomplished using the arcpy.management.AddXY() tool. Second, a 1,000 meter buffer needed to be created around each hospital. I accomplished this by using the arcpy.analysis.Buffer() tool. The third and final task was to dissolve the individual buffers into a single feature. I used the arcpy.management.Dissolve() tool to accomplish this. Using the GetMessages() function our script needed to print messages from the tool after each of the three tasks. Below is a screenshot of my script output messages and my map showing the dissolved buffers.




Overall, I went into this lab feeling a little intimidated but it went much smoother than anticipated aside from a few minor hang ups. It is very interesting to learn how to utilize ModelBuilder and Python to accomplish tasks. I really liked the visual component of using ModelBuilder. It makes me think of how I could have utilized these skills while working on past assignments in the program. 

Wednesday, June 5, 2024

GIS Programming - Module 3 - Debugging and Error Handling

Module 3 for GIS Programming focused on the debugging and error handling of Python scripts. We were introduced to common error messages and how to implement debugging procedures. The lecture and exercise materials built upon this foundation providing us some instruction and practice on how to interpret script error messages while recognizing and correcting syntax errors and exceptions so that scripts run successfully.

The first script we were tasked with contained two syntax errors. Syntax errors are similar to making typographical errors or saying you are grammatically incorrect. Some common issues related to syntax errors are misspellings, lack of punctuation, wrong use of upper/lowercase letters, and indentation issues. This first script when successfully run prints out the names of all fields in the attribute table of the ArcGIS Pro Project we were working with.  Below is a screenshot of my script output after correcting the two syntax issues.


The second script contained several errors/exceptions. These included issues with the undefined filepaths, forward and back slash issues, misspelled variables, and other issues mostly related to misspellings. These types of named exceptions present with messages including names such as NameError, AttributeError, and TypeError. Ultimately I was able to get the script to run, however I was receiving an OSError. After doing a quick Google search for OSError in ArcGIS Pro I found an ESRI discussion post saying that this could likely be due to having the project open and running. I then closed the project and ran the script.  the script ran successfully without any error messages. When successfully run the script prints out the names of all the layers in the ArcGIS Pro Project. Below is a screenshot of the output after all the errors/exceptions are corrected.



The third script involved running a script even though it contained errors. This is done by modifying the script by adding a try-except statement. The challenge here was deciding where the try-except statements need to be placed in order to make the script run successfully despite containing errors. When used, a try-except statement can catch and handle exceptions, thus avoiding a runtime error and sudden termination of a script. The script contained two different parts where Part A returns an error message but continues to run Part B printing out the name, data source, and spatial reference of each layer. Below is a screenshot of the script output after successfully placing the try-except statements as well as a flowchart depicting the steps I took in the process.







After feeling overwhelmed and defeated by last week's module I was very concerned coming into this week. However, after spending some extra time trying to get a grasp on things this module went much better than I anticipated. Hopefully, I can continue to move forward and build upon what I have learned.










Applications in GIS - Module 6 - Suitability & Least Cost Analysis

In Module 6, we learned about Suitability and Least Cost Path Analysis. We were introduced to performing suitability analysis using both vec...