Hi Community,
I am attempting to use the arcpy.Geometry() objects .union() method to update records in a feature class that were appended but now need to be merged with an existing feature where appropriate (governed by a SQL expression). I am using the arcpy.da.UpdateCursor() to perform the updates. I am attempting to do something like the following, but I am getting an "AttributeError: 'Array' object has no attribute 'union'" error.
arcpy.MakeFeatureLayer_management(zoning, 'zoning_lyr')
arcpy.management.SelectLayerByAttribute('zoning_lyr', "NEW_SELECTION", "Zoning = 'A'")
selectCount = int(arcpy.GetCount_management('zoning_lyr')[0])
if selectCount >= 2:
zoningGeom = arcpy.CopyFeatures_management('zoning_lyr',arcpy.Geometry())
edit.startEditing(False, False)
edit.startOperation()
N = 1
with arcpy.da.UpdateCursor(zoning, "Shape@", "Zoning = 'A'") as cursor:
for row in cursor:
if N == selectCount:break
while N < selectCount:
row = row[0].union(zoningGeom[N]) # Fails here
cursor.updateRow([row])
N += 1
del row, cursor
edit.stopOperation()
edit.stopEditing(True)
arcpy.Delete_management('zoning_lyr')
The code below works without error, except it doesn't run through the whole list of zoningGeom features before moving to the next zoning record in the for loop. Ideally I would have it run through the records in the zoningGeom geometry object, unioning each one to the zoning layer before running out of features to union and exiting both loops.
N = 1
with arcpy.da.UpdateCursor(zoning, "Shape@", "Zoning = 'A'") as cursor:
for row in cursor:
if N == selectCount:break
row = row[0].union(zoningGeom[N])
cursor.updateRow([row])
N += 1
I think I am just missing something fundamental here. Hopefully, someone can swoop in and point me in the right direction or, better yet, offer a solution.
Thank you in advance,