[R-sig-Geo] Shortest distance between points within a polygon

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Mon Oct 13 19:12:06 CEST 2014


On Mon, Oct 13, 2014 at 12:12 PM, Roman Luštrik <roman.lustrik at gmail.com> wrote:
> One way would be to calculate the distance and see if the line connecting
> the dots intersects with the polygon edge. `rgeos` package would be the
> tool of trade for this.
>

 I can't see how that works...

 A solution would be to rasterise your polygon and use `gdistance` to
compute a cost-weighted minimum distance on the raster - you'd set the
cost on the transition surface outside your polygon to +Inf and inside
the polygon to +1, or maybe its zero cost inside the polygon and
anything finite outside.

The gdistance vignette has an example of travelling between places in
Europe where travel is restricted to the land mass only.

The precision of your raster will determine the precision of your
result, but finer rasters will take longer.

Barry



More information about the R-sig-Geo mailing list