[R-sig-Geo] Adding great circle routes as polylines in Leaflet
Kent Johnson
kent3737 @ending from gm@il@com
Mon Sep 3 18:52:47 CEST 2018
>
> From: Dhiraj Khanna <dhirajkhanna using gmail.com>
> To: r-sig-geo using r-project.org
> Subject: [R-sig-Geo] Adding great circle routes as polylines in
> Leaflet
> Message-ID:
> <CANHhK31knXB+8ev2LEQWOa3y+ZaUgkJ5noAV=iX7Z14j_foqZw@
> mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> I am trying to add great circle routes between various regions in R.
>
> I would like to plot great circle routes between CommencingRegion to
> LoadingRegion and then from LoadingRegion to DischargeRegion for every row.
> Additionally, every row needs to be in a different color and the thickness
> needs to be proportional to AvgTCE. The last 6 variables in the data above
> are the coordinates in Lat Long for the commencing, loading and discharging
> regions respectively. I am quite clueless on how to go about achieving
> this. This is what I have tried and failed:
>
> leaflet() %>%
> addTiles() %>%
> for(i in 1:6){
> addPolylines(data=gcIntermediate(c(ByRoute$CLon[
> i],ByRoute$CLat[i]),c(ByRoute$LLon[i],ByRoute$CLat[i]),n=100,addStartEnd
> = T,sp=T))
> }
>
> Here is a (rather clunky) start:
library(leaflet)
library(geosphere)
library(dplyr)
d = byRoute %>%
rowwise() %>%
do(leg1=gcIntermediate(c(.$CLon, .$CLat), c(.$LLon, .$LLat), n=50,
addStartEnd=TRUE),
leg2=gcIntermediate(c(.$LLon, .$LLat), c(.$DLon, .$DLat), n=50,
addStartEnd=TRUE))
colors=palette()
map = leaflet() %>% addTiles()
for (i in seq_len(nrow(d)))
map = map %>% addPolylines(data=d$leg1[[i]], color=colors[i],
weight=byRoute$AvgTCE[i]/3000-5) %>%
addPolylines(data=d$leg2[[i]], color=colors[i],
weight=byRoute$AvgTCE[i]/3000-5)
map
You will have to split the great circles using something like
the plot_my_connection function here:
https://www.r-graph-gallery.com/how-to-draw-connecting-routes-on-map-with-r-and-great-circles/
Is this shipping data? Maybe great circles are not the correct route...
Kent
> Regards
> Dhiraj Khanna
> Mob:09873263331
[[alternative HTML version deleted]]
More information about the R-sig-Geo
mailing list