The program accesses the Object IDs, point data for all vertices, and attribute data (such as the name of the feature) for features in a polyline shapefile (by way of the Search Cursor). Using a series of nested for loops, the point data for the vertices is gathered and written to a text file (.getPart(), .write, and string module). Below is a screenshot that prints the data (that was simultaneously written to a text file). The program also contains print statements to keep track of what steps of the program have been accomplished.
While I found this module conceptually straight forward, I had some issues writing the script for this program. Specifically, I had issues writing information to a text file. This was mostly due to improper syntax and an incorrectly tabulated iterative line of code. Once I let it sink in that the Search Cursor returns tuples, I found the syntax much easier (like properly referencing and printing the data within the tuples). The solutions to my issues were so simple but I got really hung up on them. I hope my DUH moments are easier to catch in the future.
A screenshot showing the results of a program that writes geometric and attribute information to a text file. |
While I found this module conceptually straight forward, I had some issues writing the script for this program. Specifically, I had issues writing information to a text file. This was mostly due to improper syntax and an incorrectly tabulated iterative line of code. Once I let it sink in that the Search Cursor returns tuples, I found the syntax much easier (like properly referencing and printing the data within the tuples). The solutions to my issues were so simple but I got really hung up on them. I hope my DUH moments are easier to catch in the future.
No comments:
Post a Comment