-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More WMS? #86
Comments
Hi @ajpelu Lets say we want to add https://www.ideandalucia.es/wms/ortofoto2016?request=GetCapabilities&service=WMS ("ortofotografia_2016_pancromatico") layer (search for queryable= to see the of the layers) as a static map in R. This is not the canonical way to do it, but you can "hijack" mapSpain internals to get what you need: library(mapSpain)
library(sf)
library(tidyverse)
# Get shape and project to 3857
granada <- esp_get_prov("Granada") %>%
st_transform(3857)
# Build static url from https://github.com/dieghernan/leaflet-providersESP/issues/4
# This comes from the Get Capabilities
q <- "https://www.ideandalucia.es/wms/ortofoto2016?"
opts <- list(
service = "WMS", # Common to all WMS
version = "1.1.1", # Common to all WMS
request = "GetMap", # Common to all WMS
format = "image/png", # Adapt the format
transparent = "false", # Depends of what you want to all WMS
layers = "ortofotografia_2016_pancromatico", # Specific of your WMS
SRS = "EPSG:3857", # Mostly this value, worth checking
width = 512,
height = 512,
bbox = "{bbox}" # This is needed for the internals
)
# Compose url
url <- paste0(q, paste0(names(opts), "=", values = opts, collapse = "&"))
url
# Hijack mapSpain internals
# Trick a df
df <- data.frame(
field = "url_static",
value = url
)
# Note that I use ::: instead of :: to get access to the internal functions
# All params needed
tiles <- mapSpain:::getwms(
x = granada,
provs = df,
cache_dir = "./test",
update_cache = FALSE,
res = 512,
verbose = FALSE,
transparent = TRUE,
options = list()
)
# Plot with tidyterra
library(tidyterra)
autoplot(tiles) +
geom_sf(data = granada, color = "red", fill = NA, linewidth = 1)
Hope that helps |
HI @ajpelu Now after #88 you can do this: library(mapSpain)
x <- esp_get_prov("Jaen")
my_wms <- list(
id = "IDEAndalucia",
q =
paste0(
"https://www.ideandalucia.es/wms/ortofoto2016?",
"request=GetMap&service=WMS&version=1.1.1",
"&format=image/png&srs=epsg:3857",
"&layers=ortofotografia_2016_pancromatico&styles="
)
)
gettile <- esp_getTiles(x, my_wms, verbose = TRUE)
#> Downloading from
#> https://www.ideandalucia.es/wms/ortofoto2016?request=GetMap&service=WMS&version=1.1.1&format=image/png&srs=epsg:3857&layers=ortofotografia_2016_pancromatico&styles=&bbox=-482401.098657409,4465301.63825908,-266009.634060958,4681693.10285553&width=512&height=512
#> to cache dir
#> dev/IDEAndalucia
library(ggplot2)
library(tidyterra)
#>
#> Attaching package: 'tidyterra'
#> The following object is masked from 'package:stats':
#>
#> filter
ggplot(x) +
geom_spatraster_rgb(data = gettile) +
geom_sf(fill = NA, color = "red", linewidth = 2)
Created on 2022-12-19 with reprex v2.0.2 |
Even easier now: library(mapSpain)
x <- esp_get_munic_siane(munic = "^Jaén$", epsg = 3857)
my_wms <- esp_make_provider(
id = "A_test",
q = "https://www.ideandalucia.es/wms/ortofoto2016?",
service = "WMS",
layers = "ortofotografia_2016_infrarrojo"
)
gettile <- esp_getTiles(x, my_wms, bbox_expand = 0.5)
tidyterra::autoplot(gettile) +
ggplot2::geom_sf(data = x, fill = NA, color = "white", linewidth = 3) Created on 2022-12-22 with reprex v2.0.2 |
Coming from dieghernan/leaflet-providersESP#4
The text was updated successfully, but these errors were encountered: