Environment mask ERROR 010422

4560
5
11-07-2014 02:55 AM
BenLeslie1
Regular Contributor

Hi

I'm doing a python script that does:

outRast = Raster(inRast1) - Raster(inRast2)

I have about 500 of these to process however after about 100 of these the script fails with the warning:

"ERROR 010422: Error in processing the environment mask"

The trouble is that I cannot see anything different in the rasters being processed when the script fails compared to all the ones it has already completed.

I added a shapefile that encolses all the rasters

     arcpy.env.mask = "mask_poly.shp"

but this hasn't helped.  I'm stuck for things to try.

0 Kudos
5 Replies
DuncanHornby
MVP Notable Contributor

Can you upload the full code, its difficult to answer this with just 1 line of code which is clearly ok if it ran for 100 times?

0 Kudos
DanPatterson_Retired
MVP Emeritus

Always the same one?  It sounds like one of the rasters doesn't fit within the mask and was projected-on-the-fly

0 Kudos
BenLeslie1
Regular Contributor

But what can I do about it?  I've created a mask shapefile that encompasses all my files but it hasn't helped - I'm not clear on what the mask does.  Can I somehow clear a cache so it's recreated.

It does always fail on the same one, but that's not the only one that fails.  I thought it might be a problem with cell size but files that have smaller and larger cells have passed through ok.  Files that include nulls have also passed ok.

This is the full script - and then the botton 4 lines repeat some 500 times with different inputs and outputs.  The point of the script is to look for differences in elevation in adjacent tiles - each tile has a 1 row or column of pixel overlaps with its neighbour.

import arcpy

import os

from arcpy import env

arcpy.CheckOutExtension("Spatial")

from arcpy.sa import *

env.workspace = "c:/myfiles"

arcpy.env.mask = "c:/maskpoly.shp"

inRast = "E000_N00.tif"

inRast2 = "E000_N01.tif"

outRast = Raster(inRast) - Raster(inRast2)

outRast.save = "c:/E000_N00a.tif"

0 Kudos
DanPatterson_Retired
MVP Emeritus

My point was about projections on the fly...is there the remotest possibility that those tiles have been projected-on-the-fly so they appear to be within the mask but are actually not?  I would add those tiles that fail ...separately....into a dataframe and examine the coordinates using the coordinates in the bottom right hand corner of the frame and see if they agree with what is expected.  alternately bring in just the adjacent tiles and recreate the mask for just those and see if it makes sense.  You have ruled out cell size and nodata issues, it boils down to the mask itself or your use of a mask in the first place..

from the help files.... " 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.

and for snap raster "

Tools that honor the Snap Raster environment will adjust  the extent of output rasters so that they match the cell alignment of the specified snap raster.

A Snap Raster is typically used where inputs to tools:

  • Have different cell alignments
  • Have different cell resolutions
  • Have different coordinate systems
  • Are features

Sooo that is all I can think of... dump the mask...or set cell size and coordinate system...or examine the snap raster possibility.
Good luck and please report back

BenLeslie1
Regular Contributor

ok so I don't really understand the problem but I defined an extent and it seems to work now.

I can define the extent at the beginning as the whole world but, as expected, the script runs slowly.  So I calculate the extents for each raster pair in turn.

arcpy.env.extent = arcpy.Extent(minX, minY, maxX, maxY)

.......hmmm, I also set snap raster to be the same as input raster as just setting extend produced inaccurate results - I don't understand why I have to do this when my input1 and input2 have same cell size and cell alignment.

arcpy.env.snapRaster = inRast

0 Kudos