I have a problem that is very similar to this SO post:
Geographic / geospatial distance between 2 lists of lat/lon points (coordinates)
Here is an edited example set of coordinates that illustrates my case:
require(tidyverse)
list1 <- data.frame(longitude = c(72, 74, 76, 78, 79, 82),
latitude = c(20.5, 19, 19.5, 20, 22, 21),
area = "A")
list2 <- data.frame(longitude = c(71, 73, 75, 77, 79, 78.5, 72),
latitude = c(21.5, 22, 20.5, 23, 23.5, 24, 24),
area = "B")
df <- bind_rows(list1, list2)
ggplot(data = df) +
geom_point(aes(x = longitude, y = latitude, color = area)) +
geom_line(data = list1, aes(x = longitude, y = latitude, color = area)) +
geom_line(data = list1[c(2,6),], aes(x = longitude, y = latitude, color = area)) +
geom_line(data = list1[c(1,4),], aes(x = longitude, y = latitude, color = area)) +
geom_line(data = list2[c(1,7),], aes(x = longitude, y = latitude, color = area)) +
geom_line(data = list2[c(7,6),], aes(x = longitude, y = latitude, color = area)) +
geom_line(data = list2[c(6,5),], aes(x = longitude, y = latitude, color = area)) +
geom_line(data = list2[c(5,3),], aes(x = longitude, y = latitude, color = area)) +
geom_line(data = list2[c(3,1),], aes(x = longitude, y = latitude, color = area))
So I need to calculate smallest distances between two lists of coordinate points. I have been able to make this work, but I have noticed that I need something more efficient - the data is just too large.
One possibility that I have entertained, is to form non-overlapping polygons of these areas and calculate the distance from one set of points to the neighboring polygon. Is there a way to form these polygons? Convex hulls is not an options since the areas are pretty ragged.
Another option could be to form a line that runs between the areas.
Edit: I added some lines in the figure in order to illustrate the polygons.