Paired rasters must have the same dimensions!

Introduction

I’ve been working with a lot of raster and point cloud data lately and have inevitably run up against some problems. One of the most frustrating I’ve encountered is when attempting to perform algebraic operations on a pair of rasters using the FME RasterExpressionEvaluator.

If the two input rasters do not have exactly the same number of rows and columns then you will run into the dreaded “Paired rasters must have the same dimensions“ error that looks something like this:

|ERROR |RasterExpressionEvaluator(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

Some quick sleuthing on the internet brings up virtualcitymatt’s excellent response to the problem in this FME Community question:

https://community.safe.com/s/question/0D54Q000080hAh7SAE/clipped-raster-size-problem-in-rasterexpressionevaluator

So, I thought I’d write up a little post on why I was running into this problem in the first place, and on the custom transformer that I developed to help solve the issue.

Scenario

In my workflow I’m using an input point cloud to generate rasters, and then using the RasterCellValueCalculator to generate some derived products.

Main FME workflow

In order to generate the derived raster products I need to determine the point cloud first returns, last returns and ground classified points. This is done using the PointCloudSplitter transformer. The results of this are then fed into a RasterDEMGenerator transformer to create the rasters required for the calculations.

Given that the same point cloud is used as input to the PointCloudSplitter, the resulting point clouds and, subsequently, the derived rasters will normally have the same size and will not cause any problems. However, for some point clouds the derived rasters are slightly different sizes – perhaps due to differing numbers of first/last/ground classified points.

Solution

A key aspect of the devised solution lies in the fact that the generated rasters are guaranteed to be in the same coordinate system with the same ground location and the same geographic size (given that they are all derived from the same original point cloud). If those key factors cannot be guaranteed then an alternative solution should be investigated.

Given that all of the rasters should be the same size (but are not always the same size) the simplest solution is to make them the same size! This can be achieved by using the RasterResampler in “Rows and Columns” mode to set the number of rows/columns for each raster to be the same.

The trick here is to determine the size of the smallest raster and then resample the other down to the smaller size. If the rasters are already the same size then no resampling is required.

Wrapping this functionality into a custom transformer makes for simple re-usability.

The custom transformer aims to be as efficient as possible. Once the raster properties have been extracted the geometry is removed and only the required properties (number of rows / columns) are kept. Some simple calculations and tests are performed to determine if the two input rasters have the same size and then, any raster with a number of columns or rows greater than the minimum number is resampled down to the minimum size. (It’s entirely possible that both rasters could be resampled if one has less rows and one has less columns).

Conclusion

Many thanks to virtualcitymatt for the inspiration.

If you think this solution might help you, you can download the RasterSizeEqualiser custom transformer from the FME Hub.

Next
Next

A Rule-Driven Approach to Data Validation