Coder Social home page Coder Social logo

More WMS? about mapspain HOT 3 CLOSED

ropenspain avatar ropenspain commented on May 30, 2024
More WMS?

from mapspain.

Comments (3)

dieghernan avatar dieghernan commented on May 30, 2024

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)

Rplot

Hope that helps

from mapspain.

dieghernan avatar dieghernan commented on May 30, 2024

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)

image

Created on 2022-12-19 with reprex v2.0.2

from mapspain.

dieghernan avatar dieghernan commented on May 30, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.