[GRASS-dev] Re: [GRASS-user] circle surrounding neighbors

Glynn Clements wrote:

> Sorry, I am a beginner... what shall I do with this gather-circle.c?

Replace raster/r.neighbors/gather.c with the new file, re-compile,
install the modified r.neighbors as e.g. r.neighbors.circle.

If you don't have the source code or can't figure out how to make the
necessary changes, you'll need to wait until someone integrates it
into GRASS.

FWIW, I've added a -c flag to r.neighbors to use a circular
neighborhood rather than a square.

I'm unsure as to whether the test should be < or <=. It's currently
<=, but that gives "spikes" (single cells) at the four edges. Using <
would give "flats", and would always omit the outermost row/column of
pixels. Maybe there should be a +0.5 in the distance calculation?

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

On Tuesday 31 July 2007 10:54:19 Glynn Clements wrote:

Glynn Clements wrote:
> > Sorry, I am a beginner... what shall I do with this gather-circle.c?
>
> Replace raster/r.neighbors/gather.c with the new file, re-compile,
> install the modified r.neighbors as e.g. r.neighbors.circle.
>
> If you don't have the source code or can't figure out how to make the
> necessary changes, you'll need to wait until someone integrates it
> into GRASS.

FWIW, I've added a -c flag to r.neighbors to use a circular
neighborhood rather than a square.

great!

I'm unsure as to whether the test should be < or <=. It's currently
<=, but that gives "spikes" (single cells) at the four edges. Using <
would give "flats", and would always omit the outermost row/column of
pixels. Maybe there should be a +0.5 in the distance calculation?

then the command works like

r.neighbors -c input=name output=name method=average size=5
and the output would be the average of values in a ring of 5x5 around the
center pixel, wouldn't it?

then I can drop my r.mapcalc script and close one old wish report related to
r.le but solved via r.neighbors
(http://www.intevation.de/rt/webrt?serial_num=2104&display=History) - thanks
a lot!

Martin

Thanks very much Glynn. We're using r.neighbors as part of a complex surface
process modeling routine. This may help to solve a recent set of weird
results we've been getting.

Michael

On 7/31/07 1:54 AM, "Glynn Clements" <glynn@gclements.plus.com> wrote:

Glynn Clements wrote:

Sorry, I am a beginner... what shall I do with this gather-circle.c?

Replace raster/r.neighbors/gather.c with the new file, re-compile,
install the modified r.neighbors as e.g. r.neighbors.circle.

If you don't have the source code or can't figure out how to make the
necessary changes, you'll need to wait until someone integrates it
into GRASS.

FWIW, I've added a -c flag to r.neighbors to use a circular
neighborhood rather than a square.

I'm unsure as to whether the test should be < or <=. It's currently
<=, but that gives "spikes" (single cells) at the four edges. Using <
would give "flats", and would always omit the outermost row/column of
pixels. Maybe there should be a +0.5 in the distance calculation?

__________________________________________
Michael Barton, Professor of Anthropology
Director of Graduate Studies
School of Human Evolution & Social Change
Center for Social Dynamics & Complexity
Arizona State University

phone: 480-965-6213
fax: 480-965-7671
www: http://www.public.asu.edu/~cmbarton

Martin Wegmann wrote:

> I'm unsure as to whether the test should be < or <=. It's currently
> <=, but that gives "spikes" (single cells) at the four edges. Using <
> would give "flats", and would always omit the outermost row/column of
> pixels. Maybe there should be a +0.5 in the distance calculation?

then the command works like

r.neighbors -c input=name output=name method=average size=5
and the output would be the average of values in a ring of 5x5 around the
center pixel, wouldn't it?

It's a filled circle (disc), not a "ring". The neighbourhood consists
of all cells whose Euclidean distance from the output cell is <=
size/2:

    for (i = 0; i < ncb.nsize; i++)
  for (j = 0; j < ncb.nsize; j++)
      ncb.mask[i][j] = sqr(i - ncb.dist) + sqr(j - ncb.dist) <= sqr(ncb.dist);

Note: "<=", not "=".

then I can drop my r.mapcalc script and close one old wish report related to
r.le but solved via r.neighbors
(http://www.intevation.de/rt/webrt?serial_num=2104&display=History) - thanks
a lot!

The diagram in that post suggests a ring rather than a circle.

I suppose I could add a (e.g.) matrix= option to read an
r.mfilter-style matrix from a file

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