I have two sets of points (actually I have many hundreds of pairs of two sets but for example, here's one) that look like this...
What I want to do is create a linestring or multilinestring that, when drawn, looks loosely like this...
The data looks like
onecons<- st_read("https://raw.githubusercontent.com/deanm0000/SOexamples/e5591130b1d0e9c5c5fa8b6b5fc05b3958d13099/example.geojson")
mapdeck(style=mapdeck_style("light")) %>%
add_scatterplot(onecons, radius_min_pixels=5,
tooltip='nodename', fill_colour = "pos", layer_id = 'nodes')
I think I'm close.
I did
polys<-onecons %>% group_by(pos) %>% summarise() %>% st_convex_hull()
mapdeck(style=mapdeck_style("light")) %>%
add_polygon(st_as_sf(st_difference(st_geometry(polys[1,]), st_geometry(polys[2,]))), fill_opacity=.5) %>%
add_scatterplot(onecons, radius_min_pixels=5,
tooltip='nodeest', fill_colour = "pos", layer_id = 'nodes')
which gives me:
A couple issues, if I flip the row reference in st_difference
then what I get doesn't make sense ...
mapdeck(style=mapdeck_style("light")) %>%
add_polygon(st_as_sf(st_difference(st_geometry(polys[2,]), st_geometry(polys[1,]))), fill_opacity=.5) %>%
add_scatterplot(onecons, radius_min_pixels=5,
tooltip='nodeest', fill_colour = "pos", layer_id = 'nodes')
Aside from that, I want the line I generate to be in between the points, not on them. I can live with it if it does land on the points but I'd rather it be in between.
Lastly, I don't know how to get the relevant border of the polygon to represent my new line. I can use st_boundary
to get the full boundary but I don't know how to just get the part that is in between.