I am trying to read a FC geometry which has one record in it
Grab this geometry and use it in an INSERT cursor with specific attributes
Think I am close but cant get the geometry of the FCs feature...the FC has only one....
geometries = arcpy.CopyFeatures_management('Counties_3_dissolved', arcpy.Geometry())
length = sum([g.length for g in geometries])
print('Total length: {}'.format(length))
arcpy.env.overwriteOutput = True
# Create a feature class
result1 = arcpy.management.CreateFeatureclass(
arcpy.env.scratchGDB,
"esri_square", "POLYGON", spatial_reference=26917)
feature_class = result1[0]
inputFeatureclass = "C:\Data\SelectCounties.gdb\Counties_4_final_append"
# Write feature to new feature class
with arcpy.da.InsertCursor(inputFeatureclass, ['SHAPE@', 'ADDRESS', 'DISTANCE', 'UNIQUEID', 'COUNTYLIST']) as cursor:
cursor.insertRow([geometries, searchAddress, searchDistance, searchid, txt_list])
# Delete cursor object
del cursor
Solved! Go to Solution.
Taking what Dan said about a list being returned, what about changing the update line:
cursor.insertRow([geometries[0], searchAddress, searchDistance, searchid, txt_list])
which help topic did you get this line from?
geometries = arcpy.CopyFeatures_management('Counties_3_dissolved', arcpy.Geometry())
is it specific to the arcgis api for python?
it returns a list even if there is one. Did you try adding them in the insertRow one at a time?
Taking what Dan said about a list being returned, what about changing the update line:
cursor.insertRow([geometries[0], searchAddress, searchDistance, searchid, txt_list])
Not sure if you're getting all the variables you're trying to insert to the new feature class from the Counties_3_dissolved feature class, but if you are you could use something like below:
with arcpy.da.SearchCursor('Counties_3_dissolved', ["SHAPE@", "address", "distance", "id", "txt_list"]) as cursor:
for row in cursor:
geom = row[0]
searchAddress = row[1]
searchDistance = row[2]
searchid = row[3]
txt_list = row[4]
del cursor
# Write feature to new feature class
inputFeatureclass = r"C:\Data\SelectCounties.gdb\Counties_4_final_append"
with arcpy.da.InsertCursor(inputFeatureclass, ['SHAPE@', 'ADDRESS', 'DISTANCE', 'UNIQUEID', 'COUNTYLIST']) as cursor:
cursor.insertRow((geom, searchAddress, searchDistance, searchid, txt_list))
del cursor
I get this to work BUT i have a GlobalID in my feature class that does not get written too....how do I create the globalID
# GET THE GEOMETRY FROM THE DISSOLVED FC and PASS THAT TO THE INSERT CURSOR BELOW ALONG WITH THE ATTRIBUTE VALUES
geometries = arcpy.CopyFeatures_management('Counties_3_dissolved', arcpy.Geometry())
arcpy.env.overwriteOutput = True
inputFeatureclass = "C:\Work\CountySelection\Data\SelectCounties.gdb\Counties_4_final_append"
## Write feature to new feature class
with arcpy.da.InsertCursor(inputFeatureclass, ['SHAPE@', 'ADDRESS', 'DISTANCE', 'UNIQUEID', 'COUNTYLIST']) as cursor:
cursor.insertRow([geometries[0], searchAddress, searchDistance, searchid, txt_list])
# Delete cursor object
del cursor
So you have a field of GlobalID type in inputFeatureclass
and nothing is getting populated when you insert a record using the cursor?
Yea I figured when I add a new row the GlobalID would be populated automatically
think I fixed it....delete the old one and created globalIDs again and it seems to be working....weird