4

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?

asked Sep 13, 2013 at 13:02

2 Answers 2

9

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.)

answered Sep 13, 2013 at 13:16
1

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)
Vince
20.5k16 gold badges49 silver badges65 bronze badges
answered May 4, 2023 at 11:59

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.