| Title: | R Package for Getting Spatial Data from Berlin Geoportal |
|---|---|
| Description: | R Package for getting spatial data from Berlin Geoportal (https://gdi.berlin.de/geonetwork/srv/ger/catalog.search#/search). |
| Authors: | Michael Rustler [aut, cre] (ORCID: <https://orcid.org/0000-0003-0647-7726>), AD4GD [fnd], Kompetenzzentrum Wasser Berlin gGmbH (KWB) [cph] |
| Maintainer: | Michael Rustler <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.0.0.9000 |
| Built: | 2026-10-11 10:27:36 UTC |
| Source: | https://github.com/KWB-R/kwb.geoportal |
Searches the GeoNetwork catalogue read by read_metadata_all() for records
that offer a download service, and returns one row per matching WFS link.
The service column of the result is what read_wfs() takes as its first
argument.
find_wfs(pattern = NULL, metadata = NULL, protocol = "OGC:WFS", ...)find_wfs(pattern = NULL, metadata = NULL, protocol = "OGC:WFS", ...)
pattern |
regular expression matched, case-insensitively, against the
record title, its abstract and the link URL. |
metadata |
result of a previous |
protocol |
link protocol to keep (default: |
... |
further arguments passed to |
This answers "which endpoint belongs to dataset X". It is a convenience for discovery: once the service name is known it should be written down in the calling code, so that fetching the data no longer depends on the catalogue being reachable.
tibble with columns title, service, link_url, link_desc,
link_protocol, geonet_uuid, sorted by title. Warns, and returns no
rows, when metadata holds no links at all or none of them uses
protocol – both of which are a different thing from pattern not
matching. The second warning names the protocols that are on offer.
## Not run: catalogue <- read_metadata_all() find_wfs("kanalisation", metadata = catalogue) find_wfs("alkis", metadata = catalogue) ## End(Not run)## Not run: catalogue <- read_metadata_all() find_wfs("kanalisation", metadata = catalogue) find_wfs("alkis", metadata = catalogue) ## End(Not run)
Reads the service's GetCapabilities document and returns one row per
feature type. Use this to find out which layer to pass to
read_wfs() – it is the authoritative source, unlike the catalogue,
which describes datasets rather than layers.
list_wfs_layers( service, version = c("2.0.0", "1.1.0", "1.0.0"), host = "https://gdi.berlin.de/services/wfs" )list_wfs_layers( service, version = c("2.0.0", "1.1.0", "1.0.0"), host = "https://gdi.berlin.de/services/wfs" )
service |
service name, see |
version |
WFS version, one of |
host |
see |
tibble with columns typename, title, abstract, crs.
## Not run: list_wfs_layers("wsg") ## End(Not run)## Not run: list_wfs_layers("wsg") ## End(Not run)
GeoNetwork encodes links as a single string separated by |, e.g.:
|Darstellungsdienst (WMS)|https://...|OGC:WMS|||.
This helper splits such a string into named columns.
parse_gn_link(x)parse_gn_link(x)
x |
Character string as found inside a |
The fields are ordered name, description, URL, protocol, MIME type, order. The URL is the one field that can be recognised on its own, so it is located first and the remaining fields are read relative to it; that keeps the columns aligned for a catalogue that pads the record differently.
Note that a parsed link_protocol is only as good as the catalogue: the GDI
Berlin records repeat the description there instead of naming a protocol,
so filtering on it needs gn_link_protocol().
A one-row tibble with columns:
link_name
link_desc
link_url
link_protocol
link_mime
link_order
parse_gn_link("|Darstellungsdienst (WMS)|https://example.org/wms?|OGC:WMS|||")parse_gn_link("|Darstellungsdienst (WMS)|https://example.org/wms?|OGC:WMS|||")
This function reads a GeoNetwork XML search response (as delivered by
https://gdi.berlin.de/geonetwork/srv/ger/q?...) and converts it into a
tidy tibble with one row per metadata record.
All <link> elements of a record are kept together in a list column
called links, where each entry is itself a tibble created by
parse_gn_link().
read_metadata(path_xml)read_metadata(path_xml)
path_xml |
Path or URL to the GeoNetwork XML document. This can be a
local file (e.g. |
This structure is convenient when you want to keep the dataset-level information (title, abstract, uuid, ...) together, but still be able to inspect or unnest all service/download/view links later on.
The function assumes a GeoNetwork-style XML with <metadata> elements and
the namespace geonet: available for the info block.
It is tailored to the GDI Berlin instance but should work for other similar
GeoNetwork responses that use the same link encoding (| separated).
If a record has no <link> elements, the links column will contain
a single-row tibble with all NA values. This preserves the 1:1 alignment
between records and rows.
A tibble with one row per metadata record and the columns:
UUID from <geonet:info><uuid> (character).
Internal GeoNetwork id from <geonet:info><id> (character).
Dataset/service title.
Dataset/service abstract/description.
Service type, if present (e.g. WMS).
Semicolon-separated <type> elements.
Logo path, if present.
List column; each element is a tibble with the parsed links.
## Not run: df <- read_geonetwork_services( "https://gdi.berlin.de/geonetwork/srv/ger/q?facet.q=type/service&resultType=details&sortBy=changeDate&from=1&to=100&fast=index" ) dplyr::glimpse(df) df$links[[1]] ## End(Not run)## Not run: df <- read_geonetwork_services( "https://gdi.berlin.de/geonetwork/srv/ger/q?facet.q=type/service&resultType=details&sortBy=changeDate&from=1&to=100&fast=index" ) dplyr::glimpse(df) df$links[[1]] ## End(Not run)
This function uses read_metadata() repeatedly to fetch all available
metadata records from a GeoNetwork endpoint that supports from / to
pagination (like the GDI Berlin instance).
read_metadata_all( base_url = "https://gdi.berlin.de/geonetwork/srv/ger/q?facet.q=type/service&resultType=details&sortBy=changeDate&fast=index", chunk_size = 100 )read_metadata_all( base_url = "https://gdi.berlin.de/geonetwork/srv/ger/q?facet.q=type/service&resultType=details&sortBy=changeDate&fast=index", chunk_size = 100 )
base_url |
Base GeoNetwork query URL without |
chunk_size |
Number of records per request. Default: 100. |
It first downloads the initial XML, reads the <summary count="...">
attribute to know how many records exist, then iterates in chunks
(default: 100) until all records are read.
A tibble with one row per metadata record, identical in structure
to the return value of read_metadata(), but for all pages.
## Not run: all_md <- read_metadata_all() nrow(all_md) ## End(Not run)## Not run: all_md <- read_metadata_all() nrow(all_md) ## End(Not run)
Downloads one feature type of a WFS service and reads it into an sf
object. This is the data counterpart to read_metadata(), which only
describes where a dataset lives.
read_wfs( service, layer = NULL, srs = "EPSG:25833", version = c("2.0.0", "1.1.0", "1.0.0"), output_format = "application/json", count = NULL, start_index = NULL, host = "https://gdi.berlin.de/services/wfs", quiet = FALSE )read_wfs( service, layer = NULL, srs = "EPSG:25833", version = c("2.0.0", "1.1.0", "1.0.0"), output_format = "application/json", count = NULL, start_index = NULL, host = "https://gdi.berlin.de/services/wfs", quiet = FALSE )
service |
service name, see |
layer |
feature type to request. Either the fully qualified name
(e.g. |
srs |
coordinate reference system of the response (default:
|
version |
WFS version, one of |
output_format |
value of |
count |
maximum number of features to return, or |
start_index |
index of the first feature to return, or |
host |
see |
quiet |
suppress the progress messages of |
The request is a plain GetFeature call against
<host>/<service>?SERVICE=WFS&VERSION=...&REQUEST=GetFeature&TYPENAMES=...,
which is the form the Berlin endpoints answer.
an sf data frame.
## Not run: # Water protection zones, the layer the model's dashboard uses wsg <- read_wfs("wsg", "wsg") # ATKIS river centrelines rivers <- read_wfs("atkis", "b17_ax_gewaesserstationierungsachse_l") ## End(Not run)## Not run: # Water protection zones, the layer the model's dashboard uses wsg <- read_wfs("wsg", "wsg") # ATKIS river centrelines rivers <- read_wfs("atkis", "b17_ax_gewaesserstationierungsachse_l") ## End(Not run)
Simplified helper to read a single WFS layer into R using sf.
The function automatically extracts the layer ID from the WFS URL,
assuming the URL pattern .../wfs/<layer>?REQUEST=GetCapabilities....
read_wfs_sf_auto(url, crs_target = 25833, bbox = NULL, quiet = FALSE)read_wfs_sf_auto(url, crs_target = 25833, bbox = NULL, quiet = FALSE)
url |
character(1). Full WFS URL (e.g. a GetCapabilities link). |
crs_target |
integer(1) or |
bbox |
numeric(4) or |
quiet |
logical(1). Suppress download messages (default: |
An sf object with the requested WFS layer.
## Not run: # Read Berlin ALKIS Bezirke directly from GetCapabilities URL bezirke <- read_wfs_sf_auto( "https://gdi.berlin.de/services/wfs/alkis_bezirke?REQUEST=GetCapabilities&SERVICE=wfs" ) plot(bezirke["bezirk"]) ## End(Not run)## Not run: # Read Berlin ALKIS Bezirke directly from GetCapabilities URL bezirke <- read_wfs_sf_auto( "https://gdi.berlin.de/services/wfs/alkis_bezirke?REQUEST=GetCapabilities&SERVICE=wfs" ) plot(bezirke["bezirk"]) ## End(Not run)
The Berlin spatial data infrastructure publishes one WFS endpoint per
dataset under a common path, e.g. https://gdi.berlin.de/services/wfs/atkis
for the ATKIS layers. This helper only composes that URL; it does not
contact the server.
wfs_base_url(service, host = "https://gdi.berlin.de/services/wfs")wfs_base_url(service, host = "https://gdi.berlin.de/services/wfs")
service |
name of the service, i.e. the last path element of the WFS
endpoint (e.g. |
host |
base path of the WFS endpoints (default:
|
character of length one, the service URL without query string.
Signals an error when service is not a single path element, because the
resulting URL would otherwise be handed to xml2::read_xml(), which parses
any string containing < or > as literal XML rather than fetching it.
wfs_base_url("atkis")wfs_base_url("atkis")
Extracts the last path element of an endpoint URL, i.e. the name that
read_wfs() and list_wfs_layers() expect.
wfs_service_name(url)wfs_service_name(url)
url |
endpoint URL, with or without query string. |
character vector of service names, NA where none could be found.
wfs_service_name("https://gdi.berlin.de/services/wfs/atkis?SERVICE=WFS")wfs_service_name("https://gdi.berlin.de/services/wfs/atkis?SERVICE=WFS")