HOW TO

Add features to a feature class using ArcPy in ArcGIS Pro

Last Published: December 27, 2023

Summary

Adding features to a feature class can be done within an ArcGIS Pro editing session as described in the following documentation, ArcGIS Pro: Get started editing. It is also possible to add features outside of a Pro editing session using the insertCursor() ArcPy function. 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.

Procedure

  1. Open the map with the features in ArcGIS Pro.
  2. Click the Analysis tab.
  3. Click the Python drop-down selection and select Python Window to open the console.
  4. In the Python console, insert the following script:
    1. Import the ArcPy module.
import arcpy
  1. Define a new array parameter to include the desired values in the new row. The values separated by commas corresponds to the field name specified in the next step.
row_values = [('<VALUE1>', (<X1>, <Y1>)), ('<VALUE2>', (<X2>, <Y2))]
  1. Create an object item to utilize the InsertCursor() function. The function requires inputs for the desired feature location and the row field names. Edit the ("NAME", "SHAPE@XY") section according to the values specified in Step 4(b).
cursor = arcpy.da.InsertCursor(r"C:/folder/geodatabase.gdb/feature", ("NAME", "SHAPE@XY"))
  1. Start a loop to create and insert new rows to be filled in the attribute table with the predefined array values specified in Step 4(b).
for row in row_values:
    cursor.insertRow(row)
  1. Delete the cursor object to end the function.
del cursor
  1. Place the cursor at the end of the script and press Enter twice to run the script.

The following script 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(r"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 script demonstrates the use of the SearchCursor() and the InsertCursor() functions. More fields can be added into the "<Field_Name>" section of the script.

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

for row in sourceCursor:
    inputCursor.insertRow(row)

del inputCursor
del sourceCursor

Article ID: 000031657

Software:
  • ArcGIS Pro 3 1
  • ArcGIS Pro 3 0
  • ArcGIS Pro 3 2
  • ArcGIS Pro 2 9x

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options