I see CopyFeatures_management, but this creates a new feature class.
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001700000035000000
Is there a way to copy features from a feature class into an existing feature class?
2 Answers 2
You want to use the Append_Management tool.
If you know the attribute tables will match up (including data type), use schema_type
NO_TEST
anyway (even though the documentation would suggest TEST
).
If the attribute tables do not match up you will have to deal with field mappings, which can be a huge pain in arcpy.
(If you are using NO_TEST
and a subtype, make sure that you pass in None
for the field_mapping
argument.)
You can combine search cursor and insert cursor. It can be used to avoid field_mappings.
https://pro.arcgis.com/en/pro-app/latest/arcpy/data-access/searchcursor-class.htm https://pro.arcgis.com/en/pro-app/latest/arcpy/data-access/insertcursor-class.htm
# check if pasted feature have common fields
to_paste_fields_names = [field.name for field in arcpy.ListFields(shape_to_paste)]
base_shape_fields_names = [field.name for field in arcpy.ListFields(base_shape)]
fields_names = sorted(set(base_shape_fields_names) & set(to_paste_fields_names))
if len(fields_names) > 0:
# start search cursor on shape to paste
with arcpy.da.SearchCursor(shape_to_paste, fields_names) as cursor:
# start insert cursor on base shape
with arcpy.da.InsertCursor(base_shape, fields_names) as insert_cursor:
# iterate through search cursor
for row in cursor:
insert_cursor.insertRow(row)