[GIS] With Python and ArcGIS, how to add features to a featureclass

arcgis-10.0python

In ArcGIS Python code: CopyFeatures_management copies features to the same featureclass – that means overwrite to the feature class. How can I add new features to one featureclass or namely different featureclasses and prevent overwriting in the loop?

Best Answer

You are mistaken. CopyFeatures_Management copies features from the input feature class to a NEW (output) one. See the documentation here

So in your loop, use a variable name for the output feature class that gets changed each iteration to something suitable

[EDIT AS PER SYD'S REQUEST] Here's a very simple example. Suppose you are looping over a list of Feature Classes, just create a new name each loop:

copy_counter = 0
for fc in fcList:
    outFC = os.path.join(outWorkspace, "myCopiedFC_" + str(copy_counter))
    arcpy.CopyFeatures_management(shapefile, outFeatureClass)
    copy_counter += 1

Alternatively, did you mean "how do you do make a loop using model builder?"

  1. Drag and drop the copy_features tool into model builder. enter image description here
  2. Right click on the (single) input FC and select 'a list of inputs' from the properties dialog. It will change the input and output FC icons into little stacks as in the picture above. enter image description here
  3. Now right-click on the tool itself and you will see something like the next image: enter image description here Add more outputs and inputs using the plus sign.

NOTE: I have only roughed this out quickly. In ArcGIS 10 you can also use iterators in Model Builder which can sometimes allow you to have a list or series of inputs. I haven't got space here to describe how to set up all the iterators for every use-case by the ESRI documentation is helpful for this.