How to check if a raster has a NULL value

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

How to check if a raster has a NULL value

Robert Nuske
Hi Listers,

r.fillnulls exits with an error if the input map has no holes.
r.fillnulls one step in a bash script. The processing is stopped if
r.fillnulls writes no output because of an error.

Thus i would like to check if any holes need to be filled. If this is
the case run r.fillnulls and if not just copy input to output map name.

Is there a handy command which reports if there are any NULLs in the
raster map. The output of the command shall be used in a bash if
construction.


thanks
   robert



_______________________________________________
grass-user mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/grass-user
Reply | Threaded
Open this post in threaded view
|

Re: How to check if a raster has a NULL value

Markus Neteler
Hi Robert,

On Tue, Jun 18, 2019 at 1:54 PM Robert Nuske <[hidden email]> wrote:

>
> Hi Listers,
>
> r.fillnulls exits with an error if the input map has no holes.
> r.fillnulls one step in a bash script. The processing is stopped if
> r.fillnulls writes no output because of an error.
>
> Thus i would like to check if any holes need to be filled. If this is
> the case run r.fillnulls and if not just copy input to output map name.
>
> Is there a handy command which reports if there are any NULLs in the
> raster map. The output of the command shall be used in a bash if
> construction.

Yes: e.g., r.univar can do that:

GRASS 7.6.2git (nc_spm_08_grass7):~ >

g.region raster=boundary_county_500m
r.univar -g boundary_county_500m
n=616509
null_cells=506073
cells=1122582
min=0
max=199
range=199
mean=87.1764564669778
mean_of_abs=87.1764564669778
stddev=62.4325833627095
variance=3897.82746534167
coeff_var=71.6163352961689
sum=53745070

Usage in a shell script:

g.region raster=boundary_county_500m
eval $(r.univar -g boundary_county_500m)
echo $null_cells
506073

HTH,

Markus
_______________________________________________
grass-user mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/grass-user
Reply | Threaded
Open this post in threaded view
|

Re: How to check if a raster has a NULL value

Robert Nuske
Moin Markus,

thanks a ton!


cheers
   robert

Am 18.06.19 um 15:31 schrieb Markus Neteler:

> Hi Robert,
>
> On Tue, Jun 18, 2019 at 1:54 PM Robert Nuske <[hidden email]> wrote:
>>
>> Hi Listers,
>>
>> r.fillnulls exits with an error if the input map has no holes.
>> r.fillnulls one step in a bash script. The processing is stopped if
>> r.fillnulls writes no output because of an error.
>>
>> Thus i would like to check if any holes need to be filled. If this is
>> the case run r.fillnulls and if not just copy input to output map name.
>>
>> Is there a handy command which reports if there are any NULLs in the
>> raster map. The output of the command shall be used in a bash if
>> construction.
>
> Yes: e.g., r.univar can do that:
>
> GRASS 7.6.2git (nc_spm_08_grass7):~ >
>
> g.region raster=boundary_county_500m
> r.univar -g boundary_county_500m
> n=616509
> null_cells=506073
> cells=1122582
> min=0
> max=199
> range=199
> mean=87.1764564669778
> mean_of_abs=87.1764564669778
> stddev=62.4325833627095
> variance=3897.82746534167
> coeff_var=71.6163352961689
> sum=53745070
>
> Usage in a shell script:
>
> g.region raster=boundary_county_500m
> eval $(r.univar -g boundary_county_500m)
> echo $null_cells
> 506073
>
> HTH,
>
> Markus
>

_______________________________________________
grass-user mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/grass-user
Reply | Threaded
Open this post in threaded view
|

Re: How to check if a raster has a NULL value

Moritz Lennert
In reply to this post by Markus Neteler
On 18/06/19 15:31, Markus Neteler wrote:

> Hi Robert,
>
> On Tue, Jun 18, 2019 at 1:54 PM Robert Nuske <[hidden email]> wrote:
>>
>> Hi Listers,
>>
>> r.fillnulls exits with an error if the input map has no holes.
>> r.fillnulls one step in a bash script. The processing is stopped if
>> r.fillnulls writes no output because of an error.
>>
>> Thus i would like to check if any holes need to be filled. If this is
>> the case run r.fillnulls and if not just copy input to output map name.
>>
>> Is there a handy command which reports if there are any NULLs in the
>> raster map. The output of the command shall be used in a bash if
>> construction.
>
> Yes: e.g., r.univar can do that:
>
> GRASS 7.6.2git (nc_spm_08_grass7):~ >
>
> g.region raster=boundary_county_500m
> r.univar -g boundary_county_500m
> n=616509
> null_cells=506073
> cells=1122582
> min=0
> max=199
> range=199
> mean=87.1764564669778
> mean_of_abs=87.1764564669778
> stddev=62.4325833627095
> variance=3897.82746534167
> coeff_var=71.6163352961689
> sum=53745070
>
> Usage in a shell script:
>
> g.region raster=boundary_county_500m
> eval $(r.univar -g boundary_county_500m)
> echo $null_cells
> 506073
>

Just watch out that this will not work as expected when you have set a mask:

https://trac.osgeo.org/grass/ticket/3696

Moritz
_______________________________________________
grass-user mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/grass-user