使用gcIntermediate在R传单/发光中的日期线上绘制最短的飞行路线 [英] Mapping the shortest flight path across the date line in R leaflet/Shiny, using gcIntermediate
问题描述
我正在使用R-Leaflet创建澳大利亚机场及其国际目的地的地图.
I'm creating a map of Australian airports and their international destinations using 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)
)
我认为通过gcIntermediate使用弯曲的飞行路径会很酷,所以我创建了一个SpatialLines对象:
I thought it would be cool to use curved flight paths using gcIntermediate, so I created a SpatialLines object:
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)
然后我使用传单和Shiny绘制它:
And then I plotted it using leaflet and Shiny:
server <-function(input, output) {
airportmap<- leaflet() %>% addTiles() %>%
addCircleMarkers(df, lng = df$Australian_lon, lat = df$Australian_lat,
radius = 2, label = paste(df$Australian_Airport, "Airport"))%>%
addPolylines(data = df2, weight = 1)
output$mymap <- renderLeaflet({airportmap}) # render the base map
}
ui<- navbarPage("International flight path statistics - top routes",
tabPanel("Interactive map",
leafletOutput('mymap', width="100%", height=900)
)
)
# Run the application
shinyApp(ui = ui, server = server)
它看起来像这样:
因此,如果路径越过日期线,则路径是不正确的.将breakAtDateLine更改为FALSE不能解决问题(该行消失,但路径仍然断开).在此阶段,我怀疑我可能需要使用其他映射系统或其他工具,但是如果有人提出建议,我将不胜感激.
So the paths are incorrect if they cross the date line. Changing breakAtDateLine to FALSE doesn't fix it (the line disappears but the path is still broken). At this stage, I suspect I may need to use a different mapping system or something but I'd be very grateful if anyone has some advice.
先谢谢了.
推荐答案
如果您对另一个映射库感兴趣,那么googleway
使用Google Maps,以我的经验,它更适合处理跨越日期线的行.
If you are interested in another mapping library, then googleway
uses Google Maps, which in my experience is better at handling lines that cross the date line.
注释
- 要使用Google Maps,您需要一个API密钥
- 当前仅支持
sf
个对象,不支持sp
- 这也将在闪亮时起作用;我只是在这里向您展示基本地图
- 我创作了
googleway
- To use Google Maps you need an API key
- Currently only
sf
objects are supported, notsp
- This will also work in shiny; I'm just showing you the basic map here
- I authored
googleway
library(sf)
library(googleway)
## convert the sp object to sf
sf <- sf::st_as_sf(df2)
set_key("your_api_key")
google_map() %>%
add_polylines(data = sf)
这篇关于使用gcIntermediate在R传单/发光中的日期线上绘制最短的飞行路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!