I'm new to Python and have been trying to code a raster calculator style script. Basically, I want to convert a raster that has values 0 to -10,000 into a raster that is populated by 1s between certain values.
The reason I want to do it in Python is because I eventually want to automate this process so that I can pick out different values (ie 0 to -10, -5 to -25 etc) and end up with a raster of 1s for each. My aim then is to convert these to polygons so that I can then do a number of vector clip operations across about 800 shapefiles.
I've written a script which produces a new raster at the end but instead of this grid being full of 1s it has values 0-256, so somewhere in my code there's a bug. I'd be grateful if anyone can spot it! If anyone has a way to speed up the code or a better idea for how I can do all this also then that would also be interesting to know.
Here's my code:
import arcpy from arcpy import env from arcpy.sa import * arcpy.env.overwriteOutput = 1 #this also doesn't work by the way, I have also tried #TRUE, no errors come up but it still doesn't let me overwrite the output file #Set environment settings env.workspace = "C:/folderlocation where inRaster is stored" # Set local variables inRaster = Raster("inputraster") # Check out Spatial Analyst extension license arcpy.CheckOutExtension("Spatial") # depths wanted from inputraster raster var = [-2500,-3000] #min depth, max depth #Execute and save Con OutRaster = Con((inRaster <= var)&(inRaster <= var),1) OutRaster.save("C:/drivelocation/outputfilename")
If anyone has any ideas they'd be gratefully received! Many thanks.