小编Sus*_*san的帖子

使用gcIntermediate在R小册子/ Shiny中映射穿过日期行的最短飞行路径

我正在使用R-Leaflet创建澳大利亚机场及其国际目的地的地图.

这是我的示例数据:

df<-data.frame("Australian_Airport" = "Brisbane", 
           "International" =  c("Auckland", "Bandar Seri Begawan","Bangkok","Christchurch","Denpasar","Dunedin","Hamilton","Hong Kong","Honiara","Kuala Lumpur"),
           "Australian_lon" = c(153.117, 153.117,153.117,153.117,153.117,153.117, 153.117, 153.117, 153.117, 153.117),
           "Australian_lat" = c(-27.3842,-27.3842,-27.3842,-27.3842,-27.3842,-27.3842, -27.3842, -27.3842, -27.3842, -27.3842),
           "International_lon" = c(174.7633, 114.9398, 100.5018, 172.6362, 115.2126,-82.77177, -84.56134, 114.10950, 159.97290, 101.68685),
           "International_lat" = c(-36.848460, 4.903052, 13.756331, -43.532054,-8.670458,28.019740, 39.399501, 22.396428, -9.445638,  3.139003)
           )
Run Code Online (Sandbox Code Playgroud)

我认为使用gcIntermediate使用弯曲的飞行路径会很酷,所以我创建了一个SpatialLines对象:

library(rgeos)
library(geosphere)

p1<-as.matrix(df[,c(3,4)])

p2<-as.matrix(df[,c(5,6)])

df2 <-gcIntermediate(p1, p2, breakAtDateLine=F, 
                    n=100, 
                    addStartEnd=TRUE,
                    sp=T) 
Run Code Online (Sandbox Code Playgroud)

然后我用小册子和Shiny绘制它:

server <-function(input, output) {

airportmap<- leaflet() %>% addTiles() %>% 
    addCircleMarkers(df, lng = df$Australian_lon, lat = df$Australian_lat, 
    radius …
Run Code Online (Sandbox Code Playgroud)

r leaflet shiny geosphere

4
推荐指数
2
解决办法
654
查看次数

标签 统计

geosphere ×1

leaflet ×1

r ×1

shiny ×1