[R-sig-Geo] Distance to (nearest) polygon

Robert J. Hijmans r.hijmans at gmail.com
Wed Jan 27 20:32:33 CET 2010


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:
> On Tue, 26 Jan 2010 16:27:23 +0100 (CET) Roger Bivand
> <Roger.Bivand at nhh.no> wrote:
>
>>> For example, I need the distance between points at sea to the nearest
>>> land area (as defined by for example the 'world' dataset).
>>
>> There are methods for point to line segment distances in spatstat.
>> Further, for projected (planar) coordinates, this could be added to
>> R-Forge rgeos; for geographical coordinates Boost ggl would be needed.
>
> Thanks. The 'nncross' function in 'spatstat' does essentially do what I
> need. Unfortunately, I work with geographical coordinates (spanning
> about 15 degrees of latitude), so the results are not perfect (using
> plain long/lat coordinates), but they will probably be an adequate
> approximation.
>
> BTW, for my application, I'm not interested in the distance per se, only
> in the points (e.g., boats) within a certain distance from the polygon
> (land). So I have also thought about a possible solution of using an
> expanded polygon, expanded in a certain number of kilometers outwards,
> and then using point-in-polygon (i.e., 'overlay') to find the points
> that are inside this new polygon. But I couldn't find a function to
> 'grow' a polygon in this way.
>
> --
> Karl Ove Hufthammer
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>



More information about the R-sig-Geo mailing list