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)
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Aug 14, 2018 at 21:04

1 Answer 1

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'
answered Aug 14, 2018 at 21:19
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.