Question

Raster Test for nodata

  • 5 November 2015
  • 2 replies
  • 2 views

Badge +1
I am tiling a raster dataset of elevation. if one of the tiles only has nodata values i want to remove that tile from the process

 

any ideas on the process?

2 replies

Userlevel 4
Hi

 

 

You can use the RasterBandMinMaxExtractor and test if the resulting list values only contain nodata (e.g. using the ListRangeExtractor):

 

_band{}.min

 

_band{}.max

 

 

David

 

Userlevel 4
For reference, here is also a small Python snippet that will check the _band{} list to see if a raster only contains one value (e.g. all white or black) , it should be relatively easy to adapt to other criteria:

 

 

max_values = [int(x) for x in feature.getAttribute('_band{}.max')]
min_values = [int(x) for x in feature.getAttribute('_band{}.min')]
values = zip(max_values, min_values)
contents = sum([x[0]-x[1] for x in values])
if contents == 0:
    # No content, all min and max cell values are identical on every band
    feature.setAttribute('_raster_contents', 'EMPTY')
else:
    feature.setAttribute('_raster_contents', 'OK')

 

You probably shouldn't be using it as-is on your rasters unless you know for a fact that single-color tiles are invalid.

 

 

David

Reply