I have two shapefiles of type LINESTRING.
One is a list of 9 lines between Object A and Object B.
The other is a list of 18 lines between Object B and Object C.
For linestrings that share the same Object B coordinates, I want to find the distance between the corresponding Object A coordinates and Object C coordinates.
For example;
Object B to Object C linestrings: LINESTRING(21 15, 40.5 10.5) LINESTRING(23 15,40.5 10.5)
Object B to Object A linestrings: LINESTRING(53 11, 40.5 10.5)
Then I would like to calculate the distance between the coordinates (21, 15) and (53,11) and calculate the distance between (23, 15) and (53,11)
To reproduce my LINESTRING shapefiles, you can run the following code:
Object B to Object A
ObjectBtoA <-structure(list(structure(c(53, 40.5, 11, 10.5), .Dim = c(2L,
2L), class = c("XY", "LINESTRING", "sfg")), structure(c(53, 41.5,
11, 10.5), .Dim = c(2L, 2L), class = c("XY", "LINESTRING", "sfg"
)), structure(c(53, 42.5, 11, 10.5), .Dim = c(2L, 2L), class = c("XY",
"LINESTRING", "sfg")), structure(c(53, 40.5, 11.5, 11.5), .Dim = c(2L,
2L), class = c("XY", "LINESTRING", "sfg")), structure(c(53, 41.5,
11.5, 11.5), .Dim = c(2L, 2L), class = c("XY", "LINESTRING",
"sfg")), structure(c(53, 42.5, 11.5, 11.5), .Dim = c(2L, 2L), class = c("XY",
"LINESTRING", "sfg")), structure(c(53, 40.5, 12.5, 12.5), .Dim = c(2L,
2L), class = c("XY", "LINESTRING", "sfg")), structure(c(53, 41.5,
12.5, 12.5), .Dim = c(2L, 2L), class = c("XY", "LINESTRING",
"sfg")), structure(c(53, 42.5, 12.5, 12.5), .Dim = c(2L, 2L), class = c("XY",
"LINESTRING", "sfg"))), n_empty = 0L, precision = 0, crs = structure(list(
input = "EPSG:4326", wkt = "GEOGCS[\"WGS 84\",\n DATUM[\"WGS_1984\",\n
SPHEROID[\"WGS 84\",6378137,298.257223563,\n AUTHORITY[\"EPSG\",\"7030\"]],\n
AUTHORITY[\"EPSG\",\"6326\"]],\n PRIMEM[\"Greenwich\",0,\n
AUTHORITY[\"EPSG\",\"8901\"]],\n UNIT[\"degree\",0.0174532925199433,\n
AUTHORITY[\"EPSG\",\"9122\"]],\n AUTHORITY[\"EPSG\",\"4326\"]]"), class = "crs"), class =
c("sfc_LINESTRING",
"sfc"), bbox = structure(c(xmin = 40.5, ymin = 10.5, xmax = 53,
ymax = 12.5), class = "bbox"))
Object B to Object C:
structure(list(structure(c(21, 40.5, 15, 10.5), .Dim = c(2L,
2L), class = c("XY", "LINESTRING", "sfg")), structure(c(21, 41.5,
15, 10.5), .Dim = c(2L, 2L), class = c("XY", "LINESTRING", "sfg"
)), structure(c(21, 42.5, 15, 10.5), .Dim = c(2L, 2L), class = c("XY",
"LINESTRING", "sfg")), structure(c(21, 40.5, 15, 11.5), .Dim = c(2L,
2L), class = c("XY", "LINESTRING", "sfg")), structure(c(21, 41.5,
15, 11.5), .Dim = c(2L, 2L), class = c("XY", "LINESTRING", "sfg"
)), structure(c(21, 42.5, 15, 11.5), .Dim = c(2L, 2L), class = c("XY", "LINESTRING",
"sfg")), structure(c(21, 40.5, 15, 12.5), .Dim = c(2L,
2L), class = c("XY", "LINESTRING", "sfg")), structure(c(21, 41.5,
15, 12.5), .Dim = c(2L, 2L), class = c("XY", "LINESTRING", "sfg"
)), structure(c(21, 42.5, 15, 12.5), .Dim = c(2L, 2L), class = c("XY",
"LINESTRING", "sfg")), structure(c(23, 40.5, 15, 10.5), .Dim = c(2L,
2L), class = c("XY", "LINESTRING", "sfg")), structure(c(23, 41.5,
15, 10.5), .Dim = c(2L, 2L), class = c("XY", "LINESTRING", "sfg"
)), structure(c(23, 42.5, 15, 10.5), .Dim = c(2L, 2L), class = c("XY",
"LINESTRING", "sfg")), structure(c(23, 40.5, 15, 11.5), .Dim = c(2L,
2L), class = c("XY", "LINESTRING", "sfg")), structure(c(23, 41.5,
15, 11.5), .Dim = c(2L, 2L), class = c("XY", "LINESTRING", "sfg"
)), structure(c(23, 42.5, 15, 11.5), .Dim = c(2L, 2L), class = c("XY",
"LINESTRING", "sfg")), structure(c(23, 40.5, 15, 12.5), .Dim = c(2L,
2L), class = c("XY", "LINESTRING", "sfg")), structure(c(23, 41.5,
15, 12.5), .Dim = c(2L, 2L), class = c("XY", "LINESTRING", "sfg"
)), structure(c(23, 42.5, 15, 12.5), .Dim = c(2L, 2L), class = c("XY",
"LINESTRING", "sfg"))), n_empty = 0L, precision = 0, crs = structure(list(
input = "EPSG:4326", wkt = "GEOGCS[\"WGS 84\",\n DATUM[\"WGS_1984\",\n
SPHEROID[\"WGS 84\",6378137,298.257223563,\n AUTHORITY[\"EPSG\",\"7030\"]],\n
AUTHORITY[\"EPSG\",\"6326\"]],\n PRIMEM[\"Greenwich\",0,\n
AUTHORITY[\"EPSG\",\"8901\"]],\n UNIT[\"degree\",0.0174532925199433,\n
AUTHORITY[\"EPSG\",\"9122\"]],\n AUTHORITY[\"EPSG\",\"4326\"]]"), class = "crs"), class =
c("sfc_LINESTRING",
"sfc"), bbox = structure(c(xmin = 21, ymin = 10.5, xmax = 42.5,
ymax = 15), class = "bbox"))