0

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, but only where the difference is negative. 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 with this expression:

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

However I'm trying to write a script to do this and as we know, you can not use Raster Calculator in Python. So I tried this code:

outAbs = Abs(raster2)
outTimes = Times(raster1, 0.1)
arcpy.CheckOutExtension("Spatial")
outFinal = outAbs > outTimes

But I get:

RuntimeError: ERROR 010422: Error in processing the environment mask.

To be clear, raster1 and raster 2 are both in GRID format.

Any ideas why I might be getting this error?

4
  • 1
    Do both files have the same projection and cell size?
    – Barbarossa
    Aug 5, 2015 at 19:49
  • You could try your raster calculation with numpy. Have a look at the "Working with rasters" section in the following link - resources.arcgis.com/en/help/main/10.2/index.html#//… Aug 5, 2015 at 19:57
  • @Barbarossa you've saved me again by pointing out the obvious haha
    – purelyp93
    Aug 5, 2015 at 22:52
  • Glad to help. I'll post as an answer.
    – Barbarossa
    Aug 5, 2015 at 22:57

2 Answers 2

4

The ArcGIS help for many tools can usually point you towards potential culprits of errors. The error in your case mentions environment mask.

The Mask help states the following:

If the analysis mask is a feature dataset, it will internally be converted to a raster on execution. For this reason, you should take care to ensure that the Cell Size and Snap Raster are set appropriately for your analysis.

In other words, make sure the cell size of all rasters involved are the same.

Be sure to also ensure all data involved have the same projections.

2

You can use map algebra syntax in Python, similar to the Raster Calculator:

import arcview, arcpy
from arcpy.sa import *
arcpy.CheckOutExtension("Spatial")

raster1 = Raster('/path/to/raster1')
raster2 = Raster('/path/to/raster2')

out_final = (Abs(raster2) > 0.1) * raster1
out_final.save('/path/to/raster3')

I'm not sure why you're getting the RuntimeError: ERROR 010422: Error in processing the environment mask.. If you are setting arcpy.env.mask (or running script as a script tool from the toolbox and setting the mask environment), make sure you are setting it to an existing dataset.

1
  • It turns out that the cell size of the two inputs were not even close to eachother, so that explains the Runtime Error. Thanks for the map algebra syntax, what I originally had worked anyways but I'll use your's for efficiency's sake.
    – purelyp93
    Aug 5, 2015 at 22:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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