I need to buffer a subset of features in a particular feature class. To do this, I am first creating a feature layer (using a SQL query to select only what I want), and then running Buffer. So my ArcPy script includes this little function to buffer my handful of feature classes:
def funcBuffer(inFeature, outFeature, bufDist, querySQL): arcpy.MakeFeatureLayer_management(inFeature, "tempLayer", querySQL) arcpy.Buffer_analysis("tempLayer", outFeature, bufDist, "FULL", "ROUND", "ALL", "")
This works perfectly on most of my feature classes. However, there is one that fails. The Python error is:
ERROR 000230: Failed selecting with "OH_UG" = 'UG'
The help page for that error suggests that the SQL query is invalid. However,
- the field
OH_UGexists, and there are some features with the value "UG"
- it successfully validates in Query Builder
- I can use it to Select by Attribute with no problem (python snippet from within ArcMap:
arcpy.SelectLayerByAttribute_management("TransmissionLines","NEW_SELECTION","OH_UG = 'UG'"))
- similarly structured queries work on other feature classes
I've tried different ways of passing the SQL query and all fail:
'"OH_UH" = \'UG\'',
'OH_UH = \'UG\'',
""" "OH_UG" = 'UG' """
I revised the script to do the selection after making the feature layer:
def funcBuffer(inFeature, outFeature, bufDist, querySQL): arcpy.MakeFeatureLayer_management(inFeature, "tempLayer") arcpy.SelectLayerByAttribute_management("tempLayer", "NEW_SELECTION", querySQL) arcpy.Buffer_analysis("tempLayer", outFeature, bufDist, "FULL", "ROUND", "ALL", "")
MakeFeatureLayer works, but
ERROR 000358: Invalid expression -- still a complaint regarding invalid SQL.
I attempted to select using a different (numeric) field in the table, and am still getting the same
So I am not sure what's going wrong -- is it the SQL, is it the particular feature class, is it gremlins? How can I work around the problem in ArcPy?