Thursday, June 20, 2024

GIS 5103 Module 6 - Manipulating Geometries

For the final module of GIS Programming, we explored the many different ways to manipulate geometrical datasets using Python scripts. All datasets that we have worked with in this course have been vector data, or data that consists of points, lines, and polygons. At its core, these three data types are made up of either one vertex [point feature classes], or multiple vertices [line and polygon feature classes]. Something to note here, is that line feature classes can consist of one line segment [the distance between two geographical points, or vertices]; however, they can also be made up of many line segments, with each segment having two vertices. If the feature is a continuous line segment, the last vertex of one segment will match the first vertex of the next. When working with polygons, the coordinates of the first vector will match the coordinates of the last vector; this ensures that the polygon is, in fact, a closed, areal entity.

How can this geographical data be stored and manipulated by a Python script? In short form, a for loop can be used to extract all the desired information pertinent to each object within that specific feature class; this information is stored as an array. From this point, a nested for loop can be ran [using a specific geometry token] to retrieve geographical coordinates for each vertex that is responsible for making each feature. Once, this token has been used to extract the point data of each vertex, the data can be manipulated and used in other geoprocessing tasks.

For this assignment, we were asked to create a script that iterates through each object of a feature class, extracting all vertices that make up that object, number each vertex within the object, and also extract the name associated with said object [the feature class we were working with was named 'rivers']. Finally, we were to print the output to the screen and to a .TXT file so a comparison could be made to ensure the script was accomplishing the task at hand.

As shown in the flowchart below, all standard coding procedures were performed first, such as importing modules, setting the working environment, and setting any variables needed to run the program. Next, the script prints a message stating an empty .TXT file is being created; the file is then created, followed by a subsequent message that informs the user that it was created successfully.


Next, the script initiates a search cursor and enters a for loop that iterates through each feature included in the 'rivers' feature class. Once inside this first for loop, a counter begins that will number each vertex within the current feature. The code then enters a second for loop which will extract each vertex of the current object. Once the final vertex is reached, a blank line is printed to separate each of the features [for legibility purposes], and the code returns to the initial for loop progressing forward to the next feature in line, entering into the nested for loop once again. After the script has progressed through the entire 'rivers' feature class, a 'script completed' message is printed to the screen. Finally, the 'row' and 'cursor' variables are deleted, and the script closes the .TXT file. The results of the script can be seen below:

While the logistics of this script were fairly simple, it does instill some curiosity as to how advanced Python scripts can get in regard to geometrical manipulation of vector datasets. I am positive that this could be a career-long endeavor, with endless possibilities. As I have said in previous posts, I am eager to dive deeper into the capabilities of Python scripting.

No comments:

Post a Comment

GIS 5935 Module 2.2 - Surface Interpolation

  Post in progress - please check back soon...