【发布时间】:2017-01-02 07:29:46
【问题描述】:
我有一个由一堆线条组成的非常简单的空间对象。我可以毫无问题地以不同的方式绘制它:QGIS、mapshaper.org。甚至标准的 R plot() 函数:
但是当我用leaflet() 绘制它时,一些片段神秘地消失了,留下了不连贯的线条:
下面是一个可重现的例子。注意:为了简单起见,我在这里使用 GeoJSON 源文件。我还尝试将线条保存为 ESRI shapefile,效果相同:使用 QGIS 或 plot() 等绘制数据正常,但使用 leaflet() 绘制数据不正确。
library(leaflet)
library(rgdal)
download.file("https://www.dropbox.com/s/nij2oa2rp7ijaaj/commuter_rail.geojson?dl=1",
method = "auto", mode = "wb", destfile = "commuter_rail.json")
commuterLines <- readOGR("commuter_rail.json",
"OGRGeoJSON")
# Straight R Plot - Looks good
plot(commuterLines)
# Plot using leaflet - Some lines are missing!
leaflet() %>% addPolylines(data = commuterLines)
更新:
这是作为闪亮应用程序运行的可重现示例,托管在 shinyapps.io,并显示了奇怪的传单行为:https://havb.shinyapps.io/leaflet_example/
【问题讨论】:
-
json 的下载对我不起作用。你试过
readLines("foo.json")吗? rstudio.github.io/leaflet/json.html -
@maRtin,哎呀,现在修复了。读取 json 不是问题,如果我读取 ESRI shapefile 格式的数据,我会得到完全相同(奇怪)的结果。为了方便起见,我只是在示例中使用了一个 json 文件。如果有用,下面是与 shapefile 相同的数据:dropbox.com/s/4yq7vh4w43q3suy/MBTA.zip?dl=1