Question

How do I get the raster cell(s) with the maximum value?

  • 26 January 2017
  • 6 replies
  • 28 views

Badge +3

A very simple question, hopefully with a simple answer.

I have a single-band raster file with flood depths, and want to put a point or label at the deepest point ("X marks the spot"). I can get the deepest value using the RasterBandMinMaxExtractor, but how do I get the location of the deepest value.

The solution I've come up with so far is using a RasterCellCoercer converting the entire raster into a point feature class, and then extract the deepest point using a Tester transformer. But this feels to be a bit of a roundabout way, having to vectorise the raster first.

Hopefully/Surely there is a shortcut....?


6 replies

Badge +22

I have two thoughts, no idea which will end up being more efficient.

1. RasterExpressionEvaluator, deepest value = 1, everything else = NoData, followed by a RasterCellCoercer with extract NoData set to No.

 

 

2. Convert the raster to a point cloud (PointCloudCombiner) followed by a PointCloudFilter, and optionally a PointCloudCoercer.

 

 

The point cloud tools are quite efficient and there are often gains in converting a raster to a point cloud and processing.
Userlevel 2
Badge +16

As a follow-up on @jdh I would add:

If you create a point cloud you could use the PointcloudStatisticsCalcultator transformer to get the values.

Badge +22

As a follow-up on @jdh I would add:

If you create a point cloud you could use the PointcloudStatisticsCalcultator transformer to get the values.

Yes, that is generally more efficient than the RasterBandMinMaxExtractor

 

 

Badge +3

I have two thoughts, no idea which will end up being more efficient.

1. RasterExpressionEvaluator, deepest value = 1, everything else = NoData, followed by a RasterCellCoercer with extract NoData set to No.

 

 

2. Convert the raster to a point cloud (PointCloudCombiner) followed by a PointCloudFilter, and optionally a PointCloudCoercer.

 

 

The point cloud tools are quite efficient and there are often gains in converting a raster to a point cloud and processing.
We have a winner! I set up a workspace with my original solution and both your suggestions (incl. @erik_jan's suggestion below), and option 2 is by far the fastest and most efficient. I took a large 500MB Esri ASCII Grid file, and got the following results:

 

  • My original solution = duration 16 min 39.8s, peak memory 881424 kB
  • Alternative solution 1 = duration 2 min 28.1s, peak memory 122756 kB
  • Alternative solution 2 = duration 1 min 20.5s, peak memory 55836 kB
Workbench (without data) attached.

 

 

I think your comment about converting raster to a point cloud may turn out to be a valuable one!

 

 

Badge
We have a winner! I set up a workspace with my original solution and both your suggestions (incl. @erik_jan's suggestion below), and option 2 is by far the fastest and most efficient. I took a large 500MB Esri ASCII Grid file, and got the following results:

 

  • My original solution = duration 16 min 39.8s, peak memory 881424 kB
  • Alternative solution 1 = duration 2 min 28.1s, peak memory 122756 kB
  • Alternative solution 2 = duration 1 min 20.5s, peak memory 55836 kB
Workbench (without data) attached.

 

 

I think your comment about converting raster to a point cloud may turn out to be a valuable one!

 

 

There is another scenario where conversion to point cloud has significant performance boost, and this is when using a terrain model of some sort. With some series of point or line vertices and SurfaceDraper it can take several hours to build a large model and drape features. Converting input to pointcloud and using PointCloudOnRasterComponentSetter (using Z component) same data takes less than a minute to be brought to ground/raster level.

 

 

Userlevel 4
Badge +25
Just saw this question (from January) and wanted to mention that this is already filed as an enhancement request with our developers. It's PR#15552. I've increased the priority and posted a link to this thread, so we can hopefully get a fix and be informed about it. Glad you have a working solution.

 

Reply