Select to view content in your preferred language

FeatureClass to FeatureClass error

1417
1
Jump to solution
01-05-2021 05:06 AM
CliveSwan
Frequent Contributor

Greetings,

I can return and loop through a list of Features that I want to export to a file gdb.

I can't add the  gdb + Feature as a variable to export.

It fails in the arcpy.FeatureClassToFeatureClass_conversion(Features, outLocation, outFeatures) section.

 

I would appreciate any pointers, and/or links to help resolve this.

 

import arcpy
import arcgis
from arcgis.gis import *
from arcgis.gis import GIS
from arcgis.features import FeatureLayer
from arcgis.features import FeatureLayerCollection
import pandas as pd

## SET Parameters
arcpy.env.orverwriteOutput = True
arcpy.env.workspace = r"D:\Users\user\Documents\ArcGIS\Projects\Databases\SDE.sde"

datasets = arcpy.ListDatasets(feature_type='feature')
datasets = [''] + datasets if datasets is not None else []

print("START")
## output file
outLocation = (r"W:\My Documents\user\ENV.gdb\ENV") 
inFeatures = ""
outFeatures = inFeatures

#### EXPORT DATA

for ds in datasets:
    for fc in arcpy.ListFeatureClasses(feature_dataset=ds):
        new_name = fc.split('.')[-1]
        #print(new_name)
        Features = ([new_name])
        print(inFeatures)
        arcpy.FeatureClassToFeatureClass_conversion(Features, outLocation, outFeatures)

 

 

 

 

 

The arcpy error message

RuntimeError                              Traceback (most recent call last)
<ipython-input-13-f520ea9e3f4b> in <module>
     38         Features = ([new_name])
     39         print(inFeatures)
---> 40         arcpy.FeatureClassToFeatureClass_conversion(Features, outLocation, outFeatures)
     41 
     42             # outFile.close

C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\conversion.py in FeatureClassToFeatureClass(in_features, out_path, out_name, where_clause, field_mapping, config_keyword)
   2098         return retval
   2099     except Exception as e:
-> 2100         raise e
   2101 
   2102 @gptooldoc('FeatureClassToGeodatabase_conversion', None)

C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\conversion.py in FeatureClassToFeatureClass(in_features, out_path, out_name, where_clause, field_mapping, config_keyword)
   2095     from arcpy.arcobjects.arcobjectconversion import convertArcObjectToPythonObject
   2096     try:
-> 2097         retval = convertArcObjectToPythonObject(gp.FeatureClassToFeatureClass_conversion(*gp_fixargs((in_features, out_path, out_name, where_clause, field_mapping, config_keyword), True)))
   2098         return retval
   2099     except Exception as e:

C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py in <lambda>(*args)
    509         val = getattr(self._gp, attr)
    510         if callable(val):
--> 511             return lambda *args: val(*gp_fixargs(args, True))
    512         else:
    513             return convertArcObjectToPythonObject(val)

RuntimeError: Object: Error in executing tool

 

 

Regards,

Clive

0 Kudos
1 Solution

Accepted Solutions
BlakeTerhune
MVP Regular Contributor

There's a lot going on in your code that is either redundant or slightly off. I recommend familiarizing yourself with the syntax of FeatureClassToFeatureClass_conversion()

Here's a simplified version. See if this runs and does what you want.

 

import arcpy

sde_workspace = r"D:\Users\user\Documents\ArcGIS\Projects\Databases\SDE.sde"
env_gdb = r"W:\My Documents\user\ENV.gdb\ENV"
print("START")
for ds in arcpy.ListDatasets(feature_type="Feature"):
    new_name = ds.split(".")[-1]
    print("Copying {}".format(new_name))
    arcpy.FeatureClassToFeatureClass_conversion(ds, outLocation, new_name)

 

View solution in original post

1 Reply
BlakeTerhune
MVP Regular Contributor

There's a lot going on in your code that is either redundant or slightly off. I recommend familiarizing yourself with the syntax of FeatureClassToFeatureClass_conversion()

Here's a simplified version. See if this runs and does what you want.

 

import arcpy

sde_workspace = r"D:\Users\user\Documents\ArcGIS\Projects\Databases\SDE.sde"
env_gdb = r"W:\My Documents\user\ENV.gdb\ENV"
print("START")
for ds in arcpy.ListDatasets(feature_type="Feature"):
    new_name = ds.split(".")[-1]
    print("Copying {}".format(new_name))
    arcpy.FeatureClassToFeatureClass_conversion(ds, outLocation, new_name)