I am trying to set all values in my raster that are not equal to -9999 to Null using Arcpy. The problem is that using != operator gets me an arcgisscripting.ExecuteError: ERROR 010416: Error in setting raster table filter for F:\Data\test.tif. However, other operators like = or < works okay. Any ideas?


I solved the problem using <> instead of !=, but I still do not understand why ArcGIS and Arcpy use different operators for the same functions.

# Import arcpy module
import arcpy

# Set the current workspace
arcpy.env.workspace = "F:/Data"

# check out any necessary licenses

inRaster = arcpy.Raster('test.tif')
outSetNull = arcpy.sa.SetNull(inRaster, in_false_raster_or_constant=1, where_clause='Value != -9999')
  • 1
    Have you tried to use not equal <>? – ahmadhanb Dec 8 '17 at 16:52

!= is Python syntax for does not equal. <> is sql syntax for the same. Since the expression in question is an sql where clause, you must use the sql syntax, even though it’s within a python script.

< and = perform the same function in sql and python (edit: python uses == for equals), which is why python syntax seems to ‘work’ in your sql where clause.

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.