Module 7 was definitely a challenge. We covered a lot of material in two chapters (6 and 7) of our text. We learned how to check for, describe, and list data. Next, we worked with lists, tuples, and dictionaries. Lists are used to facilitate batch processing and exist for different types of elements. "For" loops can be used to iterate over the elements in a list. Elements in a list can be modified through operations such as deleting, appending, and removing. Tuples are similar to lists but their elements are immutable. If you use an operation that would modify the elements in a tuple it returns another tuple. Elements in lists and tuples can be identified by their index number or location in the list or tuple. Dictionaries contain item pairs. The pair matches a key to its corresponding value. Dictionaries can be modified however "keys" have to be unique but "values" do not. For example a dictionary containing city and state pairs might have a "key" of the city "Greenville". The corresponding state "values" for the city of Greenville could be different, such as Alabama, North Carolina, South Carolina.
Chapter 7 introduced us to using cursors to access data. Cursors work similarly to list functions and can be used to iterate over rows in a table. There are three types of cursors. Search cursors are used to retrieve rows. Insert cursors are used to insert rows. Update cursors are used to update and remove rows. All cursor types have two required arguments: and input table and a list of field names. A SQL query can be used to establish criteria for the optional "where_clause" parameter of the cursor object.
This assignment tasked us to use Python code to create an empty geodatabase (gdb) and then copy the shapefiles from our Module7/Data folder into the new gdb. Using the "cities" feature class that was now in the gdb we needed to populate a newly created dictionary with the names and population of every "County Seat" city in the state of New Mexico. To perform these tasks it was important to understand the examples provided in our text and module exercise. Syntax was very important in creating the python code needed for the search cursor that would find the cities that were defined as "County Seats". The syntax format differs depending on the feature class type. Each beginning single quote, double quote, parenthesis, or bracket needs to have a corresponding ending. Placing "print" statements within the script helped identify the location of errors when the script failed to execute entirely.
Learning how to update a dictionary was also new. This step was the most difficult for me to understand. I had to think about where the search cursor was in the table and think about what were the "key" and "value" pairs. Using the examples in the text for printing rows in the table, helped me understand where the cursor was in the table and how to update the dictionary.
Here's my flowchart for the assignment script and a screenshot of the results after running the script.
|
No comments:
Post a Comment