Skip to content
Prev 7478 / 29559 Next

Distance to (nearest) polygon

if you have a high precision coast line relative to the distances you
want to estimate, you could compute the distance of each point to the
nearest node of your coast line.
Here illustrated with a quick hack example based on what Roger just
send in response to Agus:

library(raster) # to get the data
fra = getData('GADM', country='FRA', level=0)
fra = as(fra, 'SpatialLines')
crd <- coordinates(fra)
crd <- sapply(crd, function(x) do.call("rbind", x))
# returns a vector, not sure why, but this fixes it
crd <- matrix(crd, ncol=2)
# plot(crd, cex=0.1)
min(pointDistance(c(-5,46), crd, type='GreatCircle'))

Robert
On Wed, Jan 27, 2010 at 1:17 AM, Karl Ove Hufthammer <karl at huftis.org> wrote: