Lab 6 [GIS5103]: Working with Geometries
The screenshot above shows the output from this week's lab where skills emphasizing working with geometry objects were addressed. In the output above these skills were used to read a shapefile and then write specific information on each feature to a text file. The items on each line in the output file included the object ID number, vertex count number, X coordinate, Y coordinate, and feature name. The general pseudocode was as follows:
Start
Step 0: (Setup)
Setup input filepath
Setup output filepath
Step 1: (Prepare output file)
Create output filename
Open output file for
writing
Step
2: (Write details to output file)
Create search cursor to
extract OID@, SHAPE@, NAME for each feature
Iterate through each
row/feature in cursor
Set vertexID to 0
Iterate through the
points in each feature (using getPart)
Increment vertexID
by 1 (starts count at 1 for each set of vertices)
Convert OID to
string
Convert vertexID
to string
Convert point.x to
string
Convert point.y to
string
Store NAME in
string variable
Write five text
strings to output file (ending with line break character)
Write five text
strings to screen (ending with line break character)
Cleanup: close output
file
Cleanup: delete cursor
and row
End
Key take-away points during this lab included proper set-up of the search cursor and then understanding how to use nested loops to iterate through the features and the associated array of geometry objects. The use of geometry tokens was also addressed, including their time-saving utility as shorthands to extract specific geometric properties. Finally, the importance of cleanly formatting screen output as well as text-based output files with the "\n" character was covered.
Comments
Post a Comment