Comments (3)
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
from mapspain.
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
from mapspain.
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
from mapspain.
Related Issues (20)
- New feature: function for displacing external objects located on Canary Islands
- Release mapSpain 0.9.0
- Tidy documentation
- Revisar traducciones en gallego, euskera y catalán HOT 1
- Release mapSpain 0.5.0
- Añadir secciones censales HOT 1
- Release mapSpain 0.6.0
- Release mapSpain 0.6.1
- Añadir mapas del INE
- Release mapSpain 0.6.2
- How to offset points when moveCAN is set to TRUE HOT 6
- Problem installing mapSpain in R version 4.2.1 (2022-06-23) HOT 2
- Update leaflet providers to v1.3.1
- Does Leaflet-providersESP work with mapview? HOT 2
- Release mapSpain 0.7.0
- URGENT! Failed CRAN Checks: 2023-02-13
- Release mapSpain 0.8.0
- Echo de menos 3 municipios en el resultado de esp_get_munic_siane HOT 1
- pkgcheck results - main HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mapspain.