Monday, June 15, 2020

Working with Geometries


The lesson this week was working with geometries.  This is a very useful and practical skill, as you can use python to transcribe data into a text file, or to take data and use it to create something within ArcGIS.  When you can have data for hundreds of polygons each with multiple points this is much easier than doing it all manually.

Our assignment was to create a .txt file within python and then write data from a river shapefile to that document.  This is done by creating a search cursor and setting the appropriate parameters that we will use to loop through each feature.

This process uses a nested loop.  The first loop uses the cursor to iterate through each row.  We then need a second loop to iterate through every point of that feature.  Within the previous loop, I created a variable called "vertexID" and set it to zero.  In the next loop, every point it goes through it increments up one.  This labels each point within a feature.  In the nested loop we use the .getPart() function on the row to create an array of points within each feature.  At this point I have the program transcribe the object ID, vertex ID, X coordinate, Y coordinate, and feature name to a line of text in the created file.  I also have the script print out each of these lines in the console so I can see the program's progress and check for errors.

The output of the program, showing each point within each feature.
A flow chart demonstrating how the nested loops work within the program.




No comments:

Post a Comment