Module 5 - Explore & Manipulate Data
This module was information overload and I had to like dig deep through my brain on our past modules. But it was rather exciting and awesome that I was able to finish this script. I really appreciate the comments a lot and the flowchart. That was the MOST HELPFUL part of this class as I was able to cut them into pieces and debug the codes accordingly per piece.
For the first 2 parts was easy, creating an fgdb and copying the shapefiles to the fgdb since it was straightforward done in the Exercise module. I had some difficulties with the iterating over cursor and dictionary. With the iterating over cursor, I was stuck in printing the POP_2000 values at it returns that it is an integer and not a string. So I did a lot of workaround and ended up even reducing my code lines. So I combined the print output instead of defining them then printing results. What I did then is to add format() for my row value so that it converts my integer value to string. Also, I wasn't so sure at first with the -999999 values since they were not printed out in the screenshot example on the Assignment PDF document and then saw that it was included in the sample screenshot that was in the zipped file example. So I continue on not removing the -999999 and moved on with the next code.
Next one, was populating my dictionary. I think I got the part quickly but was stuck at some point in adding them into the empty bracket. Although reading through a lot of comments by my classmates, I realized that I can actually combine the codes for the first one and this one but I just separated them both since I'm still a newbie and I might encounter more issues. So I ran the for loop again in here and assign the values for NAME and POP_2000 accordingly and then use the values to update the county_seats dictionary. Finally called print after the for loop.
Here's the final output (screenshot) of my code:
Here's the flowchart (screenshot) for my code so each column is divided into parts: (1) Creating the fgdb, (2) Copying the shapefiles into the fgdb, (3) Iterating over cursor, and (4) Dictionary.
Important notes to remember:
- Path/File names are not case-sensitive unlike strings.
- If the user is running a stand-alone script from other IDEs besides adding env.overwriteoutput = True, make sure that ArcGIS Pro is closed. An open ArcGIS Pro may place a shared lock on the data that you might be using that can also prevent it from being overwritten.
- Dictionary is contained by braces {} and not ()
- Keys and values for the dictionary are separated using a colon : and are separated from each other using a comma ,
- Be careful when printing results like feature class in your IDE as some feature class can contain a lot of records (thousands and even millions).
- For the SQL expressions when defining field delimiters with numeric/integer value only the field names are enclosed in quotation marks and not the numeric value (e.g. “POP_2000” > 10000).
- But (referencing #6) for an entire SQL expression to be called please use quotation marks for the script (like using WHERE clause in the syntax of the search cursor). So, your example in 6 wil now be ‘“POP_2000” > 10000’. *THIS IS ONLY APPLICABLE FOR INTEGER FIELD*.
- Referencing #7, if your using the WHERE clause for a text field please avoid using too much quotation marks as it can create complications. Use the escape character (\) instead. So ‘“NAME” = ‘Las Vegas’’ should become ‘“NAME” = \’Las Vegas\’’
Comments
Post a Comment