The week saw us going further with the use of cursors and nested for loops. Our exercise and assignment allowed us to explore getting coordinate data from points, lines, polygons and multipart features. Although I was a little confused on the exact function of cursors when they were first introduced, this module helped me get a better understanding of their syntax and use.
An additional task required by the assignment was to create and write to a text file (see screenshot above). This was covered in a previous chapter, so I am glad to get experience with editing text files in Python this week. It is interesting to see how the syntax learned in previous modules is incorporated in new tasks each week. I have even begun experimenting with Python in my internship, with varying levels of success.
Below is a copy of the pseudocode from my process summary. Pseudocode is something I have neglected a bit throughout the course, but I can see how useful it would be as scripts increase in complexity.
Start
import modules
allow overwrite of previous
data
set workspace
variable1 =
"rivers.shp"
set search cursor to retrieve
variable1's "OID" and
"NAME" fields + full geometry object
create/open writable text
file "rivers_tevans.txt" in S:\GISProgramming\Module7\Data
begin for loop for cursor:
print
"NAME" field
set index variable/vertex
ID
for loop for point
in row with .getPart function
add 1 to index variable
write to text file row's OID, Vertex
ID, X coordinate, Y coordinate, and name
print OID, Vertex ID, X coordinate, Y
coordinate, and name
close text
delete row and cursor
No comments:
Post a Comment