Get shortest/fastest path between two points from SpatialLines(DataFrame)

by Squeezie   Last Updated August 14, 2019 08:22 AM - source

I have a large rivernetwork as a SpatialLines(DataFrame) and want to subset it so I get a SpatialLine with only the shortest/fastest path between two SpatialPoints(DataFrame) which propably need to be snapped onto the line first.

In the example Code, I want to get the closest line between the red dots, while moving on the lines. Also I want to move between the left red point and the right blue point, which needs to be snapped to the closest SpatialLine

x <- c(1,5,6,8)
y1 <- c(1,3,4,7)
y2 <- c(5,5,5,2)

L <- SpatialLines(list(Lines(Line(cbind(x,y1)), ID="a"),Lines(Line(cbind(x,y2)), ID="b")))
P <- SpatialPoints(data.frame(x=c(1,8),y=c(1,2)))
P_snap <- SpatialPoints(data.frame(x=c(8),y=c(1)))

Tags : gdal r line sp

Related Questions

Set default GDAL/OGR config options?

Updated September 05, 2017 21:22 PM

making use of code examples in this Q&A

Updated February 02, 2018 18:22 PM

How to convert CSV file in VRT

Updated July 17, 2015 13:09 PM

Error when using

Updated May 30, 2017 16:22 PM