Friday, July 17, 2015

GISProgramming: Module 8 - Working with Geometries

     This module focuses on working with geometry objects. All features are comprised of a set of points. These points are the vertices of a feature and they are accessed through geometry objects. Whether reading or writing geometries, geometry tokens (SHAPE@XY, SHAPE@, etc) act as shortcuts for accessing specific properties of a feature. Cursors are integral in accessing geometries or creating new geometries. The previous module introduced cursors which helped writing this week's script as I needed to use them again. The program this week practiced reading geometries and writing point data to a text file. 
     The program accesses the Object IDs, point data for all vertices, and attribute data (such as the name of the feature) for features in a polyline shapefile (by way of the Search Cursor). Using a series of nested for loops, the point data for the vertices is gathered and written to a text file (.getPart(), .write, and string module). Below is a screenshot that prints the data (that was simultaneously written to a text file). The program also contains print statements to keep track of what steps of the program have been accomplished.
A screenshot showing the results of a program that
writes geometric and attribute information to a text file. 

     While I found this module conceptually straight forward, I had some issues writing the script for this program. Specifically, I had issues writing information to a text file. This was mostly due to improper syntax and an incorrectly tabulated iterative line of code. Once I let it sink in that the Search Cursor returns tuples, I found the syntax much easier (like properly referencing and printing the data within the tuples). The solutions to my issues were so simple but I got really hung up on them. I hope my DUH moments are easier to catch in the future. 

No comments:

Post a Comment