简体   繁体   中英

ArcGIS 10 python - Conditional statement checking to see if a raster value is in a set

I am attempting to create a raster based on input from another raster. If a raster value is equal to a number included in a set() than I want it to be 1, else 0

I've attempted the following:

 ConfusedRaster = arcpy.Con(inraster in repeatSet, 1, 0)

and

 ConfusedRaster = arcpy.Con(inraster, 1, 0, "inraster in repeatSet")

Neither of these work. I believe they don't work because the where clause only accepts Map Algebra expressions: ArcGIS Help

There are two other ways I can think of doing this. One being converting it to a NumPyArray and working with that. The other is looping through the set and creating a raster object for each value in the set. After the loop has finished merge them.

Does anyone have any suggestions or comments on how to go about this?

Thank you

I was searching for an answer to the similar issue and developed a way using the SQL clause in 'ExtractByAttributes'.

repeatList = list(repeatSet)
ras1 = arcpy.sa.ExtractByAttributes(inraster, 'VALUE IN (' + str(repeatList).strip('[]') + ')') 
ConfusedRaster = arcpy.sa.Con(arcpy.sa.IsNull(ras1) == 0, 1, 0)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM