Get geotagged images from the Spanish Cadastre. This function is a wrapper of
mapSpain::esp_getTiles()
.
Usage
catr_wms_get_layer(
x,
srs,
what = "building",
styles = "default",
update_cache = FALSE,
cache_dir = NULL,
verbose = FALSE,
crop = FALSE,
options = NULL,
...
)
Arguments
- x
See Details. It could be:
A numeric vector of length 4 with the coordinates that defines the bounding box:
c(xmin, ymin, xmax, ymax)
A
sf/sfc
object, as provided by the sf package.
- srs
SRS/CRS to use on the query. To check the admitted values check catr_srs_values, specifically the
wfs_service
column. See Details.- what
Layer to be extracted. Possible values are
"building"
,"parcel"
,"zoning"
,"address"
. See Details.- styles
Style of the WMS layer. See Details.
- update_cache
A logical whether to update cache. Default is
FALSE
. When set toTRUE
it would force a fresh download of the source file.- cache_dir
A path to a cache directory. On missing value the function would store the cached files on a temporary dir (See
base::tempdir()
).- verbose
Logical, displays information. Useful for debugging, default is
FALSE
.- crop
TRUE
if results should be cropped to the specifiedx
extent,FALSE
otherwise. Ifx
is an sf object with onePOINT
, crop is set toFALSE
.- options
A named list containing additional options to pass to the query.
- ...
Arguments passed on to
mapSpain::esp_getTiles
res
Resolution (in pixels) of the final tile. Only valid for WMS.
bbox_expand
A numeric value that indicates the expansion percentage of the bounding box of
x
.transparent
Logical. Provides transparent background, if supported. Depends on the selected provider on
type
.mask
TRUE
if the result should be masked tox
.
Value
A SpatRaster
is returned, with 3 (RGB) or 4 (RGBA) layers. See
terra::rast()
.
Details
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 is performed using EPSG:3857 (Web Mercator)
and the tile is projected back to the SRS of x
. In
case that the tile looks deformed, try either providing x
or specify the
SRS of the requested tile via the srs
parameter, that ideally would need
to match the SRS of x
. See Examples.
Layers
The parameter what
defines the layer to be extracted. The equivalence with
the
API Docs
equivalence is:
"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 provide different styles on each layer (what
parameter).
Some of the styles available are:
"parcel": styles :
"BoundariesOnly"
,"ReferencePointOnly"
,"ELFCadastre"
."zoning": styles :
"BoundariesOnly"
,"ELFCadastre"
."building" and "buildingpart":
"ELFCadastre"
"address":
"Number.ELFCadastre"
"admboundary" y "admunit":
"ELFCadastre"
Check the API Docs for more information.
See also
mapSpain::esp_getTiles()
, tidyterra::geom_spatraster_rgb()
,
terra::plotRGB()
.
INSPIRE API functions:
catr_atom_get_address_db_all()
,
catr_atom_get_address()
,
catr_atom_get_buildings_db_all()
,
catr_atom_get_buildings()
,
catr_atom_get_parcels_db_all()
,
catr_atom_get_parcels()
,
catr_wfs_get_address_bbox()
,
catr_wfs_get_buildings_bbox()
,
catr_wfs_get_parcels_bbox()
Other spatial:
catr_atom_get_address()
,
catr_atom_get_buildings()
,
catr_atom_get_parcels()
,
catr_wfs_get_address_bbox()
,
catr_wfs_get_buildings_bbox()
,
catr_wfs_get_parcels_bbox()
Examples
# \donttest{
# With a bbox
pict <- catr_wms_get_layer(c(222500, 4019500, 223700, 4020700),
srs = 25830,
what = "parcel"
)
#> Warning: downloaded length 0 != reported length 498
#> Warning: cannot open URL 'https://ovc.catastro.meh.es/cartografia/INSPIRE/spadgcwms.aspx?service=WMS&version=1.1.0&request=GetMap&format=image/png&transparent=true&layers=CP.CadastralParcel&srs=EPSG:25830&width=512&height=512&bbox=222470,4019470,223730,4020730&styles=default': HTTP status was '403 Forbidden'
#> Error in download.file(url = q, destfile = filename, mode = "wb", quiet = !verbose): cannot open URL 'https://ovc.catastro.meh.es/cartografia/INSPIRE/spadgcwms.aspx?service=WMS&version=1.1.0&request=GetMap&format=image/png&transparent=true&layers=CP.CadastralParcel&srs=EPSG:25830&width=512&height=512&bbox=222470,4019470,223730,4020730&styles=default'
library(mapSpain)
library(ggplot2)
library(tidyterra)
#>
#> Attaching package: 'tidyterra'
#> The following object is masked from 'package:stats':
#>
#> filter
ggplot() +
geom_spatraster_rgb(data = pict)
#> Error in geom_spatraster_rgb(data = pict): object 'pict' not found
# With a spatial object
parcels <- catr_wfs_get_parcels_neigh_parcel("3662303TF3136B", srs = 25830)
#> Warning: downloaded length 0 != reported length 498
#> Warning: cannot open URL 'https://ovc.catastro.meh.es/INSPIRE/wfsCP.aspx?service=wfs&version=2.0.0&request=getfeature&StoredQuerie_id=GetNeighbourParcel&refcat=3662303TF3136B&SRSNAME=EPSG::25830': HTTP status was '403 Forbidden'
#> Warning: downloaded length 0 != reported length 498
#> Warning: cannot open URL 'https://ovc.catastro.meh.es/INSPIRE/wfsCP.aspx?service=wfs&version=2.0.0&request=getfeature&StoredQuerie_id=GetNeighbourParcel&refcat=3662303TF3136B&SRSNAME=EPSG::25830': HTTP status was '403 Forbidden'
#> Download failed
#>
#> url
#> https://ovc.catastro.meh.es/INSPIRE/wfsCP.aspx?service=wfs&version=2.0.0&request=getfeature&StoredQuerie_id=GetNeighbourParcel&refcat=3662303TF3136B&SRSNAME=EPSG::25830 not reachable.
#>
#> Please try with another options. If you think this is a bug please consider opening an issue
#> Error in catr_hlp_dwnload(api_entry, filename, cache_dir = tempdir(), verbose = verbose, update_cache = FALSE, cache = TRUE):
#> Execution halted
# Use styles
parcels_img <- catr_wms_get_layer(parcels,
what = "buildingpart",
srs = 25830, # As parcels object
bbox_expand = 0.3,
styles = "ELFCadastre"
)
#> Error in get_sf_from_bbox(x, srs): object 'parcels' not found
ggplot() +
geom_sf(data = parcels, fill = "blue", alpha = 0.5) +
geom_spatraster_rgb(data = parcels_img)
#> Error in fortify(data): object 'parcels' not found
# }