Copy FeatureClass

754
6
04-30-2014 04:49 AM
MickeyO_Neil
New Contributor III
Hello,

i want to copy a FeatureClass which is in a Feature-Dataset into an other Feature-Class (which is also in a Feature-Dataset).Both Feature-Classes are on different SDEs.

arcpy.Copy_management(fromgdbpath + "\\" + fd + "\\" + fc,  togdbpath + "\\" + toschema + "." + outfd+ "\\" + toschema + "." + outfc, "FeatureClass")


I always get the following error:
('ERROR 000258: Output C:\\...<Path>... already exists\nFailed to execute (Copy).\n',)

Of course the Output-FC already exists, but why is this a Problem? If I use the Copy-Geoprocessintool in ArcCatalog with the same Parameters everything works fine!
And if i copy Feature-Classes into other Feature-Classes which are not in a Feature-Dataset, it works, too.

Thanks for your help!

Cheers Mickey
Tags (2)
0 Kudos
6 Replies
Zeke
by
Regular Contributor III
You don't want Copy, you want Append or Merge. Copy makes a new feature class, and you already have the destination feature class. If you want to replace the destination, delete the destination first and use copy, or delete features and append.
0 Kudos
MickeyO_Neil
New Contributor III
But the Copy-Tool also copys the Indexes and my target FC is empty, so copy would be just fine.
0 Kudos
Zeke
by
Regular Contributor III
Do the feature classes have the same name? Do they have different spatial references? Either will cause the tool to fail.
0 Kudos
MickeyO_Neil
New Contributor III
It works on ArcGIS 10.1 when I use this Line of Code:

arcpy.env.overwriteOutput = True


But when I want to run the same Script on an ArcGIS 10.2.1, the same ERROR shows up!
How is that possible? It's the same code?
Even the Place where I copy to, is the same ArcSDE in my local Network!
0 Kudos
MichaelVolz
Esteemed Contributor
Is this an error that just appeared when you upgraded from v10.1 to v10.2?
0 Kudos
MickeyO_Neil
New Contributor III
No, these are two different machines. No upgrad was made.

My final solution:
I split my script in two parts:
If I'm allowed to delete a FeatureClass I use:
if arcpy.Exists(__toFCpath):
   arcpy.Delete_management(__toFCpath)
arcpy.Copy_management(__fromFCpath, __toFCpath)

And if i'm not allowed to delete a FeatureClass I use:
arcpy.DeleteRows_management(...)
arcpy.Append_management(...)
and
arcpy.AddIndex_management(...)
to copy the Indexes.

But be aware of Bug NIM084818 if you are using ArcGIS 10.2.0 or lower:
The Append geoprocessing tool fails to append field values for fields with field names that have 29 or more characters.

Cheers.
Mickey
0 Kudos