Retrieve georeferenced map images from the Spanish Cadastre WMS service.
This function wraps mapSpain::esp_get_tiles().
Usage
catr_wms_get_layer(
x,
srs = NULL,
what = c("building", "buildingpart", "parcel", "zoning", "address", "admboundary",
"admunit"),
styles = "default",
update_cache = FALSE,
cache_dir = NULL,
verbose = FALSE,
crop = FALSE,
options = NULL,
...
)Arguments
- x
Input defining the query area. See Bounding box. It can be:
A numeric vector of length 4 with the coordinates that define the bounding box:
c(xmin, ymin, xmax, ymax).An
sforsfcobject from sf.
- srs
SRS/CRS to use in the query. To see allowed values, use catr_srs_values, specifically the
wfs_servicecolumn. See Bounding box.- what
WMS layer to download. See Layers and styles.
- styles
Style to apply to the selected WMS layer. See Layers and styles.
- update_cache
Logical. Whether to refresh the cached file. Defaults to
FALSE.- cache_dir
Path to a cache directory. If
NULLorFALSE, the function stores cached files in a temporary directory. Seebase::tempdir().- verbose
Logical. If
TRUE, displays informational messages.- crop
Logical. If
TRUE, crop results to the specifiedxextent. Ifxis ansfobject with onePOINT,cropis set toFALSE. Seeterra::crop().- options
A named list containing additional options to pass to the query.
- ...
Arguments passed on to
mapSpain::esp_get_tilesresCharacter string or number. Only valid for WMS providers. Resolution (in pixels) of the final tile.
bbox_expandNumber. Expansion percentage of the bounding box of
x.transparentLogical. Whether to use a transparent background, if supported.
maskLogical.
TRUEto mask the result tox. Seeterra::mask().
Value
A SpatRaster with three RGB or four RGBA layers. See
terra::RGB().
Bounding box
When x is a numeric vector, make sure that the srs matches the
coordinate values. When x is a sf object, the value
srs is ignored.
The query uses EPSG:3857 (Web Mercator), then
transforms the tile back to the SRS of x. If the tile appears distorted,
provide a spatial object as x or set srs to the SRS of the requested
tile. See Examples.
Layers and styles
Layers
The what argument selects one of the following API layers:
"parcel":CP.CadastralParcel."zoning":CP.CadastralZoning."building":BU.Building."buildingpart":BU.BuildingPart."address":AD.Address."admboundary":AU.AdministrativeBoundary."admunit":AU.AdministrativeUnit.
Styles
The WMS service provides different styles for each layer (what argument).
Available styles include:
"parcel":"BoundariesOnly","ReferencePointOnly"and"ELFCadastre"."zoning":"BoundariesOnly"and"ELFCadastre"."building"and"buildingpart":"ELFCadastre"."address":"Number.ELFCadastre"."admboundary"and"admunit":"ELFCadastre".
See the API documentation for complete layer and style information.
See also
mapSpain::esp_get_tiles()downloads map tiles.terra::RGB()identifies RGB channels.terra::plotRGB()andtidyterra::geom_spatraster_rgb()plot RGB rasters.
Examples
# \donttest{
# With a bounding box
pict <- catr_wms_get_layer(
c(222500, 4019500, 223700, 4020700),
srs = 25830,
what = "parcel"
)
library(mapSpain)
library(ggplot2)
library(tidyterra)
#>
#> Attaching package: ‘tidyterra’
#> The following object is masked from ‘package:stats’:
#>
#> filter
ggplot() +
geom_spatraster_rgb(data = pict)
#> ! `data` has 4 layers. Selecting layers 1, 2, and 3.
# With a spatial object
parcels <- catr_wfs_get_parcels_neigh_parcel("3662303TF3136B", srs = 25830)
# Use styles
parcels_img <- catr_wms_get_layer(parcels,
what = "buildingpart",
srs = 25830, # Same as the parcels object
bbox_expand = 0.3,
styles = "ELFCadastre"
)
ggplot() +
geom_sf(data = parcels, fill = "blue", alpha = 0.5) +
geom_spatraster_rgb(data = parcels_img)
#> ! `data` has 4 layers. Selecting layers 1, 2, and 3.
# }
