I've created polygons from a table that has two columns- an OBJECTID and a string of coordinates (Polygon_Coordinates). The resulting polygons (called "testing" in the code below) are in the correct locations, but I can't seem to figure out how to carry over the ID, which I need for a join later in the workflow.
Any idea on how to build geometry, but maintain the attributes?
fields = ['Polygon_Coordinates', 'OBJECTID']
with arcpy.da.SearchCursor(table, fields) as table_cursor:
for row in table_cursor:
#skip null rows
if row[0] != '-9999':
#turn string of coordinates into a list but split them at the commas
coords= list(row[0].split(','))
#break up list into list of pairs
pairs = [coords[i:i + 2] for i in range(0, len(coords), 2)]
coord_ints = [[float(i) for i in p] for p in pairs]
#create insert cursor for geometry creation
geocursor = arcpy.da.InsertCursor(testing, ["SHAPE@"])
array = arcpy.Array()
#grab pairs from list, put into array
for a in pairs:
array.add(arcpy.Point(a[1],a[0], ID=row[1]))
#set crs, build polygon
wgs = arcpy.SpatialReference(4326)
poly = arcpy.Polygon(array, wgs)
geocursor.insertRow([poly])