[GRASS-user] circle surrounding neighbors

Glynn Clements glynn at gclements.plus.com
Mon Jul 30 23:45:45 EDT 2007


bks at centrum.cz 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.

Alternatively, you could use r.mapcalc, but if your circle is large,
this is going to require a large expression. You would probably want
to use a script to generate it, e.g.:

#!/usr/bin/python
# example usage: python circle.py | r.mapcalc

size = 9

dist = size / 2

n = 0
cmd = "out.avg = ("
for i in range(-dist,dist+1):
    for j in range(-dist,dist+1):
	if i**2 + j**2 <= dist**2:
	    if n > 0:
	    	cmd = cmd + " + "
	    cmd = cmd + "inmap[" + str(i) + "," + str(j) + "]"
	    n=n+1
cmd = cmd + ") / " + str(n)
print cmd

n = 0
cmd = "out.min = min("
for i in range(-dist,dist+1):
    for j in range(-dist,dist+1):
	if i**2 + j**2 <= dist**2:
	    if n > 0:
	    	cmd = cmd + ", "
	    cmd = cmd + "inmap[" + str(i) + "," + str(j) + "]"
	    n=n+1
cmd = cmd + ")"
print cmd

n = 0
cmd = "out.max = max("
for i in range(-dist,dist+1):
    for j in range(-dist,dist+1):
	if i**2 + j**2 <= dist**2:
	    if n > 0:
	    	cmd = cmd + ", "
	    cmd = cmd + "inmap[" + str(i) + "," + str(j) + "]"
	    n=n+1
cmd = cmd + ")"
print cmd

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




More information about the grass-user mailing list