0

I am using ArcPy 2.7 to subset a shapefile. I am trying to use arcpy.Select_analysis to exclude certain features from a shapefile (idle fields denoted as 1401 in the field 'Crop_Type'. my 'Crop_Type' field is of type long.

I'm receiving the following error: ExecuteError: ERROR 000358: Invalid expression NOT "Crop_Type" = '1401'

Looking at ESRI's Building a SQL Expression, my code is:

import arcpy
from arcpy.sa import *

arcpy.env.overwriteOutput =  True

in_features = 'Copy_SaltonT4_2017.shp'
out_feature_class = 'CroppedFields.shp'
where_clause = 'NOT "Crop_Type" = \'1401\''

arcpy.Select_analysis(in_features, out_feature_class, where_clause)

arcpy.CopyFeatures_management(in_features, out_feature_class)
2

Single quotes should only be used with string literal values. Do not put single quotes around a long value. Change the where_clause to the following:

where_clause = 'NOT "Crop_Type" = 1401' 

Also this should work:

where_clause = '"Crop_Type" <> 1401'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.