AnsweredAssumed Answered

How do you duplicate a point within a shapefile using Python?

Question asked by dselik on Jul 28, 2014
Latest reply on Jul 30, 2014 by jcscott

How do you duplicate a point within a single feature class using Python? I have a partial sample script below, but in a nutshell, I want to duplicate a point, copy it into the same shapefile, and pupulate the fields with user-provided strings. I suspect this is elementary, but I'm new at this and am frustrated with loops and cursors.


# Script tool will take a point file and allow the user to duplicate a single point while updateing necessary field information.

# The purpose is not to delete or overwrite the orginal point object, but rather to ad a duplicate point with the new information.

# This allows historical context for apoint that spatially never changes, but who's fields are dynamic.

# No information is hard-coded.


import arcpy

# set up input variables for target folder and target dataset.

targetFC=arcpy.GetParameterAsText(0)  # this is the point file

targetKeyField=arcpyGetparameterAsText(1)  # this is the key field in the point file

newKeyID=arcpy.GetParameterAsText(2)  # must be duplicate of a string in targetKeyField

newField2 = arcpy.GetParameterAsText(3)

newField3 = arcpy.GetParamaterAsText(4)


# Add new fields to table

in_table = targetFC

field_name2 = "Field_2"

field_name3 = "Field_3"

field_type = "TEXT"

arcpy.AddField_management(in_table, field_name2, field_type)

arcpy.AddField_management(in_table, field_name3, field_type)


# Loop through targetFC to find a match between newKeyID and a string in targetKeyField

with arcpy.da.SearchCursor(targetFC, [targetKeyField, "SHAPE@"]) as cursor:


     # insertCursor based on the match; duplicate the point in the table

          # Populate the new cursor with the new parameters (newField2, newField3, etc)


     # Error if the newParcelID does not match a string in the targetKeyField

     # User is brought back to enter a new newKeyID string.