[R-sig-Geo] distances between polygons
adrian at maths.uwa.edu.au
adrian at maths.uwa.edu.au
Mon Feb 4 08:43:20 CET 2008
Didier Leibovici <didier.leibovici at nottingham.ac.uk> wrote:
> Subject: [R-sig-Geo] sp basics !
> I would like to read some shapefiles of polygons( I know how to do that)
> and loop through all the polygons to be able to compute the shortest
> distance to one another (fix) polygon
> e.g. distance to the sea or to a montain
> -I had at one point a polylist but probably I need to have "consistant"
> polygon for each element of the list ?
> -is there any distance method supported by a class "polygon" which can
> compute the distance to another geometry?
This is possible in package 'spatstat' version 1.12-6 (just released; not
yet on CRAN).
First convert your polygons to lists of edges (objects of class "psp") in
spatstat. Then use
D <- crossdist.psp(A, B, type="separation")
to compute the matrix of shortest distances between an edge in list A and
an edge in list B. Finally take the minimum of the non-diagonal entries in
the matrix D
diag(D) <- Inf
dmin <- min(D)
to determine the shortest distance from polygon A to polygon B.
Adrian Baddeley
More information about the R-sig-Geo
mailing list