Module 6: Writing Geometry Data to a Text File Using Python

 For this week’s lab, I used a Python Notebook in ArcGIS Pro to write information from a shapefile into a text file. The shapefile used was rivers.shp, and the goal was to loop through each river feature and pull-out important geometry info like the vertex ID, X and Y coordinates, and the river name. That data was then written to a text file in a clean, readable format.


I started by setting the workspace to my Module6 Data folder and enabling overwriteOutput so I wouldn’t get errors if I had to rerun anything. I imported arcpy and used a SearchCursor to read through the shapefile. I made sure to include the OID, SHAPE, and NAME fields so I could access the geometry and identify each feature by name.Inside the main loop, I set vertex ID to zero and used getPart(0) to go through each individual vertex. For every point, I got the X and Y coordinates and added 1 to the vertex ID. Then I formatted the output string and used write() to save it in the TXT file.


After all the data was written, I closed the file and printed a message to confirm everything ran successfully. I double-checked the file and everything looked good.




For my project structure, I kept things clean by organizing my folders into Data, Scripts, and Results. I also created a Project folder just to keep my .aprx and Notebook separate. It helped keep things from getting cluttered and made it easier to fill out the data sheet.


This was a really helpful lab because it tied together geometry access, looping, and file output all in one place. It also showed how useful it is to use .getPart() when you need to dig deeper into geometry data.

Comments