GIS Programming: Exploring and Manipulating Data

Two of the most common methods for exploring data are through the Describe() function and the ListFeatureClasses() function within the arcpy package. The Describe() function allows one to explore the properties of a particular dataset, such as data type, file path, base name, etc., and  the ListFeatureClasses() function creates a list of all feature classes within the current workspace. Tabular and spatial data can be manipulated with the use of cursors, which allow one to iterate over the records in a table or insert new records. There are three types of cursors, namely search cursors, insert cursors, and update cursors. 

In this weeks lab, we used the ListFeatureClasses() and Describe() functions to copy all the features in our Module 4 Data folder into a new file geodatabase. We then used a search cursor to locate all the county seats of New Mexico within the "cities" feature class and printed the name, population, and feature type of each county seat. Lastly, we created an empty dictionary and used another search cursor to populate the dictionary with the county seats as keys and their corresponding populations as values. Below is a conceptual flowchart for the script. 

Script flowchart



The step I had the most trouble with was populating the empty dictionary with the county seats as keys and their corresponding populations as values. The issue I was having was finding the correct syntax for the keys and values when using the second option described in the lab for adding pairs of items into a dictionary: 

 <dictionary variable>.update({<key>:<value>})

Earlier in my script, I had set the variables field1 and field2 to “NAME” and “POP_2000” respectively. The syntax that finally worked for me was: 

key: row.getValue(field1)
value: row.getValue(field2)

Below are the results from my successful script. 

Script output in Spyder

Comments

Popular posts from this blog

Isarithmic Mapping: Annual Precipitation in Washington State

Spatial Enhancement, Multispectral Data, and Band Indices

Development Suitability Analysis