Select to view content in your preferred language

Using Arcpy, how to add selected features to FC AND attributes?

477
2
08-01-2013 04:10 PM
KirstenFrost_Andersen
Regular Contributor
This should be pretty simple, but I'm not finding a good answer in Help or Google.  I have a section of features from a feature class.  I want to essentially create one feature from them and add them to another existing feature class along with one or two attributes.  I'm attempting to create a tool in ArcMap 10.0 that allows my users to select the features, open the tool, add the information about the soon-to-be-created feature into the text boxes in the tool and when they click OK, have it create a new feature out of the selected geometry (polygon) in my other FC with attributes filled out from the user's specifications.  It looks like arcpy.CopyFeatures_management() will create a new feature in a NEW feature class, but how do I tell it what attributes to use and to add to an EXISTING feature class?

Thanks for any direction.
Tags (2)
0 Kudos
2 Replies
ArkadiuszMatoszka
Frequent Contributor
Hi,

You can try delete existing fields (arpcy.DeleteField_management) from copied featureclass, then adding your attributes (arcpy.AddField_management), putting new values with arcpy.CalculateField_management, and at last appending to existing featureclass (arcpy.Append_management). So it will look something like:

arcpy.CopyFeatures_management(lyr, tmp_fc)
f_list = arcpy.ListFields(tmp_fc)
for f in f_list:
  if f.type not in ('OID', 'Geometry'):
    arcpy.DeleteField_management(tmp_fc, f) #delete all fields except of geometry and FID

arcpy.AddField_management(tmp_fc, field1, 'TEXT')
arcpy.AddField_management(tmp_fc, field2, 'LONG') # adding fields you need
...
arcpy.CalculateField_management(tmp_fc, filed1, value1)
arcpy.CalculateField_management(tmp_fc, filed2, value2)
...

arcpy.Append_management(tmp_fc, out_fc, *params)


Hope it helps.
Regards
Arek
0 Kudos
KirstenFrost_Andersen
Regular Contributor
Thanks Arek!  I'm not quite there yet, but still working on it.  I appreciate your assistance!
0 Kudos