HOW TO
Adding features to a feature class can be automated using a Python script. The ArcPy function, InsertCursor() is used to insert a new row in an attribute table. The function can be used as an object to insert the values for the newly created rows.
Note: The InsertCursor() function can also be used in conjunction with the SearchCursor() function to replicate certain fields.
The following procedure demonstrates how to add a feature to a feature class using Python:
import arcpy
row_values = [('Anderson', (1409934.4442000017, 1076766.8192000017)), ('Andrews', (752000.2489000037, 1128929.8114))]
cursor = arcpy.da.InsertCursor("C://sample.gdb/test",("[row 1]", "[row 2]"))
for row in row_values: cursor.insertRow(row)
del cursor
The following codeblock demonstrates the full working code.
import arcpy # A list of values that will be used to construct new rows row_values = [('Atascosa', (1409934.4442000017, 1076766.8192000017)), ('Bosque', (752000.2489000037, 1128929.8114))] # Open an InsertCursor. # Specify the location for the desired feature. The sample inserts the values into the field, NAME and SHAPE. cursor = arcpy.da.InsertCursor("C:/data/texas.gdb/counties", ("NAME", "SHAPE@XY")) # Insert new rows that include the county name and the x and y coordinate # pair that represents the county center for row in row_values: cursor.insertRow(row) # Delete cursor object del cursor
To add data from another feature class, the SearchCursor() function must be used with the InsertCursor() function. The following codeblock demonstrates the use of the SearchCursor() and the InsertCursor() functions.
import arcpy sourceCursor = arcpy.da.SearchCursor(r"<feature_path>", ("<Field_Name>", "SHAPE@XYZ")) inputCursor = arcpy.da.InsertCursor(r"<new_feature_path>", ("<Field_Name>", "SHAPE@XYZ")) #example #sourceCursor = arcpy.da.SearchCursor(r"C:\Users\User\Documents\ArcGIS\Projects\test\test.gdb\Point", ("URL", "SHAPE@XYZ")) #inputCursor = arcpy.da.InsertCursor(r"C:\Users\User\Documents\ArcGIS\Projects\test\test.gdb\NewPoint", ("URL", "SHAPE@XYZ")) for row in sourceCursor: inputCursor.insertRow(row) del inputCursor del sourceCursor
Get help from ArcGIS experts
Download the Esri Support App