Hi !
I'm using GRASS for lidar data calculation in forest inventory.
I needed r.neighbors to calculate values only to every 20 th row and column. Thus I added a new parameter step in r.neighbors program. At the same time I allowed user to choose a larger subwindow in calculations.
Here's my modifications to r.neighbors code (generated with diff -u r.neighbors r.neighbors2 >grassdiff). My source code is released version of GRASS 6.2.
grassdiff starts
**************************************************************************
diff -u r.neighbors/main.c r.neighbors2/main.c
--- r.neighbors/main.c 2006-08-23 10:29:12.000000000 +0300
+++ r.neighbors2/main.c 2006-11-15 09:29:35.000000000 +0200
@@ -39,7 +39,7 @@
struct
{
struct Option *input, *output;
- struct Option *method, *size;
+ struct Option *method, *size, *step;
struct Option *title;
} parm;
struct
@@ -92,9 +92,16 @@
parm.size->key = "size" ;
parm.size->type = TYPE_INTEGER ;
parm.size->required = YES ;
- parm.size->options = "1,3,5,7,9,11,13,15,17,19,21,23,25" ;
+ parm.size->options = "1,3,5,7,9,11,13,15,17,19,21,23,25,37,29,31,33,35" ; /* J.Soimasuo 25 -> 35 */
parm.size->description= _("Neighborhood size") ;
+ parm.step = G_define_option(); /* J.Soimasuo added this parameter*/
+ parm.step->key = "step"; /* J.Soimasuo */
+ parm.step->type = TYPE_INTEGER; /* J.Soimasuo */
+ parm.step->answer = STEP; /* J.Soimasuo */ + parm.step->required = NO; /* J.Soimasuo */
+ parm.step->description = _("Step the rows and columns with this factor"); /* J.Soimasuo */
+
parm.title = G_define_option() ;
parm.title->key = "title" ;
parm.title->key_desc = "\"phrase\"" ;
@@ -177,6 +184,10 @@
/* get the neighborhood size */
sscanf (parm.size->answer, "%d", &ncb.nsize);
ncb.dist = ncb.nsize/2;
+ + /* Get the step factor */ /* J.Soimasuo */
+ sscanf(parm.step->answer, "%d", &ncb.step); /* J.Soimasuo */
+ ncb.firststep = ncb.step/2; /* J.Soimasuo */
/* allocate the cell buffers */
allocate_bufs ();
@@ -223,6 +234,13 @@
rp = result;
for (col = 0; col < ncols; col++)
{
+ if (((row + ncb.firststep) % ncb.step != 0) /* J.Soimasuo */
+ || ((col + ncb.firststep) % ncb.step != 0)) /* J.Soimasuo */
+ { /* J.Soimasuo */ + G_set_null_value(rp, 1, map_type); /* J.Soimasuo */
+ } /* J.Soimasuo */ + else /* J.Soimasuo */
+ { /* J.Soimasuo */
n = gather (values, col);
if (n < 0)
G_set_null_value(rp, 1, map_type);
@@ -231,8 +249,9 @@
DCELL out_val = newvalue (values, n, map_type);
G_set_raster_value_d(rp, out_val, map_type);
}
- rp = G_incr_void_ptr(rp, G_raster_size(map_type));
- ncb.center++;
+ } /* J.Soimasuo */
+ rp = G_incr_void_ptr(rp, G_raster_size(map_type));
+ ncb.center++;
}
G_put_raster_row (out_fd, result, map_type);
}
diff -u r.neighbors/method.h r.neighbors2/method.h
--- r.neighbors/method.h 2004-11-09 15:27:15.000000000 +0200
+++ r.neighbors2/method.h 2006-11-15 09:25:53.000000000 +0200
@@ -10,6 +10,7 @@
};
#ifdef MAIN
#define NO_CATS 0
+#define STEP "1" /* J.Soimasuo */
diff -u r.neighbors/ncb.h r.neighbors2/ncb.h
--- r.neighbors/ncb.h 2004-11-09 15:27:18.000000000 +0200
+++ r.neighbors2/ncb.h 2006-11-15 09:17:33.000000000 +0200
@@ -4,6 +4,8 @@
int *value; /* neighborhood values */
int nsize; /* size of the neighborhood */
int dist; /* nsize/2 */
+ int step; /* Stepping factor when calculating values */ /* J.Soimasuo */
+ int firststep; /* step/2 */ /* J.Soimasuo */
struct Categories cats;
char title[1024];
FILE *out;
**************************************************************************
grassdiff ends
Regards,
Janne Soimasuo
Finland