Module 7 - Exploring and Manipulating Spatial Data



We covered a lot of ground this week, two chapters worth! Some of the topics and concepts we reviewed included: checking for existing data and describing it, manipulating lists of data and dictionary objects, the different types of cursors and their uses, and using SQL expressions in search cursors.

For our lab assignment, we were tasked to write a script that went through a series of steps: creating a geodatabase in a specified folder; setting our workspace to a data folder; creating a variable that returned a list of shapefiles located in this data folder; copying all of these shapefiles into the newly created geodatabase (which required using a for loop and using the basename property from the arcpy.Describe() function, since shapefiles are converted to feature classes when imported into a geodatabase and thus must lose the .shp file extension); creating a SearchCursor on the feature class called "cities"; retrieving data from fields "NAME", "FEATURE", and "POP_2000" from this "cities" feature class where the cursor only retrieved cities' data listed as "County Seat" from the "FEATURE" field (which required creating a delimiter field, and then using a SQL query in the where clause parameter section of the SearchCursor line code); creating an empty dictionary; creating a for loop to populate the empty dictionary with "NAME" (as keys), and "POP_2000" (as values) of all "County Seat" cities; and finally, printing this dictionary.

Additional deliverables that were required within our script included printing messages at the beginning and end of each step (there were 8 steps total), as well as including the arcpy.GetMessages() function for steps that used a geoprocessing task (which were Steps 1 through 4.) Screenshots of my results are shown above.

I got really choked up on Step 7. I was having a really difficult time understanding how to assign keys and values to the empty dictionary with the selected features we obtained from the SearchCursor. Our textbook and lab exercise showed us examples of manually created dictionaries, not ones in a "memory state-like", and thus I didn't know how to go about associating them into the empty dictionary. Additionally, I was unnecessarily scripting two for loops back-to-back. After many hours of troubleshooting, I finally got it to work. Although a very challenging and frustrating step of the lab assignment, it was a good experience and heck of a learned lesson.

Comments