Select to view content in your preferred language

Feature Class to Feature Class

6875
10
Jump to solution
10-29-2018 03:00 PM
GIS_geek
Regular Contributor

Hello,

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 Class.py", line 25, in <module>
    arcpy.FeatureClassToFeatureClass_conversion(inFeatures, outputDatabaseLocation, outputFeatureClass)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\conversion.py", 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.

0 Kudos
10 Replies
GIS_geek
Regular Contributor

Darren, you are a genius! Removing the brackets worked.  Thanks.

0 Kudos