A continuación, se muestra el proceso de réplica de ejecución de lectura de datos en RStudio, el código original se ubica en la siguiente url: https://inbo.github.io/tutorials/tutorials/spatial_wfs_services/., el propósito está replica fue socializar los códigos generados por (Thierry Onkelinx , Hans Van Calster , Floris Vanderhaeghe, 2021), para conocer el potencial Rstudio en procesos de lectura y uso de datos espaciales publicados en los formatos WMS Y WFS, a los estudiantes del curso de Geografía y Sistemas de información Geografía del programa de ingeniería en Topografía.
# Utilizando WMS con R
# cargamos las urls que tienen acceso de datos de WMS
wms_grb <- "https://geoservices.informatievlaanderen.be/raadpleegdiensten/GRB-basiskaart/wms"
wms_ortho <- "https://geoservices.informatievlaanderen.be/raadpleegdiensten/OMWRGBMRVL/wms"
wms_inbo <- "https://geoservices.informatievlaanderen.be/raadpleegdiensten/INBO/wms"
wms_hunting <- "https://geoservices.informatievlaanderen.be/raadpleegdiensten/Jacht/wms"
# Cargamos la libreria.
library(leaflet)
#Cargando imagene en formato png.
leaflet() %>%
setView(lng = 4.238449, lat = 50.731716, zoom = 15) %>%
addWMSTiles(
wms_grb,
layers = "GRB_BSK",
options = WMSTileOptions(format = "image/png", transparent = TRUE)
)
# Cargando imagenes de tipo ortofoto
leaflet() %>%
setView(lng = 4.238449, lat = 50.731716, zoom = 15) %>%
addWMSTiles(
wms_ortho,
layers = "Ortho",
options = WMSTileOptions(format = "image/png", transparent = TRUE)
)
# cargando datos de tipo PNveg.
leaflet() %>%
setView(lng = 4.238449, lat = 50.731716, zoom = 15) %>%
addWMSTiles(
wms_inbo,
layers = "PNVeg",
options = WMSTileOptions(format = "image/png", transparent = TRUE)
)
# cargando datos de tipo vector gogle maps
leaflet() %>%
setView(lng = 4.238449, lat = 50.731716, zoom = 15) %>%
addTiles(group = "OSM") %>%
addWMSTiles(
wms_hunting,
layers = "Jachtterr",
options = WMSTileOptions(format = "image/png", transparent = TRUE)
)
# agregando más de dos capas en una misma ventana.
leaflet() %>%
setView(lng = 4.238449, lat = 50.731716, zoom = 15) %>%
addTiles(group = "OSM") %>%
addWMSTiles(
wms_grb,
layers = "GRB_BSK",
options = WMSTileOptions(format = "image/png", transparent = TRUE),
group = "GRB"
) %>%
addWMSTiles(
wms_hunting,
layers = "Jachtterr",
options = WMSTileOptions(format = "image/png", transparent = TRUE),
group = "hunting<br>grounds"
) %>%
addLayersControl(
baseGroups = "OSM",
overlayGroups = c("GRB", "hunting<br>grounds","orto"),
options = layersControlOptions(collapsed = FALSE)
)
# Uso de datos de tipo wfs
# Para este caso sugiere que se active las librerias
library(sf)# libreria que permite leer dar vectoriales.
## Linking to GEOS 3.9.0, GDAL 3.2.1, PROJ 7.2.1
library(httr) # libreria generica para servicios web
library(tidyverse) # libreria que ayuda en la transformacion de los daotos
## -- Attaching packages --------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.3 v purrr 0.3.3
## v tibble 3.0.1 v dplyr 1.0.5
## v tidyr 1.1.0 v stringr 1.4.0
## v readr 1.3.1 v forcats 0.5.0
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(ows4R) # libreria que ayuda en el inferface de servicios web de OGC
## Loading required package: geometa
## Loading ISO 19139 XML schemas...
## Loading ISO 19115 codelists...
wfs_bwk <- "https://geoservices.informatievlaanderen.be/overdrachtdiensten/BWK/wfs"
# Generando la direccion standar
url <- parse_url(wfs_bwk)
url$query <- list(service = "wfs",
#version = "2.0.0", # facultative
request = "GetCapabilities"
)
request <- build_url(url)
request
## [1] "https://geoservices.informatievlaanderen.be/overdrachtdiensten/BWK/wfs?service=wfs&request=GetCapabilities"
bwk_client <- WFSClient$new(wfs_bwk,
serviceVersion = "2.0.0")
## Warning in CPL_crs_from_input(x): GDAL Message 1: +init=epsg:XXXX syntax is
## deprecated. It might return a CRS with a non-EPSG compliant axis order.
bwk_client
## <WFSClient>
## Inherits from: <OWSClient>
## Public:
## attrs: list
## capabilities: WFSCapabilities, OWSCapabilities, OGCAbstractObject, R6
## clone: function (deep = FALSE)
## defaults: list
## describeFeatureType: function (typeName)
## encode: function (addNS = TRUE, geometa_validate = TRUE, geometa_inspire = FALSE)
## ERROR: function (text)
## getCapabilities: function ()
## getClass: function ()
## getClassName: function ()
## getFeatures: function (typeName, ...)
## getFeatureTypes: function (pretty = FALSE)
## getPwd: function ()
## getToken: function ()
## getUrl: function ()
## getUser: function ()
## getVersion: function ()
## INFO: function (text)
## initialize: function (url, serviceVersion = NULL, user = NULL, pwd = NULL,
## logger: function (type, text)
## loggerType: NULL
## reloadCapabilities: function ()
## url: https://geoservices.informatievlaanderen.be/overdrachtdi ...
## verbose.debug: FALSE
## verbose.info: FALSE
## version: 2.0.0
## WARN: function (text)
## wrap: FALSE
## Private:
## pwd: NULL
## serviceName: WFS
## system_fields: verbose.info verbose.debug loggerType wrap attrs defaults
## token: NULL
## user: NULL
## xmlElement: NULL
## xmlNamespace: NULL
## xmlNodeToCharacter: function (x, ..., indent = "", tagSeparator = "\n")
bwk_client$getFeatureTypes(pretty = TRUE)
## name title
## 1 BWK:Bwkhab BWK 2 - BWK-zone en Natura 2000 Habitat
## 2 BWK:Bwkfauna BWK 2 - Faunistisch belangrijke gebieden
## 3 BWK:Hab3260 BWK 2 - Habitattype 3260
# otra forma de acceder a la información
bwk_client$getFeatureTypes() %>%
map_chr(function(x){x$getTitle()})
## [1] "BWK 2 - BWK-zone en Natura 2000 Habitat"
## [2] "BWK 2 - Faunistisch belangrijke gebieden"
## [3] "BWK 2 - Habitattype 3260"
# vemos el contenido de capbilites
bwk_client$getCapabilities()
## <WFSCapabilities>
## Inherits from: <OWSCapabilities>
## Public:
## attrs: list
## clone: function (deep = FALSE)
## defaults: list
## encode: function (addNS = TRUE, geometa_validate = TRUE, geometa_inspire = FALSE)
## ERROR: function (text)
## findFeatureTypeByName: function (expr, exact = TRUE)
## getClass: function ()
## getClassName: function ()
## getFeatureTypes: function (pretty = FALSE)
## getOperationsMetadata: function ()
## getOWSVersion: function ()
## getRequest: function ()
## getService: function ()
## getServiceIdentification: function ()
## getServiceProvider: function ()
## getServiceVersion: function ()
## getUrl: function ()
## INFO: function (text)
## initialize: function (url, version, logger = NULL)
## logger: function (type, text)
## loggerType: NULL
## verbose.debug: FALSE
## verbose.info: FALSE
## WARN: function (text)
## wrap: FALSE
## Private:
## featureTypes: list
## fetchFeatureTypes: function (xmlObj, version)
## operationsMetadata: OWSOperationsMetadata, R6
## owsVersion: 1.1
## request: OWSGetCapabilities, OWSRequest, OGCAbstractObject, R6
## service: WFS
## serviceIdentification: OWSServiceIdentification, R6
## serviceProvider: OWSServiceProvider, R6
## serviceVersion: 2.0.0
## system_fields: verbose.info verbose.debug loggerType wrap attrs defaults
## url: https://geoservices.informatievlaanderen.be/overdrachtdi ...
## xmlElement: NULL
## xmlNamespace: NULL
## xmlNodeToCharacter: function (x, ..., indent = "", tagSeparator = "\n")
# nos presenta los datos en el contenido
bwk_client$
getCapabilities()$
findFeatureTypeByName("BWK:Bwkhab")$
getDescription() %>%
map_chr(function(x){x$getName()})
## [1] "UIDN" "OIDN" "TAG" "EVAL" "EENH1"
## [6] "EENH2" "EENH3" "EENH4" "EENH5" "EENH6"
## [11] "EENH7" "EENH8" "V1" "V2" "V3"
## [16] "HERK" "INFO" "BWKLABEL" "HAB1" "PHAB1"
## [21] "HAB2" "PHAB2" "HAB3" "PHAB3" "HAB4"
## [26] "PHAB4" "HAB5" "PHAB5" "HERKHAB" "HERKPHAB"
## [31] "HABLEGENDE" "SHAPE"
# otra forma abreviada
bwk_client$
describeFeatureType(typeName = "BWK:Bwkhab") %>%
map_chr(function(x){x$getName()})
## [1] "UIDN" "OIDN" "TAG" "EVAL" "EENH1"
## [6] "EENH2" "EENH3" "EENH4" "EENH5" "EENH6"
## [11] "EENH7" "EENH8" "V1" "V2" "V3"
## [16] "HERK" "INFO" "BWKLABEL" "HAB1" "PHAB1"
## [21] "HAB2" "PHAB2" "HAB3" "PHAB3" "HAB4"
## [26] "PHAB4" "HAB5" "PHAB5" "HERKHAB" "HERKPHAB"
## [31] "HABLEGENDE" "SHAPE"
# Para mostrar los datos vectoriales
bwk_client$
getCapabilities()$
getOperationsMetadata()$
getOperations() %>%
map_chr(function(x){x$getName()})
## [1] "GetCapabilities" "DescribeFeatureType" "GetFeature"
## [4] "GetPropertyValue" "ListStoredQueries" "DescribeStoredQueries"
## [7] "CreateStoredQuery" "DropStoredQuery"
# para ver en que formatos es posible obtenerlo
bwk_client$
getCapabilities()$
getOperationsMetadata()$
getOperations() %>%
map(function(x){x$getParameters()}) %>%
pluck(3, "outputFormat")
## [1] "text/xml; subtype=gml/3.2"
## [2] "gml32"
## [3] "application/gml+xml; version=3.2"
## [4] "GML2"
## [5] "KML"
## [6] "SHAPE-ZIP"
## [7] "application/json"
## [8] "application/vnd.google-earth.kml xml"
## [9] "application/vnd.google-earth.kml+xml"
## [10] "csv"
## [11] "gml3"
## [12] "json"
## [13] "text/xml; subtype=gml/2.1.2"
## [14] "text/xml; subtype=gml/3.1.1"
# para ver a que zona corresponde
bwk_client$
getCapabilities()$
getFeatureTypes() %>%
map(function(x){x$getBoundingBox()})
## [[1]]
## min max
## x 2.525262 5.936009
## y 50.673762 51.505480
##
## [[2]]
## min max
## x 2.525262 5.936009
## y 50.673762 51.505480
##
## [[3]]
## min max
## x 2.525262 5.936009
## y 50.673762 51.505480
#Intentando leer datos vectoriales
wfs_regions <- "https://eservices.minfin.fgov.be/arcgis/services/R2C/Regions/MapServer/WFSServer"
regions_client <- WFSClient$new(wfs_regions,
serviceVersion = "2.0.0")
regions_client$getFeatureTypes(pretty = TRUE)
## name title
## 1 R2C_Regions:Regions Regions
url <- parse_url(wfs_regions)
url$query <- list(service = "wfs",
#version = "2.0.0", # optional
request = "GetFeature",
typename = "regions",
srsName = "EPSG:4326"
)
request <- build_url(url)
bel_regions <- read_sf(request) #Lambert2008
ggplot(bel_regions) +
geom_sf()