Skip to content
Prev 21825 / 29559 Next

Shortest distance between points within a polygon

I was thinking along the lines of this example from `gCrosses`. If
line crosses the shape, it returns TRUE. If not, you've got your
distance. I can't speak for the performance part, you better do some
field testing.

require(rgeos)

l1 = readWKT("LINESTRING(0 3,1 1,2 2,3 0)")
l2 = readWKT("LINESTRING(0 0.5,1 1,2 2,3 2.5)")
l3 = readWKT("LINESTRING(1 3,1.5 1,2.5 2)")

pt1 = readWKT("MULTIPOINT(1 1,3 0)")
pt2 = readWKT("MULTIPOINT(1 1,3 0,1 2)")

p1 = readWKT("POLYGON((0 0,0 2,1 3.5,3 3,4 1,3 0,0 0))")
p2 = readWKT("POLYGON((2 2,3 4,4 1,4 0,2 2))")


plot(p1,border='blue',col='blue');plot(l1,add=TRUE)
title(paste("Crosses:",gCrosses(p1,l1),
            "\nOverlaps:",gOverlaps(p1,l1)))

Cheers,
Roman


On Mon, Oct 13, 2014 at 7:12 PM, Barry Rowlingson
<b.rowlingson at lancaster.ac.uk> wrote: