You could approach it as a minimum distance between points problem.
With sp, first convert each SpatialPolygons to SpatialLines, generate regular points on each line and then compute minimum dist between all points. Obviously, there is a trade off between the number of points and precision.

Something like this:

require(sp)

# 1st  "polygon"
p1 = SpatialLines(list(Lines(list(Line(cbind(c(10.92, 8.13, 17.12, 29.97, 31.06, 25.95, 20.21,10.92),
c(86.56, 73.24, 59.75, 67.54, 75.84, 86.39, 95.04,86.56) ))))))

# 2nd "polygon"
p2 = SpatialLines(list(Lines(list(Line(cbind(c(41.75, 35.55, 42.68, 53.99, 60.96, 58.94, 53.21,41.75),
c(66.5, 53.87, 41.07, 42.11, 51.62, 64.77, 67.36,66.5)))))))

plot(1:100, type = "n")
plot(p1, add = T)
plot(p2, add = T)


# regular  sampling on each polygon
n = 500
p1.pts = spsample(p1, n = n, type = "regular")
p2.pts = spsample(p2, n = n, type = "regular")

# minimun distance between polygons' edges
min(apply(coordinates(p1.pts), 1, function(p) spDistsN1(coordinates(p2.pts), p )))


...
Mihai





Marion TAFANI wrote:
dear all,

we want to calculate the minimun distance between polygons' edges , do you know any package or function which can help us ? we try to work with vectors rather than raster but we lack some tools. we only found how to calculate distances between centroids but nothing between edges.

thanks



__________ Information from ESET Mail Security, version of virus signature database 3904 (20090303) __________

The message was checked by ESET Mail Security.
http://www.eset.com

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo



-

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to