[GRASS-dev] Test if raster map and current region match?

Glynn Clements glynn at gclements.plus.com
Tue Jun 24 10:06:44 EDT 2008


Markus Neteler wrote:

> >>> Is there a shell-level utility in GRASS to check whether the region of a
> >>> raster is equal to the current working region - the function could call
> >>> that and create a copy of the required raster in current resolution if they
> >>> differ?
> >>
> >> The easiest way it to compare the output of
> >>
> >> r.info -g map127
> >> north=230000
> >> south=214000
> >> east=646000
> >> west=628000
> >>
> >> and
> >> g.region -g | grep '^n=\|^s=\|^e=\|^w='
> >> n=228513
> >> s=214975.5
> >> w=629992.5
> >> e=645012
> >
> > But the resolution may differ too - I need a one shot comparison. Isn't
> > anything exposed - I've looked in g.copy and r.resample without seeing
> > anything. Maybe:
> >
> > r.info -gs elevation.dem
> > g.region -g | grep '^n=\|^s=\|^e=\|^w=\|^ewres=\|^nsres='
> >
> > but an internal match (where r.resample would be a no-op or not) would be
> > helpful.
> 
> Any hints for Roger?

"r.info -gs" will print both the bounds and resolution in shell-script
style:

$ r.info -gs elevation.dem
north=4928000
south=4914020
east=609000
west=590010
nsres=30
ewres=30

Although the output of the two commands is slightly different, it's
close enough that the keys will sort the same, so you can use e.g.:

map=map127
( g.region -g ; r.info -gs $map ) | sort | grep '^[nsew]' | sed 's/^.*=//' | uniq -u | grep . &> /dev/null
if [ $? = 0 ] ; then
    echo different
else
    echo same
fi

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-dev mailing list