Skip to main content
Question

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


Forum|alt.badge.img

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

Forum|alt.badge.img
  • Author
  • January 13, 2022

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


takashi
Contributor
Forum|alt.badge.img+21
  • Contributor
  • January 13, 2022

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


mark2atsafe
Safer
Forum|alt.badge.img+43
  • Safer
  • January 14, 2022

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.


mark2atsafe
Safer
Forum|alt.badge.img+43
  • Safer
  • January 17, 2022
mark2atsafe wrote:

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings