I have two simulated linestrings, one that represents a satellite ground-track and the other representing a linear surface feature (e.g., a road or river). I am trying to calculate the minimum distance the two features.
From searching stack exchange, I have only found minimum distance methods for polygons to points, points to points, lines to points, etc. but cannot seem to find line to line examples.
My current code approach is as follows:
library(sf)
# Create 'coordinate' dataframes -----------------------------------------------
#Simulate satellite transect coordinates
x0 <- runif(1, 1,10)
y0 <- runif(1, 1,10)
x1 <- runif(1, 1,10)
y1 <- runif(1, 1,10)
#Simulate road coordinates
l_x0 <- runif(1, 1,10)
l_y0 <- runif(1, 1,10)
l_x1 <- runif(1, 1,10)
l_y1 <- runif(1, 1,10)
# Set up a dataframe for the satellite transect
transect.df <- data.frame(
'x' = c(x0, x1),
'y' = c(y0, y1)
)
# Set up a dataframe for the simulated road info
road.df <- data.frame(
'x' = c(l_x0, l_x1),
'y' = c(l_y0, l_y1)
)
# Create 'sf' objects -----------------------------------------------
road.sf <- st_sf(id = 'L01', st_sfc(st_linestring(as.matrix(road.df)))) #create a formal sf feature
st_crs(lead.sf) <- st_crs(4326) # assign crs
road.sf <- st_transform(road.sf, crs = 4326) # transform
transect.sf <- st_sf(id = 't01', st_sfc(st_linestring(as.matrix(transect.df)))) #create a formal sf feature
st_crs(transect.sf) <- st_crs(4326) # assign crs
transect.sf <- st_transform(transect.sf, crs = 4326) # transform