[GRASSLIST:2748] Re: r.neighbors with size>25

Christof Bigler christof.bigler at colorado.edu
Wed Feb 25 12:29:11 EST 2004


Since I have the binaries installed, I couldn't change the source code.

But if you have R, you can create easily a filter that you can use with 
r.mfilter in Grass.

Example with a quadratic filter (moving window):
filter <- data.frame(matrix(1,61,61))

Example with a circular filter:

filter.matrix.center.p <- function(n=9,size=5,p=2)
{
   x <- matrix(1,n,n)
   center <- (n+1)/2
   tmp <- (abs(row(x)-center)^p+abs(col(x)-center)^p)^(1/p) < size
   0 + tmp
}

filter <- filter.matrix.center.p(61,30,2)
Or filter.matrix.center.p(61,30.1,2) if you want to include the corner 
points

image(filter)

Then export the quadratic or circular filter:
write.table(filter,"61x61filter",sep=" ",row.names=F,col.names=F)

Open '61x61filter' e.g. in Xemacs and add the first two and the last 
two lines:
TITLE 61x61 filter
MATRIX 61
1 1 1 1 1 ...
...
1 1 1 1 1 ...
DIVISOR 1
TYPE P

In Grass, you write
r.mfilter map1 out=map2 filt=61x61filter

Christof

> If you have the source code, remove the 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 and re-compile.
>
> -- 
> Glynn Clements <glynn.clements at virgin.net>
>
>> I want to assign to each grid cell the number of grid cells with a 
>> certain characteristics in a neighborhood of 30x30 cells. The problem 
>> with r.neighbors is that it allows only neighborhood sizes up to 25.
>> Any ideas how to do it (without typing in 30x30 coordinates of the 
>> neighborhood cells in r.mapcalc...)?
>>
>> Christof
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 1584 bytes
Desc: not available
Url : http://lists.osgeo.org/pipermail/grass-user/attachments/20040225/eee8788c/attachment.bin


More information about the grass-user mailing list