Maciek Sieczka via RT wrote:
This bug is still present and it's bad. In spearfish60:
$ g.region -a n=4916070 s=4915800 w=602940 e=603240 res=30
$ r.mapcalc 'map1=1'
$ g.region -a n=4916250 s=4915620 w=602730 e=603450 res=30
$ g.region zoom=map1
$ g.region -g
n=4916070
s=4915800
w=602940
e=603270
nsres=30
ewres=30
rows=9
cols=11
WRONG: 'e' should be '603240' -> 'cols' should be '10'.
I've committed this change:
--- general/g.region/cmd/zoom.c 20 Aug 2006 14:40:05 -0000 2.3
+++ general/g.region/cmd/zoom.c 25 Sep 2006 14:45:10 -0000
@@ -47,7 +47,7 @@
if (row < top) top = row;
if (row > bottom) bottom = row;
if (col < left) left = col;
- for (mark = col++; col < ncols; col++)
+ for (mark = col; col < ncols; col++)
{
if (!G_is_null_value(rast_ptr, map_type))
mark = col;
col gets incremented (the fact that we got here means that we already
know that raster[col] is non-null, so we can skip testing it again),
but rast_ptr doesn't, so the two are out of sync. Either rast_ptr
needs to be explicitly incremented along with col, or col should not
be incremented (the latter is simpler, and probably clearer; the
inefficiency is trivial).
Also, the issue is much worse than your example suggests. Because col
is one too high, the loop never examines the rightmost column.
Consider:
$ g.region -a n=4916070 s=4915800 w=602940 e=603240 res=30
$ r.mapcalc 'map1 = if(col() == 1 || col() == 10,1,null())'
$ g.region -a n=4916250 s=4915620 w=602730 e=603450 res=30
$ g.region rast=map1
$ g.region zoom=map1
$ g.region -p
projection: 1 (UTM)
zone: 13
datum: nad27
ellipsoid: clark66
north: 4916070
south: 4915800
west: 602940
east: 603000
nsres: 30
ewres: 30
rows: 9
***> cols: 2
cells: 18
Thus, "g.region zoom=..." can actually make the region too small,
discarding valid data.
--
Glynn Clements <glynn@gclements.plus.com>