Sunday, July 10, 2016

GIS5103 - Module 8 - Working with Geometries

Module 8 required us to edit an existing script template to understand how to work with geometry objects.   Our assignment taught us how to work with spatial data using a specified shapefile, rivers.shp.   We learned you can access the entire geometry object or use geometry tokens to as shortcut to access certain geometry properties.  Using search cursors and for loops you can iterate over rows and arrays to provide specific information about individual points/vertices.  Point feature classes have a single point object for each feature but polyline and polygon feature classes have an array of points/vertices for each feature. 

The assignment required us to create a search cursor to locate/call the OID/Feature # field, the SHAPE geometry object, and the NAME field.   We used the token SHAPE@ token to return the full geometry of our rivers shapefile features.  Next we used the "open" command to create a text file set in writing mode that could be written to.   Using nested for loops we first used the cursor to locate each feature and then in the next for loop used the "getPart()" method to call for five items for each vertices for each river feature.   The five items (OID#, VertexID, XCoord., YCoord, and River Name) were then written to the newly created text file on their own line.   Creating a vertexID variable to act as a counter enabled us to keep track of all the vertices in each river feature.   After successfully running the modified script, the completed text file contained 26 different features with a total of 247 vertices.

The most difficult part of this lab was wrapping my head around arrays and how search cursors can be used to call/locate fields and geometry objects in the arrays.    Having examples from the text and exercise help tremendously in ensuring the correct syntax is used to call the needed items.  

Below is the flowchart for the Module 8 script I modified.


Flowchart Module 8 Script


Here are the screenshots from opening the text file that contained the five items for all of the vertices for each feature in the rivers shapefile.




Module 8 Text File Screenshots

No comments:

Post a Comment