Sunday, July 5, 2015

Module 7 - Explore/Manipulate Spatial Data

In this assignment, we learned to explore and manipulate spatial data in Python. I found this to be a great introduction to manipulating spatial data and I learned how to use some functions that I had no experience with. The objective was to create a script that created a new geodatabase, copied data from the data folder into the new geodatabase, and populated a dictionary with the names and population of county seats in New Mexico.
First I imported the modules and set the environments so that the output could be overwritten. Then I created a new geodatabase and set my current workspace. I needed to create a variable returning a list of all feature classes in the workspace folder. I used a “for” loop to copy feature from the workspace to the new geodatabase. Here, I made a simple mistake that took a little bit to find. I inadvertently set the workspace and the new geodatabase to the same location, so I had to correct that. The new files use the basename property from the arcpy.Describe() function. I then created a search cursor for the cities layer. It took a while to get the syntax correct, and I tried some different options with delimiting the FEATURE field. This part of the lab was tricky with getting the single and double quotation marks correct. Then we started working with dictionaries. I created an empty dictionary, which I was to then populate. This step took me the longest, and the issue was mainly just figuring out the proper syntax to do what I wanted to do. I wanted the county seats and their populations, but I had to select the county seats from the cities field, which added some complexity to the script. I added print messages to each step and made sure to comment the script.


Looking back over the exercise for this assignment was a big help, as sometimes I couldn’t remember the syntax exactly or which command to use in my script. We were provided a template, which was helpful for the most part. It was helpful to see in which order we were to perform a step, but sometimes when the code for that step was only one line I wondered if I was missing something. I also have a comma in my dictionary instead of a colon separating the fields in the output; I’m not sure what’s causing that, but the code does work without error. Below is a screenshot of the output (no actual code).



No comments:

Post a Comment