我一直致力于绘制徒步旅行路线的GPX数据。我可以下载并提取所有的管线数据,但是当我将它们绘制为多段线时,它只绘制了一小段。我已经通过运行一个函数来确认该文件是完整的,该函数拆分GPX文件,创建一个经度和经度的数据框,并将它们绘制为标记或圆圈标记。这对于我正在处理的文件来说是非常慢的。
代码如下:
library(rgdal)
library(maps)
library(htmltools)
library(devtools)
library(leaflet)
library(sp)
library(htmlwidgets)
library(plotKML)
library(maptools)
library(XML)
url <- "http://hiking.waymarkedtrails.org/en/routebrowser/1225378/gpx"
download.file(url, destfile = "pct.gpx", method = "wininet")
pct <- readOGR("pct.gpx", layer = "tracks")
# Import list with shapefiles of the three states the PCT is crossing
mapStates <- map("state", fill = TRUE,
plot = FALSE,
region = c('california', 'oregon', 'washington:main'))
your.map <- leaflet(pct) %>%
# Add layer
addTiles(urlTemplate = "http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png") %>%
addPolylines(color="red", popup="PCT") %>%
addMarkers(-116.4697, 32.60758, popup = "Campo") %>%
addMarkers(-120.7816, 49.06465, popup = "Manning Park, Canada") %>%
addPolygons(data=mapStates, fillColor = heat.colors(3, alpha = NULL), stroke = FALSE) %>%
# Add legend
addLegend(position = 'topright', colors = "red", labels = "PCT", opacity = 0.4,
title = 'Legend')
your.map
这段代码起作用了,你会得到一张地图,正确地着色,标记在正确的位置。
但是,只打印了一小段直线。通过查看pct
对象,我可以看到GPX文件中有12行代码,但它似乎只绘制了一行代码。无论我下载哪个GPX文件,都是同样的问题。
发布于 2016-04-27 14:33:03
这可能与传单中的一个bug有关。已经在github上提交了一个问题,请参阅here。
在mapview中,我们已经修复了这个问题,并且MultiLines被正确绘制。请参阅问题对话here。
作为一个可重复的示例(取自mapview问题):
library(trajectories)
data(storms)
x = as(storms, "SpatialLinesDataFrame")
plot(x)
library(mapview)
mapview(x)
leaflet() %>% addTiles() %>% addPolylines(data = x)
或者,对于您的示例,简单地
your.map <- mapview(pct, map.types = "CartoDB.Positron")@map %>%
addMarkers(-116.4697, 32.60758, popup = "Campo") %>%
addMarkers(-120.7816, 49.06465, popup = "Manning Park, Canada") %>%
addPolygons(data=mapStates, fillColor = heat.colors(3, alpha = NULL), stroke = FALSE) %>%
# Add legend
addLegend(position = 'topright', colors = "red", labels = "PCT", opacity = 0.4,
title = 'Legend')
your.map
注意:此问题目前仅在可与devtools::install_github("environmentalinformatics-marburg/mapview", ref = "develop")
一起安装的mapview开发版本中修复
https://stackoverflow.com/questions/36876839
复制相似问题