[GIS] Using Raster Calculator expression in Python

arcpymap-algebraraster-calculator

I've posted about this problem before but I've got a few new questions.

So here's the problem. I have two rasters containing bathymetry data: one containing the bathymetry of the sea floor, we'll call this raster1, and another containing the difference between two previous scans of the same area, we'll call this raster2. I have to query raster2 such that any areas where the value is >10% of raster1's value will be highlighted. I can do this in Raster Calculator in ArcGIS and using:

Abs("raster2") > 0.1 * "raster1"

Now the Raster Calculator approach works great, but I tried to incorporate this step into a larger script with these lines of code:

arcpy.CheckOutExtension("Spatial")
outFinal = Abs(outDiffMinus) > (0.1 * outIntShallow)
#The output needs to be saved as an ASCII file due to the applications of my script
arcpy.RasterToASCII_conversion(outFinal, directory)

The problem is that the script approach only shows areas that don't fit the criteria (i.e. the "0" areas in the Raster calculator approach).

Here's the output from the raster calculator:
enter image description here

And here's the script's output of the same area:

enter image description here

Any thoughts on what could be wrong with my script?

Best Answer

Well, turns out the issue is when I converted "outFinal" to ASCII, everything got assigned as the same value, but when I saved it as a BIL, the calculation worked, as shown here:

enter image description here

So if you're raster isn't categorized right the first time around. Try saving it as a BIL or another format.

Related Question