[GRASS-user] How to check if a raster has a NULL value

Markus Neteler neteler at osgeo.org
Tue Jun 18 06:31:15 PDT 2019


Hi Robert,

On Tue, Jun 18, 2019 at 1:54 PM Robert Nuske <rsn.mailinglists at gmail.com> 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


More information about the grass-user mailing list