This week, we explored vector geometries in Python. We were given a rivers shapefile with 26 objects and 247 vertices and were tasked with writing a script that would create a new text file, identify the OID, vertex ID number, X coordinate, Y coordinate and feature name, and write those parameters in the newly created text file. Below is a snippet of the completed text file after the script has been run.
Below are some of my notes related to this project, and a brief pseudocode describing the process.
Start:
Import arcpy catalog
Set environment
= S:/GISProgramming/Module6/Data
Overwrite
Workspace = True
Create new
text file, make file writeable
Specify
cursor to search through fields in a shapefile
Create a loop
to iterate through fields
Nest loop to allow the cursor to
find vertices of all points in a multipoint file
Write code to text file with
following paramaters:
OID, Vertex ID number, X
Coordinate, Y Coordinate, and Feature Name
Print statement equal to the code
that is written to the text file
Close text
file
Delete cursor
End
1 I struggled the most with grasping the concept of row[0, 1, 2] as a representation of the Search Cursor parameters. Once I finally grasped this concept (which was very obvious when reading through the arcpy catalog help), I was able to finish the code with relative ease.
2 As with all previous labs, the logic of python becomes obvious once you write a code sequence correctly. It can feel defeating at times, but when you finally have that aha moment, it all comes together and you feel your knowledge of the language take a leap forward.
3 I cannot express enough how helpful it is to have relatively little guidance on the lab assignments because they force you to really think and solve the problems on your own. This makes it difficult, but the learning is increased because of the need to figure it out for yourself with snippets of the solution scattered through the exercises and readings. It makes me feel as though any problem is solvable with Python if you are willing to take the time and solve it.