I'm using a WMTS layer in QGIS. Everything works fine. Now I would like to get access to the images in R both using maptiles
and mapview
. I do not know the WMTS standard and consequently I hardly understand the layer capability metadata but I eventually built a valid url from that xml file. The code do download something but it is always in a somewhat random location. The XML capability file is here.
library(maptiles)
library(sf)
p = st_point(c(63500, 624900))
p = st_sfc(p)
p = st_set_crs(p, 32198)
p = st_transform(p, 4326)
bb = st_bbox(st_buffer(p, 300))
# Good
rgb = get_tiles(bb, provider = "Esri.WorldImagery")
library(terra)
plot(rgb)
mffp <- list(
src = 'Aerial photography',
q = 'https://servicesmatriciels.mern.gouv.qc.ca:443/erdas-iws/ogc/wmts/Inventaire_Ecoforestier/Inventaire_Ecoforestier/default/OGC:1.0:GlobalCRS84Pixel/{z}/{x}/{y}.jpg',
sub = NA,
cit = ''
)
# In the ocean (maybe)
rgb = get_tiles(bb, provider = mffp)
plot(rgb)
Notice that I'm keen to bypass maptile
and do the math myself to retrieve the tiles if necessary but at this stage I don't even know what to compute. Also I did not find yet how to add a provider in mapview
but if I can work with maptile
it's already good enough.
maptile
is expecting everything to be in Google Maps' Web Mercator... Have you tried the image URL for theGoogleMapsCompatibleExt2:epsg:3857
tile set?GoogleMapsCompatibleExt2:epsg:3857
butmaptile
is expecting lon/lat WGS84 (epsg:4326) so it does not works better in my tests. As I said I could do the math if I were able to figure out the proper inputs (bbox modulo 256px tiles + zoom resolution should be enough I guess) .