Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a raster file containing some integer values.

I need to find all pixels whose values are not defined in list like this one:

l = [1,2,4,8,16,32,64,128].

Is there any easy way to solve that problem without converting raster to points and editing attribute table?

share|improve this question

2 Answers 2

up vote 7 down vote accepted

Extract by attributes using "VALUE NOT IN (1,2,4,8,16,32,64,128)" (Thanks to @afalciano) will give you a new raster with only the cells where the value is different from your list.

share|improve this answer
    
...or using "VALUE NOT IN (1,2,4,8,16,32,64,128)" –  afalciano Jan 20 at 14:28
    
That would be more convenient of course.. Thanks, I'll update the answer –  Martin Jan 20 at 14:32

One option would be to use a SQL statement within a Con function. The following example performs the following actions:

  1. Generate a SQL expression from a list of values. Doing this in an automated fashion is important for long lists of values.
  2. Use Con to perform an if/else evaluation on a raster. In this case, all values in the list will be assigned "1" and all others "0".

import arcpy
from arcpy import env
from arcpy.sa import *
arcpy.CheckOutExtension = "Spatial"

vals = [1,2,4,8,16,32,64,128]
inRaster = r'C:\temp\example.tif'
new = []

# Generate a SQL expression from the "vals" list
for i in vals:
    new.append("value " + "= " + str(i) + " OR ")
    expression = ''.join(new)[:-4]

# Use Con to convert all raster values from the "vals" list to 1 and all others to 0
outCon = Con(inRaster, 1, 0, expression)
outCon.save("C:/temp/revisedRaster.tif")
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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