AnsweredAssumed Answered

Use SearchCursor to generate a text string of x,y values from Shape@; then update text filed with string?

Question asked by roberteg7108 on May 2, 2018

Hi there


I have a shapefile  that has polygon geometry and also a text attribute field that contains approximate UTM coordinates. I would like to utilise the Shape@ x,y values and repopulate this Coord_String field with a string of comma delimited x,y values.


I have been able to export the string x,y values into a text file, so I can see that I can probably create another feature class that would contain and empty Coord_String field - then perhaps populate that empty field with the string contents.


I would like to do it all in python (perhaps using UpdateCursor) - but since my programming is entry level - looking for some pointers on where to go next. My current text file generation looks like this:


import arcpy, os, sys

infc = "H:\GIST_8125\Oil_Gas\Gail_test\clip_project.shp"
cursor = arcpy.da.SearchCursor(infc, ["OID@","SHAPE@","GRID","SECTION","UNIT"])
with open('H:\GIST_8125\Oil_Gas\Gail_test\Results.txt', 'w') as output:
for row in cursor:
print ("id:{0}".format(row[0]))
print ("grid:{0}".format(row[2]))
print ("section:{0}".format(row[3]))
output.write("Section "+str(row[3])+"\n")
print ("unit:{0}".format(row[4]))
output.write("Unit "+str(row[4])+"\n")
for point in row[1].getPart(0):
#add the geometry as x,y in string format with commas
print ("{0}, {1},".format(point.X, point.Y))


Anyone help? Thanks in advance