[GRASS-dev] dealing with null values in rasters only within mask

Moritz Lennert mlennert at club.worldonline.be
Mon Jul 1 02:50:10 PDT 2019


Hi Markus,

On 28/06/19 22:08, Markus Metz wrote:
> Hi Moritz,
> 
> On Fri, Jun 28, 2019 at 11:56 AM Moritz Lennert 
> <mlennert at club.worldonline.be <mailto:mlennert at club.worldonline.be>> wrote:
>  >
>  > On 28/06/19 11:10, Stefan Blumentrath wrote:
>  > > Hi Moritz,
>  > >
>  > > Did you consider r.stats -N for checking for NULL values within the 
> masked area, like:
>  > > r.stats -N input=tile,MASK
>  > > if there is *|1 in the output you have NULL cells in the tile...
> 
> the fastest way to get the total number of cells and the number of 
> non-NULL cells, ignoring any MASK, is r.info <http://r.info> -s, e.g.
> cells=4917486    <-- total number of cells
> n=4873149         <-- number of non-NULL cells
> 
> these numbers are stored in metadata and independent of the current region

But so this does not help in my problem which is to determine the number 
of NULL pixels within a given MASK.

>  > > For filling NULLs with a given value you could do:
>  > > r.mapcalc 
> expression=tile_filled=if(MASK,if(isnull(tile),1,tile),null())
> 
> in this case, I recommend to create a custom mask that is not named MASK 
> but e.g. mymask, and the r.mapcalc expression probably needs some 
> modification regarding NULL values in mymask:
> r.mapcalc expression="tile_filled = if(isnull(mymask) != 0 and mymask != 
> 0, if(isnull(tile), 1, tile), null())"
> 
> The reason is that if(MASK, ...) should return NULL if MASK is NULL 
> which is not what you want, you want " if MASK is not NULL"

Right, thanks for the hint !

Moritz



More information about the grass-dev mailing list