AnsweredAssumed Answered

Feature Class to Feature Class

Question asked by hnavarro23 on Oct 29, 2018
Latest reply on Oct 29, 2018 by hnavarro23



I work on a project that is very repetitive and would like to have a python script for it. I am trying to export a feature class from SDE which contains an expression. The geodatabase has been created and I have the following code,


# Import system modules
import arcpy
from arcpy import env


# Set the workspace
arcpy.env.workspace = "Database Connections\ADMIN Edit.sde\GIS.DBO.SewerCollectionNetwork"
ArcSDE = arcpy.env.workspace
env.overwriteOutput = True


# Set local variables
inFeatures = ['sewer']
outputDatabaseLocation = "C:\Users\gis\Desktop\sewer\CCTV.gdb"
outputFeatureClass = "SewerMains"
delimitedField = arcpy.AddFieldDelimiters(arcpy.env.workspace, "OWNER")
expression = delimitedField + " = 'LOCAL'"


# Export feature class
print("Exporting feature class to CCTV geodatabase")
arcpy.FeatureClassToFeatureClass_conversion(inFeatures, outputDatabaseLocation, outputFeatureClass, expression)


I get the following error,


Traceback (most recent call last):
  File "B:\Scripts\Python\ArcSDE Maintenance\CCTV Feature", line 25, in <module>
    arcpy.FeatureClassToFeatureClass_conversion(inFeatures, outputDatabaseLocation, outputFeatureClass)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\", line 1891, in FeatureClassToFeatureClass
    raise e
RuntimeError: Object: Error in executing tool


I have tried using FeatureClassToGeodatabase and FeatureClassToShapefile with success, but I need to be able to add an expression to only export specific values from a field.


Any help will be appreciated.