GIS4102 - Module 6 - Working with Geometries

For this module it was tasked of us to create a TXT file based on data given to us and write to it the coordinates and object IDs for vertices in a shapefile. We were given a script template to help guide us through the process. Essentially the process was to import the modules needed and enable overwriteoutput, create a seach cursor for the OID field, the SHAPE geometry object, and the NAME field. Create a TXT file, write data to said file and create a for loop for each feature in the shapefile. We then created another loop for each point in array and used the getPart() method to access the
points/vertices in each array. Below is a pseudocode of the process in a more specific way.

                Start 

                            # Step 1: Setup 

Import necessary modules 

Enable overwrite output setting 

Set the workspace to the Module6 Data folder 

Define the feature class variable for rivers.shp 


# Step 2: Prepare to write .txt file 

Open rivers_dji4.txt file for writing 

Create a search cursor for rivers.shp with fields OID, SHAPE, and NAME 


# Step 3: Write to .txt file using for loops 

For each row in the cursor: 

Set vertex_id to 0 

For each part in the row's geometry: 

For each point in the part: 

Increment vertex_id by 1 

Write OID, vertex_id, X coordinate, Y coordinate, and Name to the text file

Print the same information for debugging 

# Step 4: Close the .txt file 

Close the text file 

Delete the cursor 

End

 

With the code completed and correctly running, a resulting piece of the code is shown below, showing all 25 features.




 

Comments

Popular posts from this blog

About Me

GIS4048 - Module 6 - Suitability Analysis (Part 2)

GIS4930 - Module 2.2 - Interpolation