Skip to main content

I have stumbled across a raster size problem in RasterExpressionEvaluator whereas two input rasters are clipped using Clipper to the exact same shape, however some of them upon arriving for raster calculation differ by one pixel.

The problem is that although all input rasters are of different sizes only some in several hundred will result in this error quite randomly despite use of clipping that should cut them precisely to same size.

|ERROR |RasterExpressionEvaluator_2(RasterEvaluationFactory): Raster A has '2119' rows and '2042' columns, whereas raster B has '2120' rows and '2042' columns. Paired rasters must have the same dimensions

Oh, that's not a fun problem. One possible workaround to this could be to use a RasterResampler (after the clipper) force all rasters to have the same number of columns and rows. You could take a sample raster after the clipper, use a RasterPropertyExtracter to get the cols, rows for this one raster. then use VariableSetters to pass the values to subsequent rasters.

 


I believe the clipper works on raster by including pixels whose center are inside the clipper boundary, and excluding those whose center are outside the clipper, even though a portion of the pixel is inside the clipper.

 

 

Minute differences in raster origin or pixel size can accumulate over the raster leading to the bottom/right pixels being just outside the clipper (or conversely just inside).

 

 

This is particularly evident when your images are in lat/long and the resolution might be 2.777777e-5 or 2.7777777e-5.

Oh, that's not a fun problem. One possible workaround to this could be to use a RasterResampler (after the clipper) force all rasters to have the same number of columns and rows. You could take a sample raster after the clipper, use a RasterPropertyExtracter to get the cols, rows for this one raster. then use VariableSetters to pass the values to subsequent rasters.

 

@virtualcitymatt thanks for your suggestion. I have indeed tried this before however with thousands of rasters to process, resampling each of them made it too slow, also secondly each output raster is different size too, so setting one size in stone wasn't an option. So finally I'm testing raster sizes before RasterExpressionEvaluator and re-direct only those that differ to RasterResampler. Also as @jdh suggested, at fault was a tiny shift on half-pixel level that sometimes, due to rounding error, have fallen just outside boundary.
@virtualcitymatt thanks for your suggestion. I have indeed tried this before however with thousands of rasters to process, resampling each of them made it too slow, also secondly each output raster is different size too, so setting one size in stone wasn't an option. So finally I'm testing raster sizes before RasterExpressionEvaluator and re-direct only those that differ to RasterResampler. Also as @jdh suggested, at fault was a tiny shift on half-pixel level that sometimes, due to rounding error, have fallen just outside boundary.
Nice solution! What a headache though.

 

 


I know this is an old post but it helped me out and I ended up building a custom transformer based on @virtualcitymatt​'s response.

 

https://hub.safe.com/publishers/front-point-consulting/transformers/rastersizeequaliser

 

Hopefully it's helpful to someone.


Reply