|
Python Script Output |
This weeks assignment was to dive deeper into Python scripting by manipulating lists, dictionaries, tuples, and using cursors. List, dictionaries, and tuples are similar in that they store indexed data, however there are nuances to each that allow for diverse usage. Spatial data is often stored in some sort of indexed format (tables) which must be easy to reference and manipulate. The assignment here involved generating a geodatabase and editing some fields of a feature class within.
At right is a screenshot of my script output, which was used to select only county seats from a list of cities and then match each county seat with its population using a dictionary. Below is a discussion of some issues I had during write-up and how they were overcome.
I had the most trouble with Step 5, which involved setting
the search cursor to retrieve three fields while using an SQL query to only
select County Seat features. The issues occurred
in three places of this step: 1) Setting
the workspace; 2) calling the correct feature class; and 3) determining the
syntax of the Search Cursor.
The first issue was merely an unnoticed typo, but it cause a
lot of troubleshooting because I thought other parts of this step were causing
the error message. Typos are small
errors that can cause big headaches.
Once realized this, it was quickly fixed and I moved on.
The second issue was a result of not knowing what file
extension to use for the feature class cities
in the new geodatabase. I first used
.shp, but this gave me an error saying that the file could not be located. I then used windows explorer to determine if
the extension had changed, and I found that it had changed to .spx. Therefore I tried calling the feature class
using this extension. This again gave
me the same error message. I then
thought that perhaps the basename extraction step (i.e. removal of .shp during
copying step), produced a file with no extension, therefore I tried simply
using ‘cities’, and this worked. I then
moved on to issue three.
Issue three was the toughest because I wasn't sure whether
to use brackets, parentheses, quotation marks, commas, semicolons, etc. when
using the Search Cursor. Essentially the
amount of info that was covered this week left me a little confused. I realized, however, that I was over-thinking
the problem. I knew that the three
fields needed to be within brackets, separated by commas, and within quotes. Then I referred back to the exercise to
determine how to use the SQL query, which was straightforward.