Module 8 - Working with Geometries

In this week's lesson we learned how to read and write geometry objects (vector data) using Python. We were introduced to "geometry tokens" and their usage as shortcuts to specific geometry properties while scripting. We also learned how to work with: multipart features, polygons with holes, cursors to set spatial references, and geometry objects to work with geoprocessing tools.


For our lab assignment, we were tasked to write a script that creates a text (.txt) file of all the coordinates of all vertices of a polyline shapefile called "rivers", along with the name of the river/stream, and its associated ID number. To successfully run the script, we had to accurately go through a series of steps that uses nested loops iterating through parts of a cursor variable. Above is a screenshot of a flowchart I created depicting the flow of my script through pseudocode. And below is a screenshot of my results after running my script.


Some important notes to remember when working with geometry objects include:
  • when working with polylines or polygons, extra iteration is required to interact with the array first, before getting to the points that make up the array; and
  • for multipart features, cursors return an array containing multiple arrays of point objects; and
  • working with multipart features therefore requires an extra iteration over the parts of each feature (need to loop over the arrays in the array, and then need to loop over each point in the point array).

Comments