[R-sig-Geo] nearest distance in matrix
Marius Gilbert
mgilbert at ulb.ac.be
Wed Jul 14 18:49:16 CEST 2004
Hello,
I'm trying to use R to simulate biological invasions, and got stuck with
the following:
Is there a function that uses a matrix of occupied/empty values (1 or 0)
as input, and producing an output matrix of the same size, with each cell
containing the distance to the nearest occupied cell (1) of the input
matrix ?
For example, the input matrix:
0 1 1 0
0 0 1 0
0 0 0 0
0 0 0 0
Would produce an output matrix like:
1 0 0 1
1.4 1 0 1
2.2 1.4 1 1.4
2.8 2.2 2.0 2.2
For those familiar with AV Spatial Analyst, this function would be the
equivalent of OutGrid = EucDistance (directionFN, allocationFN,
maxDistance).
Many thanks in advance for any help or pointers,
Marius
More information about the R-sig-Geo
mailing list