Closed mdsumner closed 7 years ago
Checkout feature/geodesic branch. It's kind of wonky at best. I also had to patch the original plugin to make it work. And it looks like it won't work with custom projections.
Do you still want it ?
Definitely if it doesn't cause problems, but happy to take your branch as an example just to learn too. Thanks! It's beautiful :)
I don't think it will cause any problems, I'll wait for a bit for the plugin author to henrythasler/Leaflet.Geodesic#22, but if he/she doesn't respond, I'll go ahead with my patched ver.
Also for now the restriction is to use either plain old data frame, or a single Polyline, as Leaflet doesn't support MultiPolylines. i.e. you can plot only one line (with as many stops as you want) per invocation. So for multipolylines, you'll have to break them up and call the function per line.
Gosh that's awesome! Thanks :)
Try this
colshorten <- function(x) lapply(strsplit(x, ""), function(a) paste(a[c(1, 2, 4, 6)], collapse = ""))
library(trip) ## for the walrus tracks
## coerce to multi-lines (necessarily dropping all the per-fix attributes)
## and transform to longlat
ll <- spTransform(as(walrus818, "SpatialLinesDataFrame"), "+init=epsg:4326")
addGeodesicPolylines( addPolylines(af, data = spTransform(ll, "+init=epsg:4326"), color = colshorten(viridis::viridis(nrow(ll))), group = "tripID"), c(-172.5, -161.8), c(66.8, 70.3), color = "black")
You can perhaps see that the shorter path along the great circle matters there if you are hopeful, but I'll find some better examples, it's much clearer for shearwaters flying between Antarctica and Alaska. :)
I have some leaflet q's which probably don't belong here:
Here's another example with a different kind of seal:
http://rpubs.com/cyclemumner/ellie_gc
Which, huh, only shows that the geodesic didn't survive the trip to Rpubs:
For your first code sample,
ll <- spTransform(as(walrus818, "SpatialLinesDataFrame"), "+init=epsg:4326")
addGeodesicPolylines( addPolylines(af, data = spTransform(ll, "+init=epsg:4326"), color = colshorten(viridis::viridis(nrow(ll))), group = "tripID"), c(-172.5, -161.8), c(66.8, 70.3), color = "black")
I'm a bit confused. you are calling addPolyLines inside addGeodesicPolylines. That doesn't seem right, perhaps you meant to call them right after each other like you did on the Rpubs page. Also why double spTransform to 4236. You can do it just once. Also the colshorten can be done more intuitively, but the current ver. works too. But you do need to convert your coords to 4326, that's a leaflet JS lib limitation.
I too noticed that geodesic lines didn't make it to Rpubs, and I'm not sure why, that'll take some debugging.
ur, sorry was just going too fast - I was working in a console when I wrote it so avoided the pipe operator, but it's just nesting function calls rather than piping them, which is the same right?
should be:
colshorten <- function(x) lapply(strsplit(x, ""), function(a) paste(a[c(1, 2, 4, 6)], collapse = ""))
library(trip) ## for the walrus tracks
## coerce to multi-lines (necessarily dropping all the per-fix attributes)
## and transform to longlat
ll <- spTransform(as(walrus818, "SpatialLinesDataFrame"), "+init=epsg:4326")
af <- addTiles(leaflet())
addGeodesicPolylines( addPolylines(af, data =ll, color = colshorten(viridis::viridis(nrow(ll))), group = "tripID"), c(-172.5, -161.8), c(66.8, 70.3), color = "black")
Alternatively:
colshorten <- function(x) lapply(strsplit(x, ""), function(a) paste(a[c(1, 2, 4, 6)], collapse = ""))
library(trip)
af <- addTiles(leaflet())
ll <- spTransform(as(walrus818, "SpatialLinesDataFrame"), "+init=epsg:4326")
af %>% addPolylines(data = ll, color = colshorten(viridis::viridis(nrow(ll))), group = "tripID") %>%
addGeodesicPolylines( lng = c(-172.5, -161.8), lat = c(66.8, 70.3), color = "black")
Again, sorry for being sloppy, got excited and moved too quickly
Lastly the Rpubs problem is because the plugin uses some funky unicode characters, which are butchered by the rpubs uploader. I'll fix that my substituting the unicodes to ASCII.
I yes my bad then. Pipes have spoiled me, I can't even recognize non-pipe code any more.
It does support custom projections. I think that makes it super useful coz you see those as straight lines.
I'll double check a few things and merge it in master soon.
This is causing the mess when uploaded to Rpubs rstudio/rmarkdown#881
This is great news!
Feature implemented in 6a1bd70. Demo rpubs.com/bhaskarvk/geodesic
This plugin provides curvature based on the Geodesic between points, including wrap at the longitude boundary:
https://github.com/henrythasler/Leaflet.Geodesic