Tuesday, June 21, 2022

GIS 4102 - Module 5 - Geometries

The second to last module for my GIS programming course has been completed and I can safely say that I now have a better understanding of how to reference geometric data in python. This weeks module 5 tasked us with creating a script that could write 5 specified values for each reference point of the rivers.shp shapefile. The following is my psuedo script that walks you through the processes of each line of code. 

START
Import modules
Set workplace
Set output location
Enable overwrite output setting
Define feature class variable
Open .txt file and enable writing
Create search cursor to call on OID, SHAPE, and NAME fields
Start a for loop to iterate through each row in the cursor
        Define variable to act as vertex ID number
        Print row being referenced as “Feature #:”
        Start nested for loop to iterate each part being referenced
                  Print part being referenced as “Part #:”
                  Start nested for loop to iterate each point in part being referenced
                            Print row information pertaining to X and Y coordinate data
                            Add one value to vertex ID
                   Write method to add the five values:
Feature OID, Vertex ID, X coordinate, Y coordinate, Name of
                     the river feature
to .txt file
                    Print the five values:
Feature OID, Vertex ID, X coordinate, Y coordinate, Name of the river
                     feature
Close the .txt file
Delete the row variables outside of the for loops
Delete the cursor variables outside of the for loops
END

Here is a screenshot of the rivers_atg6.txt file after the write function had been completed, along with the console successfully showing the script ran in spyder.


Some issues I encountered over the course of this module involved referencing field values, indenting nested for loops, and referencing rows. The first problem I ran into was a simple fix but took quite some time to identify. While I was using correct syntax to create the search cursor I did not realize that the NAME field did not require an @ symbol due to it being a text related field and due to it not containing any geometry to be referenced the @ symbol was not necessary. Once this issue was sorted and all of the fields or columns were being referenced correctly I ran into my second and third problems, indenting my nested for loops and referencing rows correctly. After reviewing the module instructions and exercise information I opted to nest my for loops in a way that iterates the rows being referenced and defines the point variables for X and Y coordinates allowing the write and print functions to work correctly how I have them written. The result was print statements in the spyder console for each feature being referenced (OID), each part of the feature being referenced (vertexID), each X and Y coordinate for the feature (X,Y), and the feature name (NAME).


No comments:

Post a Comment

Spring 2023 semester wrap up

 The spring 2023 semester at UWF has been an eventful one in which I finalized the requirements for my bachelors of science in natural scien...