Package 'kwb.geoportal'

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

Help Index


Find WFS services in the Geoportal catalogue

Description

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.

Usage

find_wfs(pattern = NULL, metadata = NULL, protocol = "OGC:WFS", ...)

Arguments

pattern

regular expression matched, case-insensitively, against the record title, its abstract and the link URL. NULL (default) returns every WFS link.

metadata

result of a previous read_metadata_all() call. Pass this to search repeatedly without downloading the catalogue again. If NULL (default) the catalogue is read.

protocol

link protocol to keep (default: "OGC:WFS"). Pass "OGC:WMS" to find map services instead, or NULL for all of them.

...

further arguments passed to read_metadata_all(), e.g. base_url.

Details

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.

Value

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.

Examples

## Not run: 
catalogue <- read_metadata_all()
find_wfs("kanalisation", metadata = catalogue)
find_wfs("alkis", metadata = catalogue)

## End(Not run)

List the feature types offered by a WFS service

Description

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.

Usage

list_wfs_layers(
  service,
  version = c("2.0.0", "1.1.0", "1.0.0"),
  host = "https://gdi.berlin.de/services/wfs"
)

Arguments

service

service name, see wfs_base_url(), or a full endpoint URL.

version

WFS version, one of "2.0.0" (default), "1.1.0", "1.0.0".

host

see wfs_base_url().

Value

tibble with columns typename, title, abstract, crs.

Examples

## Not run: 
list_wfs_layers("wsg")

## End(Not run)

Read GeoNetwork service metadata (one row per service)

Description

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().

Usage

read_metadata(path_xml)

Arguments

path_xml

Path or URL to the GeoNetwork XML document. This can be a local file (e.g. "geoportal_metadaten.xml") or a remote URL such as "https://gdi.berlin.de/geonetwork/srv/ger/q?...".

Details

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.

Value

A tibble with one row per metadata record and the columns:

geonet_uuid

UUID from ⁠<geonet:info><uuid>⁠ (character).

geonet_id

Internal GeoNetwork id from ⁠<geonet:info><id>⁠ (character).

title

Dataset/service title.

abstract

Dataset/service abstract/description.

serviceType

Service type, if present (e.g. WMS).

types

Semicolon-separated ⁠<type>⁠ elements.

source_logo

Logo path, if present.

links

List column; each element is a tibble with the parsed links.

Examples

## 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)

Read all GeoNetwork / Geoportal metadata in chunks

Description

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).

Usage

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
)

Arguments

base_url

Base GeoNetwork query URL without from and to parameters. Must return an XML with a ⁠<summary count="...">⁠ node. Defaults to the GDI Berlin service search.

chunk_size

Number of records per request. Default: 100.

Details

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.

Value

A tibble with one row per metadata record, identical in structure to the return value of read_metadata(), but for all pages.

See Also

read_metadata()

Examples

## Not run: 
all_md <- read_metadata_all()
nrow(all_md)

## End(Not run)

Read a WFS layer from the Berlin Geoportal

Description

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.

Usage

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
)

Arguments

service

service name, see wfs_base_url(), or a full endpoint URL.

layer

feature type to request. Either the fully qualified name (e.g. "wsg:wsg") or the bare layer name, in which case the service name is used as the namespace prefix. If NULL (default) the service is asked for its feature types via list_wfs_layers(); this only succeeds when the service offers exactly one.

srs

coordinate reference system of the response (default: "EPSG:25833", the ETRS89 / UTM 33N used by the Berlin services).

version

WFS version, one of "2.0.0" (default), "1.1.0", "1.0.0".

output_format

value of OUTPUTFORMAT (default: "application/json", i.e. GeoJSON). Pass NULL to let the server choose, which usually yields GML.

count

maximum number of features to return, or NULL (default) for all of them. Sent as COUNT for WFS 2.0.0 and as MAXFEATURES otherwise.

start_index

index of the first feature to return, or NULL (default). Together with count this allows paging through layers that exceed the server's response limit. WFS 2.0.0 only.

host

see wfs_base_url().

quiet

suppress the progress messages of sf::read_sf() and of this function (default: FALSE).

Details

The request is a plain GetFeature call against ⁠<host>/<service>?SERVICE=WFS&VERSION=...&REQUEST=GetFeature&TYPENAMES=...⁠, which is the form the Berlin endpoints answer.

Value

an sf data frame.

Examples

## 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)

Read a WFS layer (auto-detect from URL)

Description

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...⁠.

Usage

read_wfs_sf_auto(url, crs_target = 25833, bbox = NULL, quiet = FALSE)

Arguments

url

character(1). Full WFS URL (e.g. a GetCapabilities link).

crs_target

integer(1) or NULL. EPSG code to reproject the result to. Defaults to 25833 (ETRS89 / UTM zone 33N). Use NULL to keep native CRS.

bbox

numeric(4) or NULL. Optional bounding box (c(xmin, ymin, xmax, ymax)), passed to the GetFeature request.

quiet

logical(1). Suppress download messages (default: FALSE).

Value

An sf object with the requested WFS layer.

Examples

## 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)

Base URL of a Berlin Geoportal WFS service

Description

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.

Usage

wfs_base_url(service, host = "https://gdi.berlin.de/services/wfs")

Arguments

service

name of the service, i.e. the last path element of the WFS endpoint (e.g. "atkis", "wsg"). This is also the namespace prefix of the feature types offered by that service.

host

base path of the WFS endpoints (default: "https://gdi.berlin.de/services/wfs").

Value

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.

Examples

wfs_base_url("atkis")

Service name of a WFS endpoint URL

Description

Extracts the last path element of an endpoint URL, i.e. the name that read_wfs() and list_wfs_layers() expect.

Usage

wfs_service_name(url)

Arguments

url

endpoint URL, with or without query string.

Value

character vector of service names, NA where none could be found.

Examples

wfs_service_name("https://gdi.berlin.de/services/wfs/atkis?SERVICE=WFS")