GIS Programming Module 4: Explore & Manipulate Data


Creating a new geodatabase:

Spyder Console:

Flowchart:


Using search cursor to identify and list the population of every county seat city in New Mexico:

Spyder Console:

Flowchart: 



Populating a new dictionary with the names and population of each county seat:

Spyder Console:

Flowchart:



I believe that I encountered the most script errors to date while working on this module. In the exercise, I had a bit of a difficult time working with the update cursors. The update cursor can be used to edit or remove information in the attribute table. In the first part of the example, we used the code  line “cursor.update.Row()” to fill in blank fields in the attribute table with the state. While working in Spyder, I encountered a ‘Lock Error’. To solve this I closed ArcGIS Pro on my desktop and successfully ran the script. In the second portion of this exercise, we used the code line “cursor.deleteRow()” to remove all records in the airports feature class with fewer than 100,000 passengers from the attribute table. The first time I ran the script, I deleted my entire attribute table for the airports layer. I tried to solve this by copying and pasting the files for the airports shapefile from my data folder to my geodatabase folder. Afterward, I received a type error with the if statement “if row[0] < 1000000:”, I tried adjusting and tweaking the script, as well as restarting the desktop and reopening Spyder, and I have not yet been able to resolve the problem in the script. 

In the assignment, creating the new geodatabase went smoothly. I liked learning how to copy and paste files and create new databases all from code entered into Spyder. Working with the search cursor was tricky. I found that I reviewed too many different examples of how to enter the code, and attempted to enter all of them. The result was that nothing worked, and I didn’t know where to start with resolving the errors. I needed to take it one row at a time. I restarted and made the most basic portion of the code print first – the name of the cities in the feature class. Then, once that worked, I felt less overwhelmed and modified the code to list the feature and the population. It was still slow going as I figured out what code language gave me the results I wanted and what didn’t. I was successful when I worked one step at a time. 

This week I really started to see how well python code works with ArcGIS. It was a challenging week, as I worked through syntax and type errors left and right in my code. I worked slowly through the Search Cursor and Dictionary code. I didn’t quite understand how to get the where_clause and delimters to work. Eventually, after a lot of trial and error, the code listed the cities, features, and populations as I needed it to. It was helpful to print messages and use the “arcpy.GetMessages()” code line so I could follow the results in the Spyder console.

Programming takes patience. I am finding that I am becoming familiar with patterns in the code and how each line of code works and interacts with the next line. I am also becoming more efficient at researching solutions and fixing my mistakes. 

Comments