Lab 5 [GIS5103]: Exploring and Manipulating Data
The screenshots above represent the output from a multi-part Python script that performs the following steps:
- Step 1: Create and initialize a new geodatabase
- Step 2: Create a Search Cursor for cities associated with county seats
- Step 3: Create and initialize a dictionary for cities associated with county seats
The initial pseudocode for these script requirements included:
START
Step 1:
Setup
filepath naming
Create new geodatabase
Iterate over features in Data:
Copy feature from Data folder into new
geodatabase
Print name of copied feature to screen
Step 2:
Setup filepath naming
Setup field list of specific attributes
within cities feature (NAME, FEATURE, POP_2000)
Use search cursor to grab a copy of
specified attributes associated with cities listed as 'County Seat'
Iterate over search cursor:
Print attributes of each record to
screen
Step 3:
Setup filepath naming
Setup field list of specific attributes
within cities feature (NAME, POP_2000)
Create empty dictionary county_seats
Use search cursor to grab a copy of
specified attributes associated with cities listed as 'County Seat'
Iterate over search cursor:
Copy attributes to dictionary as
key=NAME, value=POP_2000
Print completed dictionary to screen
END
Key Python constructs emphasized during this week's lab included search cursors, lists, and dictionaries. The following resources were helpful for implementing these constructs:
- Esri: Search Cursor (syntax and usage) - a key take-away from this page is the difference between arcpy.da.SearchCursor and arcpy.SearchCursor (be sure to pay attention to the parameter lists and associated data types)
- YouTube: Python Concepts - Iterators vs Iterables - this video explains what is happening under the hood with iterators and their associated methods in for loops (use it to understand what is happening when iterating over a search cursor)
Comments
Post a Comment