[GRASS-user] circle surrounding neighbors
bks at centrum.cz
bks at centrum.cz
Mon Jul 30 10:07:03 EDT 2007
Sorry, I am a beginner... what shall I do with this gather-circle.c?
Thank you very much for your patience.
St.
______________________________________________________________
> Od: glynn at gclements.plus.com
> Komu: <bks at centrum.cz>
> CC: <grassuser at grass.itc.it>
> Datum: 30.07.2007 02:40
> Předmět: Re: [GRASS-user] circle surrounding neighbors
>
>bks at centrum.cz wrote:
>
>> don't you know about any possibility to use something similar to
r.neighbors
>> but for the circle surrounding of the pixel?
>
>Modify raster/r.neighbors/gather.c.
>
>An (untested) attempt is attached.
>
>--
>Glynn Clements <glynn at gclements.plus.com>
>
>
>#include <grass/gis.h>
>#include "ncb.h"
>
>/*
> given the starting col of the neighborhood,
> copy the cell values from the bufs into the array of values
> and return the number of values copied.
>*/
>
>static char **mask;
>
>static void init_mask(void)
>{
> int i, j;
>
> if (mask)
> return;
>
> mask = G_malloc(ncb.nsize * sizeof(char *));
>
> for (i = 0; i < ncb.nsize; i++)
> mask[i] = G_malloc(ncb.nsize);
>
> for (i = 0; i < ncb.nsize; i++)
> for (j = 0; j < ncb.nsize; j++)
> mask[i][j] = sqr(i - ncb.dist) + sqr(j - ncb.dist) <= sqr(ncb.dist);
>}
>
>int gather(DCELL *values, int offset)
>{
> int row, col;
> int n = 0;
>
> *values = 0;
>
> if (!mask)
> init_mask();
>
> for (row = 0; row < ncb.nsize; row++)
> for (col = 0; col < ncb.nsize; col++)
> {
> DCELL *c = &ncb.buf[row][offset + col];
>
> if (!mask[row][col])
> continue;
>
> if (G_is_d_null_value(c))
> G_set_d_null_value(&values[n], 1);
> else
> values[n] = *c;
>
> n++;
> }
>
> return n ? n : -1;
>}
>
>
>
More information about the grass-user
mailing list