Question

How to calculate the percentage of 'nodata' cells in a raster file?

  • 13 January 2022
  • 4 replies
  • 18 views

Badge

I'm trying to calculate the percentage of nodata cells within a raster by using the point cloud combiner + point cloud splitter in fme to extract the value of cells with data vs cells with nodata, and get a ratio.

 

It's clearly not the right approach as it is taking forever. Is there a better way to do this?

 

Usually it would be fore raster tiles with 1,000,000 cells. Counting the nbr of nodata cells in each file basicallyfme_raster_validity 

 


4 replies

Badge

Using the point cloud filter is what's needed. Filter, not splitter.

 

one filter with:

@Component(z)==@Value(_band{0}.band_nodata)

and another output with:

@Component(z)!=@Value(_band{0}.band_nodata)

fme_raster_validity2

Userlevel 2
Badge +17

Hi @ts_84​ , another approach, I think you can use RasterExtentsCoercer and AreaCalculator to get the areas of data extents and raster extents, and then calculate percentage of Nodata area from those areas.calculate-nodata-percentage

Userlevel 4
Badge +25

I have an RGB raster, 1600 x 1000 pixels, and am assuming 255 is nodata. What I tried is a RasterExpressionEvaluator using the expression:

 

Int8: if (A[0] < 255 && A[1] < 255 && A[2] < 255, 0, 1)

 

Basically, if a cell is <255 then create a value 0, else create a value 1.

 

Now I run this through a RasterStatisticsCalculator. It tells me that band0.sum = 235926

 

So (235926 / (1600 * 1000)) * 100 = 14.75, so 14.75% of my raster is made up of nodata.

 

The advantage of that method is that it's quick. The disadvantage is that it destroys the raster data. But it's easy enough to just get this result and then merge it back onto the original raster using a FeatureMerger.

Userlevel 4
Badge +25

I have an RGB raster, 1600 x 1000 pixels, and am assuming 255 is nodata. What I tried is a RasterExpressionEvaluator using the expression:

 

Int8: if (A[0] < 255 && A[1] < 255 && A[2] < 255, 0, 1)

 

Basically, if a cell is <255 then create a value 0, else create a value 1.

 

Now I run this through a RasterStatisticsCalculator. It tells me that band0.sum = 235926

 

So (235926 / (1600 * 1000)) * 100 = 14.75, so 14.75% of my raster is made up of nodata.

 

The advantage of that method is that it's quick. The disadvantage is that it destroys the raster data. But it's easy enough to just get this result and then merge it back onto the original raster using a FeatureMerger.

In case it helps, I made this one of our questions of the week and covered it here: https://www.youtube.com/watch?v=ZvSaHQ7gouI&t=87s

Reply