Programming Week 5: Exploring and Manipulating Spatial Data
For this week's lab, we wrote a script that created a new geodatabase, copied data from the Data folder into the geodatabase, used the arcpy.SearchCursor() function to search a feature class of cities in New Mexico for county seats, and created a dictionary of county seats in New Mexico and their populations.
Here is the complete output from the final version of my script:
I had several issues with the step in which we had to create a SearchCursor for the citie first error I got was “RuntimeError: ERROR 999999: Something unexpected caused the tool to fail” for the line “with arcpy.SearchCursor(fc, fields, '"FEATURE" = \'County Seat\'') as cursor:”. I then tried several different ways of handling the field names (for example, by deleting this for loop I wrote and calling getValue individually for each field name:)
for field in fields:
print(row.getValue(field))
Eventually I got a new error: “AttributeError: __enter__”. I looked this up and it had to do with the with statement, so I changed that to the simpler assignment statement “cursor = arcpy.SearchCursor(fc, '"FEATURE" = \'County Seat\'') “ and it fixed it. I got the same error for the dictionary block of code, which I was able to easily fix in the same way.
Comments
Post a Comment