渲染大型瓦片数据集

Rendering large tile dataset

我花了相当多的时间在 SO 上解决这个问题,但一直未能找到合适的答案。简而言之,我无法使用 R Shinyleaflet.

查看本地存储的地图图块

我用过gdal2tiles.py to create a nested directory of tiles from an original high-resolution .tif file projected in EPSG:27700。可以使用函数自动生成的 .html 文件查看平铺过程的输出(即 googlemaps.html、leaflet.html、openlayers.html;请参见下面的 link 到带有图块的 GitHub 存储库和 leaflet.html 供查看)。因此,我得出结论,gdal2tiles.py 正确生成了可以在浏览器中显示的图块。

尝试使用 leafletR Shiny 时出现问题。我已按照以下说明 and leaflet 指向我的本地磁贴,但 R Studio 的查看器或我的浏览器中没有显示任何内容。令人沮丧的是,当 运行 代码时,R 控制台没有打印任何错误。我正在使用的代码,基于我刚刚 linked 之前的 SO 答案,看起来像:

library(leaflet)
addResourcePath("mytiles", "C:/path/to/my/tiles/")

leaflet() %>% 
  addTiles(urlTemplate = "mytiles/{z}/{x}/{y}.png") %>% 
  addMouseCoordinates()

文件夹和文件已根据语法 {z}/{x}/{y} 正确命名,例如目录结构如下:path/to/my/files/6/30/42.png。我还将我的文件上传到 GitHub 并将存储库 URL 传递给 urlTemplate 但无济于事。如果对任何人有帮助,我正在使用的图块都可以找到here。就文件和文件夹的数量而言,回购协议相当庞大(输入栅格的分辨率为 25m,我需要大量的缩放级别),但大小不高。

我注意到——在 leaflet.html 中放大我的图块时——有多种灰色阴影。这很奇怪,因为输入 .tif 是二进制的;森林存在 (1) 或不存在(NoData 或 NA)。我附上了一张截图,想知道这是否是 Chrome 中的渲染问题,或者这是否导致图块在 Shiny 中不显示。截图可以查看here.

有人可以帮助我使用本地文件在 R Shiny 中显示我的图块吗?如果最好的解决方案是 GitHub 托管的磁贴,我会接受一个答案,但我更喜欢显示本地存储的文件。

我在 Github 上的 Github repo issues page. For anyone who may experience issues in the future, it turns out that the flag tms=TRUE is required in tileOptions. I thank Barret Schloerke for his help with this. His full (working) code is copied below and can be found here 包中找到了解决方案。

library(leaflet)
library(rgdal)
library(leaflet.extras)
library(mapview)

leaflet() %>%
  addMouseCoordinates() %>%

  # Set high zoom level as I have only created tiles at zoom level 6 for a quick example. If you can get this to display, it'll be tough to discern as it's quite zoomed out!

  # This should center the view somewhere over the UK where my tiles have been created  
  setView(0, 51.5135085, zoom = 6) %>%
  # Added toner provider tiles as the white background makes it easier to see my custom tiles
  addProviderTiles(group = "Toner", providers$Stamen.Toner) %>%
  addTiles(group="test", urlTemplate = "https://simon-tarr.github.io/tilestest/tiles/{z}/{x}/{y}.png",
           options = tileOptions(tms = TRUE, minZoom = 6, maxZoom = 6)) %>% 
  addLayersControl(
    overlayGroups = c("test"),
    options = layersControlOptions(collapsed = FALSE)

  )