Select to view content in your preferred language

Export feature class based on values from two fields

872
3
Jump to solution
10-30-2018 11:16 AM
GIS_geek
Regular Contributor

Good day,

I want to export a feature class to a feature class but only the ones that meet a certain criteria.  I need values from field OWNER that are equal to LB and values from STATUS that are equal to ABN.  I was able to export just one of the fields expression (OWNER) using AddFieldDelimiters, but I am not sure if this allows for an expression pointing to two fields. I tried adding a second field but only OWNER was successful and all values from STATUS were exported.  Here is my script,

# Import system modules
import arcpy
from arcpy import env

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

# Set local variables
inFeatures = "ssGravityMain"
outputLocation = "C:/Users/Navarro/Desktop/CAD"
outputDatabase = "CCTV.gdb"
outputDatabaseLocation = "C:/Users/Navarro/Desktop/CAD/CCTV.gdb"
outputFeatureClass = "GravityMain"
delimitedOwner = arcpy.AddFieldDelimiters(ArcSDE, "OWNER")
delimitedStatus = arcpy.AddFieldDelimiters(ArcSDE, "STATUS")
expressionOwner = delimitedOwner + " = 'LB'"
expressionStatus = delimitedStatus + " = 'ABN'"

# Creating new .gdb
print("Creating geodatabase")
arcpy.CreateFileGDB_management(outputLocation, outputDatabase)

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

Thank you in advance.

0 Kudos
1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor

Hi Hector,

You could do the following:

expression = "OWNER = 'LB' AND STATUS = 'ABN'"

arcpy.FeatureClassToFeatureClass_conversion(inFeatures, outputDatabaseLocation,
outputFeatureClass, expression)

View solution in original post

0 Kudos
3 Replies
DanPatterson_Retired
MVP Emeritus

You didn't try field mapping?

FieldMappings—ArcPy classes | ArcGIS Desktop 

0 Kudos
JakeSkinner
Esri Esteemed Contributor

Hi Hector,

You could do the following:

expression = "OWNER = 'LB' AND STATUS = 'ABN'"

arcpy.FeatureClassToFeatureClass_conversion(inFeatures, outputDatabaseLocation,
outputFeatureClass, expression)
0 Kudos
GIS_geek
Regular Contributor

Jake,

Thanks for the assistance.

0 Kudos