[GRASS5] Re: [GRASSLIST:3661] Re: moving window bigger than 25 cells

Glynn Clements glynn.clements at virgin.net
Tue Jun 15 05:16:48 EDT 2004


Hamish wrote:

> > > I need to calculate max, min and mean values within a moving window with 
> > > a window size bigger than 25 cells (which is the upper limit for 
> > > r.neighbors). Does anybod know some advice?
> > 
> > If you have the source code, delete the following line:
> > 
> > 	parm.size->options    = "1,3,5,7,9,11,13,15,17,19,21,23,25" ;
> > 
> > from src/raster/r.neighbors/cmd/main.c, then re-compile and
> > re-install.
> 
> is this better?
> 
> 
> >From  src/raster/r.param.scale/interface.c
> /*-----------------------------------------------------------------*/
> /*          CHECK WINDOW SIZE IS NOT EVEN OR TOO LARGE             */
> /*-----------------------------------------------------------------*/
>     if ( (wsize/2 != (wsize-1)/2) || (wsize > MAX_WSIZE) )
>     {
>         char err[256];
>         sprintf(err,"Inappropriate window size (too big or even)");
>         G_fatal_error(err);
>     }

The sprintf() is unnecessary:

    if ( (wsize/2 != (wsize-1)/2) || (wsize > MAX_WSIZE) )
        G_fatal_error("Inappropriate window size (too big or even)");


> src/raster/r.param.scale/param.h:  #define MAX_WSIZE 69
> 
> is the upper limit (25) anything more than a local resources problem?

The upper limit is probably an artifact of not wanting to type in a
complete list of valid values. I doubt that a 1001x1001 window would
pose any problems (other than the time taken).

Personally, I would just drop the parm.size->options line, and add:

    if (ncb.nsize % 2 != 1)
        G_fatal_error("Window size must be odd");

Many GRASS programs can fail due to insufficient memory. In general,
we just rely upon G_malloc() calling G_fatal_error() if malloc()
fails, rather than trying to predict this in advance. I see no reason
to make an exception for r.neighbours.

The same applies for the product of two integers overflowing. If this
happens, most programs will either produce bogus results or crash. And
I doubt that's ever going to change (too much work).

-- 
Glynn Clements <glynn.clements at virgin.net>




More information about the grass-dev mailing list