I have a set of begin and end coordinates that look like this:
begin.coord <- data.frame(lon=c(-85.76,-85.46,-85.89), lat=c(38.34,38.76,38.31))
end.coord <- data.frame(lon=c(-85.72,-85.42,-85.85), lat=c(38.38,38.76,38.32))
I am trying to create a set of 3 line segments by connecting each begin point to its corresponding end point. I would like the end product to be a SpatialLines
object so that I can use the it with over
function in the sp
package.
One could also use the
sf
package to build a list ofsfc
class and then convert it toSpatialLines
object:Extra/Optional:
Here's a way:
This makes a separate Lines object (each with a unique ID) for each pair, you otherwise might want a single object?
And just for fun, build as a spatstat psp object first and then coerce with methods in maptools: