[GRASS-dev] Re: g.region bugs [was: GRASS 6.3.0 release preparation]

Glynn Clements glynn at gclements.plus.com
Wed Oct 17 18:06:42 EDT 2007

Maciej Sieczka wrote:

> > The -a flag causes the region to be aligned to the existing
> > resolution; the res= etc options aren't processed until later.
> >>  IN GRASS 6.3 CVS:
> <snip>
> > In 6.3-CVS, the -a flag aligns the vector to itself (!), rather than
> > to the original region.
> >
> > AFAICT, the error was introduced when the vect= option was extended to
> > allow multiple maps. Previously, temp_window was used to hold the
> > original region so that the new region (in window) could be aligned to
> > it.
> > 
> > The changed version uses temp_window to hold the region for the
> > current vector map (the bounds from the map but with the original
> > resolution) while window holds the cumulative region. The original
> > region is no longer stored anywhere, so alignment is not possible. The
> > change should have added a third variable rather than re-using
> > temp_window.
> > 
> > I've fixed this in CVS, where "fixed" means "behaves as in 6.2". 
> I confirm g.region behaves the same in 6.2 and 6.3 now. Thanks.
> > Changing the behaviour of -a to align to the new resolution rather
> > than the original resolution is an incompatible change.
> Why? It's been already alligning to new res for rasters, see:
> $ g.region n=5680980 s=5680960 w=602440 e=602480 res=20 -ag

There is no rast= in the above.

The -a flag affects the behaviour of vect= and the various resolution
options (res=, nsres=, ewres=, tbres=), i.e. the only code which tests
that flag is within the blocks which handle those options.

The only "global" alignment is the code which adjusts either the
bounds or the resolution to ensure that the numbers of rows and
columns are integers, and that is done regardless of whether -a is

The way that vectors are handled is strange. First, if either
dimension is zero, it is expanded to one cell according to the
existing resolution. Then, if -a is given, the bounds are aligned to
the existing resolution.

If you also specify res= (or {ns,ew,tb}res=), the resolution is set;
this occurs after the bounds have been set by rast=, vect=, [nsewtb]=,
etc. If -a is given, the bounds are then aligned to the new

So, when all of vect=, res= and -a are given, the bounds get aligned
twice; once to the original resolution, once to the new resolution.

Personally, I think that this is bogus, and I presume that you would
agree. But ... it's been this way since at least 5.3[1]. Which means
that it definitely shouldn't be back ported to 6.2, and it's debatable
whether it should go into 6.3. I would be more than happy to see it
changed in 7.x.

[1] Actually, in 5.3, the first alignment of the vector's bounds to
the existing resolution occurs regardless of whether or not -a is

For now, if you want to set the region to a vector's bounds, aligned
to a specific resolution, you need to run g.region twice; first with
res=, then with vect= and -a.

Glynn Clements <glynn at gclements.plus.com>

More information about the grass-dev mailing list