Friday, July 17, 2015

GIS Programming – Working with Geometries

This week in Python, we are learning about using Python to manipulate spatial data in ArcMap. In our Exercise for week 8 we worked with geometry objects and multipart features. One of the interesting items I worked with was Tokens. Tokens are shortcuts that provide you a way to access specific geometry properties. Such as:

import arcpy 
from arcpy import env 
env.workspace = "S:/GISProgramming/Module8/Data" fc = "dams.shp" 
cursor = arcpy.da.SearchCursor(fc, ["SHAPE@XY"]) 
for row in cursor:     
    x, y = row[0]     
    print("{0}, {1}".format(x, y))

Where "SHAPE@XY" is a Token that will return a tuple of X, Y coordinates representing the centroid of the feature. There are many other Tokens I had the chance to use in this week's Exercise and Lab. The goal of the Lab was to write a script that creates a .txt file and then write to it the coordinates and Object IDs for vertices in a shapefile. The first two parts of the Lab went very smoothly for me but I ran into some difficulties trying to get the complete data to write to the text file and print out properly.  I think my challenge began with the "for loop" attempting to use the .getPart command to obtain the point data. My loop should have looked something like the example in our Assignment:

for row in cursor:     

    for point in row[1].getPart(0):         
        print point

However, it did not quite work for me. Below is a screen shot of my results. I'll continue to work on this and perhaps by midnight or some day in the not too distant future I can get this to run correctly.



No comments:

Post a Comment