Copy a field from one feature class to another without creating a new feature class?

3458
1
Jump to solution
10-10-2013 05:52 AM
ionarawilson1
Occasional Contributor III
Is there a way to copy a field from one feature class to another without creating a new feature class? Is it possible to do that, perhaps using the Search and Update Cursor? Thanks
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
ionarawilson1
Occasional Contributor III
This worked for me:

# Create new field mappings and addd both feature classes  fieldmappings = arcpy.FieldMappings() fieldmappings.addTable(Input_Polygons) fieldmappings.addTable(Counties)  # create output feature for spatial join outstewardshipcounties = os.path.join(arcpy.env.scratchGDB, "StewardshipCounties")  #run spatial joint tool  arcpy.SpatialJoin_analysis(Input_Polygons, Counties, outstewardshipcounties , "#", "#", fieldmappings, "HAVE_THEIR_CENTER_IN")  #create dictionary  path_dict = { } rows = arcpy.SearchCursor(outstewardshipcounties) for row in rows:     keyrow = row.getValue("ObjectID")     valrow = row.getValue("FIPS_TXT")     path_dict[keyrow] = valrow  urows = arcpy.UpdateCursor(Input_Polygons) for urow in urows:     upkey = urow.getValue("ObjectID")     if upkey in path_dict:         urow.setValue("County", path_dict[upkey])         urows.updateRow(urow) del row, rows, urow, urows

View solution in original post

0 Kudos
1 Reply
ionarawilson1
Occasional Contributor III
This worked for me:

# Create new field mappings and addd both feature classes  fieldmappings = arcpy.FieldMappings() fieldmappings.addTable(Input_Polygons) fieldmappings.addTable(Counties)  # create output feature for spatial join outstewardshipcounties = os.path.join(arcpy.env.scratchGDB, "StewardshipCounties")  #run spatial joint tool  arcpy.SpatialJoin_analysis(Input_Polygons, Counties, outstewardshipcounties , "#", "#", fieldmappings, "HAVE_THEIR_CENTER_IN")  #create dictionary  path_dict = { } rows = arcpy.SearchCursor(outstewardshipcounties) for row in rows:     keyrow = row.getValue("ObjectID")     valrow = row.getValue("FIPS_TXT")     path_dict[keyrow] = valrow  urows = arcpy.UpdateCursor(Input_Polygons) for urow in urows:     upkey = urow.getValue("ObjectID")     if upkey in path_dict:         urow.setValue("County", path_dict[upkey])         urows.updateRow(urow) del row, rows, urow, urows
0 Kudos