[GRASS-dev] Test if raster map and current region match?
Roger Bivand
Roger.Bivand at nhh.no
Tue Jun 24 10:29:39 EDT 2008
On Tue, 24 Jun 2008, Glynn Clements wrote:
>
> 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
>
Thanks, elegant, I know. But it isn't cross-platform. All I need is an
answer TRUE/FALSE for the comparison of the 6 values. I assume that the
printf()s are using the same rounding, right? Both r.info and g.region use
G_format_easting(), G_format_northing(), G_format_resolution() in
lib/gis/wind_format.c, using format_double(), which is hard-wired to
"%.8f". Are we going to pick up numerical fuzz anywhere from conversion
to text (high longlat resolution)?
I guess I'll have to trust the text representation, read it into R,
convert to doubles, and ask abs(rast$w - wind$w) < .Machine$double.eps for
each of the six comparisons, and perhaps handle longlat with a slacker
precision.
Roger
>
--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no
More information about the grass-dev
mailing list