2

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?

Chad Cooper
12.8k4 gold badges48 silver badges87 bronze badges
asked Feb 24, 2012 at 13:16

2 Answers 2

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.

answered Feb 24, 2012 at 13:32
3
  • 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. Commented Feb 24, 2012 at 13:43
  • Ok ! Append tool solves when env.overwriteOutput = 1 in the loop. Commented Feb 24, 2012 at 14:49
  • Ah! I thought you wanted new feature classes each time - perhaps a slight misunderstanding! Commented Feb 24, 2012 at 15:01
2

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

answered Feb 24, 2012 at 15:01

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.