I am trying to establish a threshold (2 values) on a raster image. Values are between 1000 and 4000. How can I write python syntax to do that. Here is an example of what I tried...
inraster_threshold = inraster >=1000 and <=4000
inraster_threshold = inraster >=1000<=4000
both did come out with syntax errors and I can't find the "and" way of including the second value for my threshold
Solved! Go to Solution.
I'm a bit confused... you want to create a raster by only maintaining the values in a range and you want to do this in Python. This question is also located in the Big Data space. What software (parts of the platform) do you have at your disposal?
Normally this is easily done manually using the Raster Calculator:
Raster Calculator—Help | ArcGIS Desktop (ArcMap) or
Raster Calculator—Help | ArcGIS Desktop (ArcGIS Pro)
You could simply specify a formula like:
Con(myRaster >= 1000, Con(myRaster <= 4000, myRaster))
In Python you can do something similar:
import arcpy
from arcpy.sa import *
arcpy.CheckOutExtension("Spatial")
dem = arcpy.Raster(r'C:\GeoNet\DEMrange\data.gdb\dem')
result = Con(dem >= 1000, Con(dem <= 4000, dem))
result.save(r'C:\GeoNet\DEMrange\data.gdb\result')
... but is it really necessary to do this in Python?
I'm a bit confused... you want to create a raster by only maintaining the values in a range and you want to do this in Python. This question is also located in the Big Data space. What software (parts of the platform) do you have at your disposal?
Normally this is easily done manually using the Raster Calculator:
Raster Calculator—Help | ArcGIS Desktop (ArcMap) or
Raster Calculator—Help | ArcGIS Desktop (ArcGIS Pro)
You could simply specify a formula like:
Con(myRaster >= 1000, Con(myRaster <= 4000, myRaster))
In Python you can do something similar:
import arcpy
from arcpy.sa import *
arcpy.CheckOutExtension("Spatial")
dem = arcpy.Raster(r'C:\GeoNet\DEMrange\data.gdb\dem')
result = Con(dem >= 1000, Con(dem <= 4000, dem))
result.save(r'C:\GeoNet\DEMrange\data.gdb\result')
... but is it really necessary to do this in Python?