Wednesday, July 19, 2017

GIS Programming Module 8: Working With Geometries

This week we learned how to use Python to access geometric elements of features, like their shape type, coordinates, and length/area. For the assignment, we were tasked with writing a script that would iterate over all parts of all features in a shapefile and write the coordinates of each vertex, along with ID numbers and the name of the feature, to a separate text file (created within the script).

The first step is to create a search cursor to find the necessary data > then create a writable text file > then loop over each feature > and for each part of each feature, print the vertex coordinates and other data to both the text file and the interactive window.

Here's the pseudocode I wrote to show how the script works:

Cursor = OID, Shape, Name in rivers.shp
Text = rivers.txt
For row in cursor:
     Vertex = 0
    For point in row
        Vertex + 1
        Write to text OID, Vertex, X and Y coordinates, and Name
        Print OID Vertex, X and Y coordinates, and Name

And here's part of the text file my script produced:


For me, this was definitely the hardest assignment yet, but I was really looking forward to this lesson and I'm glad to be starting to understand how manipulating geometries works.

No comments:

Post a Comment