如何将 WMTS 读入 R Leaflet?

问题描述 投票:0回答:1

我想将 WMTS 加载到 R Leaflet 中。

我已经尝试了文件路径的多种变体,还尝试了“addWMSTiles()”,但到目前为止,没有任何内容加载到 Leaflet 地图中。我可以通过调整文件路径并使用“addWMSTiles”将数据作为 WMS 加载,但文件加载速度太慢,无法实现有效的网络映射。

library(sf)
library(leaflet)

# Define the WMTS URL
wmts_url_template <- "https://geo.spatialhub.scot/geoserver/ext_rpth/gwc/service/wmts/rest?authkey=b85aa063-d598-4582-8e45-e7e6048718fc/pub_rpth/default/EPSG:3857/{TileMatrix}/{TileRow}/{TileCol}?format=image/png"

# Create a basic leaflet map
map <- leaflet() %>%
    addTiles() %>%
    addTiles(
       urlTemplate = wmts_url_template,  # Add the WMTS layer
       options = tileOptions(opacity = 0.7)  # Adjust opacity
       ) %>%
    setView(lng = -3.5, lat = 55.5, zoom = 6)  # Set the initial view

# View the map
map

# alternative url I tried: "https://geo.spatialhub.scot/geoserver/ext_rpth/gwc/service/wmts?SERVICE=WMTS&VERSION=1.0.0&REQUEST=GetTile&LAYER=pub_rpth&STYLE=generic_blue&TILEMATRIXSET=EPSG:3857&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&FORMAT=image/png&authkey=b85aa063-d598-4582-8e45-e7e6048718fc" 
r leaflet r-leaflet
1个回答
0
投票

我找到了读取此数据的解决方案是来自 geoserver 的 WMTS:

library(leaflet)
library(dplyr)

leaflet() %>%
# Set initial map view
setView(lng = -4, lat = 57, zoom = 7) %>%
# Add WMS Tiles as an overlay group
addWMSTiles(
  baseUrl = "https://geo.spatialhub.scot/geoserver/ows?authkey=b85aa063-d598-4582-8e45-e7e6048718fc",
  layers = "ext_rpth:pub_rpth",
  options = WMSTileOptions(format = "image/png", transparent = TRUE),
  attribution = "XXX",
  group = "Paths"
)
© www.soinside.com 2019 - 2024. All rights reserved.