
Geographical objects and endonyms
bkg_geonames.RdGet geographic names including toponyms and endonyms. bkg_geonames
retrieves the geographical "objects" based on the digital landscape model
(DLM). These objects contain a set of metadata and a national name identifier
(NNID). These NNIDs can be used to join with the endonyms related to a
geographical object (bkg_endonyms).
These functions interface the wfs_gnde product of the BKG.
Usage
bkg_geonames(
...,
names = TRUE,
ags = FALSE,
dlm = FALSE,
status = FALSE,
bbox = NULL,
poly = NULL,
predicate = "intersects",
filter = NULL,
epsg = 3035,
properties = NULL,
max = NULL
)
bkg_endonyms(..., filter = NULL, properties = NULL, max = NULL)Arguments
- ...
Used to construct CQL filters. Dot arguments accept an R-like syntax that is converted to CQL queries internally. These queries basically consist of a property name on the left, an aribtrary vector on the right, and an operator that links both sides. If multiple queries are provided, they will be chained with
AND. The following operators and their respective equivalents in CQL and XML are supported:R CQL XML ===PropertyIsEqualTo!=<>PropertyIsNotEqualTo<<PropertyIsLessThan>>PropertyIsGreaterThan>=>=PropertyIsGreaterThanOrEqualTo<=<=PropertyIsLessThanOrEqualTo%LIKE%LIKEPropertyIsLike%ILIKE%ILIKE%in%INPropertyIsEqualToandOrTo construct more complex queries, you can use the
filterargument to pass CQL queries directly. Also note that you can switch between CQL and XML queries usingoptions(ffm_query_language = "xml"). See alsowfs_filter.- names
If
TRUE, includes endonyms of the geographical objects in the output usingbkg_endonyms. Technically, this can beFALSE, because the endpoint only returns meta data on geographical names by default. If this argument isTRUE, the output is merged with the endonym table requiring an additional request. Defaults toTRUE.- ags
If
TRUE, resolves AGS codes to geographical names usingbkg_ags. Note that setting this toTRUErequires an additional web request. Defaults toFALSE.- dlm
If
TRUE, adds the DLM identifier corresponding to the national name identifiers (NNID) of the output usingbkg_dlm. Note that setting this toTRUErequires an additional web request. Defaults toFALSE.- status
If
TRUE, adds the date of the objects last edit to the output. Note that setting this toTRUErequires an additional web request. Defaults toFALSE.- bbox
An sf geometry or a boundary box vector of the format
c(xmin, ymin, xmax, ymax). Used as a geometric filter to include only those geometries that relate tobboxaccording to the predicate specified inpredicate. If an sf geometry is provided, coordinates are automatically transformed to ESPG:25832 (the default CRS), otherwise they are expected to be in EPSG:25832.- poly
An sf geometry. Used as a geometric filter to include only those geometries that relate to
polyaccording to the predicate specified inpredicate. Coordinates are automatically transformed to ESPG:25832 (the default CRS).- predicate
A spatial predicate that is used to relate the output geometries with the object specified in
bboxorpoly. For example, ifpredicate = "within", andbboxis specified, returns only those geometries that lie withinbbox. Can be one of"equals","disjoint","intersects","touches","crosses","within","contains","overlaps","relate","dwithin", or"beyond". Defaults to"intersects".- filter
A character string containing a valid CQL or XML filter. This string is appended to the query constructed through
.... Use this argument to construct more complex filters. Defaults toNULL.- epsg
An EPSG code specifying a coordinate reference system of the output. If you're unsure what this means, try running
sf::st_crs(...)$epsgon a spatial object that you are working with. Defaults to 3035.- properties
Vector of columns to include in the output.
- max
Maximum number of results to return.
Value
A dataframe containing the following columns:
nnid: National name identifierlandesCode: Country identifier; 276 is Germany.beschreibung: Optional detailsgeoLaenge: Geographical longitudegeoBreite: Geographical latitudehoehe: Elevation above sea levelhoeheger: Computed elevation above sea levelgroesse: Undocumented, but I guess this relates to the suggested print size of the labelsewz: Number of inhabitantsewzger: Computed number of inhabitantsags: Official municipality key (Amtlicher Gemeindeschlüssel). Related to the ARS but shortened to omit position 6 to 9. Structured as follows:Position 1-2: Federal state
Position 3: Government region
Position 4-5: District
Position 6-8: Municipality
gemteil: Whether the place is part of a municipalityvirtuell: Whether the place is a real or virtual localityars: Territorial code (Amtlicher Regionalschlüssel). The ARS is stuctured hierarchically as follows:Position 1-2: Federal state
Position 3: Government region
Position 4-5: District
Position 6-9: Administrative association
Position 10-12: Municipality
If ags = TRUE, adds the output of bkg_ags. If
dlm = TRUE, adds a column dlm_id containing identifiers of
bkg_dlm.
bkg_endonyms contains the following columns:
name: Name of the geographical objectgeschlecht: If applicable, the grammatical gender of a geographical name
These are also included in the output of bkg_geonames if
names = TRUE.
Details
These functions make use of the GN-DE WFS, just like bkg_ags,
bkg_ars, and bkg_area_codes. The infrastructure
behind it is actually quite sophisticated and this function may not live
up to these standards. You can use bkg_feature_types and
bkg_wfs to manually explore the service's endpoints if
required.
Query language
While other WFS interfaces like bkg_admin allow querying
using CQL or XML, bkg_geonames and bkg_endonyms (using the
GNDE service) ONLY support XML. This has implications for the allowed
query filters (see wfs_filter).
Examples
# Plot geographical objects in Cologne
library(sf)
library(ggplot2)
cgn <- st_sfc(st_point(c(6.956944, 50.938056)), crs = 4326)
cgn <- st_buffer(st_transform(cgn, 3035), dist = 500)
cgn_names <- bkg_geonames(poly = cgn)
st_geometry(cgn_names) <- st_centroid(st_geometry(cgn_names))
cgn_names <- cgn_names[lengths(st_intersects(cgn_names, cgn)) > 0, ]
ggplot(cgn_names) + geom_sf_text(aes(label = name)) + theme_void()