0

Have many feature classes in geodatabases and eventually want to run more complex processes on them. Having trouble with the basics - can anyone tell me what I am doing wrong with the following? If I use "print fcscopy" I get the list of output file names I want.. but the featureclass to featureclass gives following error.

#Code
import arcpy

arcpy.env.workspace = r"D:\_StuData\GIS\Projects\PersonalProjects\Product\test.gdb"
fcs = arcpy.ListFeatureClasses() 
copy = 'copy'
fcscopy = [x + copy for x in fcs]
outpath = "D:\\_StuData\\GIS\\Projects\\PersonalProjects\\Product\\test.gdb"

arcpy.FeatureClassToFeatureClass_conversion(fcs, outpath, fcscopy)

Error

Runtime error Traceback (most recent call last): File "", line 12, in File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\conversion.py", line 1789, in FeatureClassToFeatureClass raise e RuntimeError: Object: Error in executing tool

Testing

>>> print fcs

[u'Border', u'Building', u'Concrete', u'Grass', u'Gravel', u'Rocks', u'Roof']

>>> print fcscopy

[u'Bordercopy', u'Buildingcopy', u'Concretecopy', u'Grasscopy', u'Gravelcopy', u'Rockscopy', u'Roofcopy']

0

2 Answers 2

2

arcpy.ListFeatureClasses() returns a list of the names of the feature classes. However, arcpy.FeatureClassToFeatureClass_conversion requires the path to the feature class. You could incorporate something like this:

import os, arcpy

arcpy.env.workspace = r"D:\_StuData\GIS\Projects\PersonalProjects\Product\test.gdb"

outpath = r"D:\_StuData\GIS\Projects\PersonalProjects\Product\test.gdb"

fcs = arcpy.ListFeatureClasses()

copy = '_copy'

for fc in fcs:
    arcpy.FeatureClassToFeatureClass_conversion(os.path.join(arcpy.env.workspace, fc),outpath, fc+copy)

os.path.join will "join one or more path components intelligently."

3
  • 1
    I think because the arcpy.env.workspace has been set the path to the fc isn't required (please correct me if I'm wrong)
    – Midavalo
    Commented Jan 19, 2016 at 3:38
  • 1
    I haven't tested it. But that's what I always use. I've had issues in the past with this. Just looked at the documentation, however, and it appears you're right.
    – Fezter
    Commented Jan 19, 2016 at 3:40
  • 1
    it won't hurt having the path there I'm sure
    – Midavalo
    Commented Jan 19, 2016 at 3:41
2

FeatureClassToFeatureClass requires a single input/output, so you'll need to include within the for loop:

import arcpy
arcpy.env.workspace = r"D:\_StuData\GIS\Projects\PersonalProjects\Product\test.gdb"

fcs = arcpy.ListFeatureClasses()

copy = 'copy'
outpath = r"D:\_StuData\GIS\Projects\PersonalProjects\Product\test.gdb"

for x in fcs:
    arcpy.FeatureClassToFeatureClass_conversion(x, outpath, x + copy)
0

Your Answer

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

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