riatelab / maptiles

Download, compose and display map tiles with R
97 stars 12 forks source link

plot_tiles doesn't show new tiles #18

Closed pietervreeburg closed 1 year ago

pietervreeburg commented 1 year ago

When I download a set of tiles using the maptiles package everything works fine the first time. When I download a variant of the same tileset the files in my cachefile get updated, but plot_tiles still uses the first set of tiles.

plot_tiles only shows the new files when physically remove the cached files and redownload the tileset variant or restart my R session.

Code to reproduce the issue below:

library(tidyverse)
library(sf)
library(httr)

zh_wfs <- "https://geodata.zuid-holland.nl/geoserver/economie/wfs?version=2.0.0"

url <- parse_url(zh_wfs)
url$query <- list(service = "WFS",
                  version = "2.0.0",
                  request = "GetFeature",
                  typename = "economie:BEDRIJVEN_TERREINEN",
                  outputFormat = "application/json")
request <- build_url(url)
request

bedr_terreinen <- st_read(request)
bedr_terreinen <- bedr_terreinen %>% 
  filter(terreinbeheerder == "SCHIEDAM")
bedr_terreinen <- st_transform(bedr_terreinen, 3857)
bedr_terreinen <- st_make_valid(bedr_terreinen)

library(maptiles)
nlmaps <- list(
  src = "nlmaps",
  q = "https://service.pdok.nl/brt/achtergrondkaart/wmts/v2_0/{s}/EPSG:3857/{z}/{x}/{y}.png",
  sub = "standaard",
  cit = "Kadaster")

bedr_tiles <- get_tiles(bedr_terreinen, 
                        nlmaps,
                        forceDownload = TRUE,
                        verbose = TRUE)
plot_tiles(bedr_tiles)

library(maptiles)
nlmaps <- list(
  src = "nlmaps",
  q = "https://service.pdok.nl/brt/achtergrondkaart/wmts/v2_0/{s}/EPSG:3857/{z}/{x}/{y}.png",
  sub = "grijs",
  cit = "Kadaster")

bedr_tiles <- get_tiles(bedr_terreinen, 
                        nlmaps,
                        forceDownload = TRUE,
                        verbose = TRUE)
plot_tiles(bedr_tiles)
rCarto commented 1 year ago

Hello @pietervreeburg , This happens because tiles are cached using a combination of the query params as filenames (nlmaps_13_4196_2709.png => src_zoom_xindex_yindex.extension). To solve your problem you just have to use a different "src" name for the second source.

library(maptiles)
nlmaps1 <- list(
  src = "nlmaps_standaard",
  q = "https://service.pdok.nl/brt/achtergrondkaart/wmts/v2_0/{s}/EPSG:3857/{z}/{x}/{y}.png",
  sub = "standaard",
  cit = "Kadaster")

bedr_tiles <- get_tiles(bedr_terreinen, 
                        nlmaps1,
                        forceDownload = TRUE,
                        verbose = TRUE)
plot_tiles(bedr_tiles)

nlmaps2 <- list(
  src = "nlmaps_grijs",
  q = "https://service.pdok.nl/brt/achtergrondkaart/wmts/v2_0/{s}/EPSG:3857/{z}/{x}/{y}.png",
  sub = "grijs",
  cit = "Kadaster")

bedr_tiles <- get_tiles(bedr_terreinen, 
                        nlmaps2,
                        forceDownload = TRUE,
                        verbose = TRUE)
plot_tiles(bedr_tiles)

I could add the "sub" value in the filenames of the cached tiles but for most tiles providers the sub value is not relevant information. They provide the same tiles on various subdomains (e.g. a, b, c) and maptiles uses these subdomains (randomly) to send distributed queries to the server.

pietervreeburg commented 1 year ago

Thanks for your reply. This indeed solved my problem. Happily making maps for my colleagues now.

Regards,

Pieter