GIS Programming Module 5: Exploring & Manipulating Data
The assignment for Module 5 involved working and manipulating data using an external Python script. The script creates a file geodatabase, copies existing shapefiles into the geodatabase, and uses cursors to view and print feature attributes.
Part 1 of the script sets the current and output workspaces for the assignment. The current workspace contains all the shapefiles that were provided. The output workspace will contain all the results of the script including a copy of the shapefiles and the file geodatabase. Below are the output messages printed for Part 1 of the script.
Part 2 of the script lists all the shapefiles that are stored in the current workspace and copies them to the output file geodatabase. Below are the messages printed during Part 2 of the script.
Part 3 of the script creates a Search Cursor containing all
the features of the cities feature class that is stored in the output file
geodatabase. The cursor only contains cities that are county seats and only the
name, feature type, and population fields. The script iterates through the
cursor and prints the city name, feature type, and 2000 population. Below are
the output messages the script prints for Part 3.
The last part of the script creates a dictionary and
populates it with all the county seat cities. Below are the output messages the
script prints for Part 4.
One of the challenges that I had with the script was getting all the print statements to look good and be consistent throughout the script. I needed to rerun the script a number of times to get the results that I wanted.
The other issue was deciding on whether to use the new cursor or the legacy cursor. The legacy cursors arcpy.InsertCursor, arcpy.SearchCursor, and arcpy.UpdateCursor are still supported, but the book suggests that the new arcpy.da cursors should be used, since they are faster than the legacy cursors. I choose the legacy cursor since that is what was demonstrated in the module lecture and lab exercise.
The script uses a search
cursor to iterate through the cities features and print the population. I
choose to create an “if” statement to replace cities that had -99999
population to “unknown” when printing the populations.
Flow Diagram
Comments
Post a Comment