In this lab assignment, I used python to iterate through fields in a shapefile and extract information of interest and write it to a .txt file. Below is pseudocode that outlines the steps that I took to extract the OID, vertex number, vertex X-coordinate, vertex Y-coordinate, and name field for each feature in a rivers shapefile. This an extremely valuable tool for accessing information stored in the features and attribute tables of feature classes.
Part 1 was very straightforward. I started by importin the module, setting the workspace, identifying the directories, and loading the feature class “rivers.shp”. I added a print statement at the end to track the progress of the script.
Part 2 was much like part 1; I had little difficulty setting up the script. I created the TXT file and the search cursor that I would use to iterate through the “river.shp” attributes. The one mistake that I made initially was treating the NAME field. I accidently added an @symbol after NAME which led to an error; however, I quickly realized the mistake removed the @ symbol since fields from feature classes can be called directly in the search cursor since the feature classes is specified prior to the fields.
I had significant troubles with part 3. The difficulties in this step were largely due to my poor understanding of the proper organization of the script that was necessary to achieve the desired outcome. After reviewing examples in the lecture and the exercise I was able to make the necessary edits to the script so that it was printing the desired information. Once I knew everything was printing properly, I used the write function to update the TXT file.
In the last part, I deleted the row and cursor. Then I closed the TXT file. Last, I added a print statement to indicate that the script had finished writing to the TXT file.


No comments:
Post a Comment