Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

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.

share|improve this answer
    
If you use a variable name in the loop for the output feature class that certainly gets changed each iteration to something suitable. But how can we do in the CopyFeatures_Management statement. Can you give an example. –  syd Feb 24 '12 at 13:43
    
Ok ! Append tool solves when env.overwriteOutput = 1 in the loop. –  syd Feb 24 '12 at 14:49
    
Ah! I thought you wanted new feature classes each time - perhaps a slight misunderstanding! –  MappaGnosis Feb 24 '12 at 15:01

Are you looking to add the features from one feature class to an Existing feature class? If So, you need the Append Tool.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.