[GRASS-dev] r.neighbors bug in cvs

Glynn Clements glynn at gclements.plus.com
Wed Sep 19 04:19:07 EDT 2007


Trevor Wiens wrote:

> I have found an error in the CVS version of the average for r.neighbors.

I'm glad that someone is actually checking their results; this bug has
been present for over a year, and you're the first person to notice.

> I've tested this with source compiles of the latest cvs snapshot on both a 32 bit and 64 bit machine.
> 
> Basically, the 6.2 version of r.neighbors gives the correct value. The cvs version reports inflated values for DCELL input layers.
> 
> For example if the input values in a 3x3 window are:
> 
> 0.8747536354 0.9208617206 1.0010881339
> 1.0152474088 1.0720150743 1.0436036351
> 1.0319341389 1.0412245464 1.0209956859
> 
> the value for the center pixel should be: 1.0024137755
> 
> the cvs version reports 1.518590477 for a regular square window and 1.5024137755 using a circular window.

I think that you have those numbers the wrong way around. I get
1.5185904770400001 with -c and 1.5024137754777778 without it.

Note that the square window case is off by exactly 0.5 (the -c switch
isn't present in 6.2.x).

When I replaced the aggregates with those in lib/stats, I moved the
rounding out of the individual aggregates and into the main program.
The 0.5 should only be added when writing integer maps, but that part
got missed.

Fixed in CVS, with:

--- raster/r.neighbors/main.c	11 Sep 2007 17:53:52 -0000	2.16
+++ raster/r.neighbors/main.c	19 Sep 2007 08:04:31 -0000
@@ -216,7 +216,7 @@
 		exit(EXIT_FAILURE);
 	}
 
-	half = menu[method].half;
+	half = (map_type == CELL_TYPE) ? menu[method].half : 0;
 
 	/* establish the newvalue routine */
 	newvalue = menu[method].method;

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




More information about the grass-dev mailing list