Skip to contents

Some PDOK layers link each feature to related features in another layer of the same dataset. In the BAG, for example, every verblijfsobject (unit of use) carries a pand.href column with the URL of the building it is part of, and every pand lists its units in verblijfsobject.href. pdok_read_href() follows such links: it reads every linked feature and attaches it to the row that links to it, so you get your own data with the linked layer's columns and geometry alongside, like a join.

Usage

pdok_read_href(
  x,
  column = NULL,
  keep = TRUE,
  crs = NULL,
  max_active = 4,
  rate = 10
)

Arguments

x

An sf object or data frame holding a link column (typically read with pdok_read()), or a character vector of feature URLs.

column

The link column of x: its name (e.g. "pand.href"), or just the layer it links to ("pand", resolved to "pand.href"). May be left out when x has a single link column or is a character vector.

keep

Which columns of x to return alongside the linked features: TRUE (the default) for all of them, a character vector of column names for a selection, or FALSE for none, which returns just the linked features, one row per distinct link. Ignored when x is a character vector.

crs

Optional output CRS as an EPSG code (e.g. 28992 for RD New). NULL keeps the source CRS.

max_active

Maximum number of requests in flight at the same time.

rate

Maximum average number of requests per second.

Value

An sf object. By default it has one row per link: the kept columns of x (its own geometry is dropped and the link column now holds a single URL per row), then the linked feature's columns, then the linked feature's geometry. A row of x with several links becomes several rows; a row without links is dropped, with a warning. Columns of the linked layer whose name also occurs in x get the layer's name as a prefix (pand.identificatie, pand.status) so nothing is overwritten.

With keep = FALSE, or a character vector as x, the result has one row per distinct link, with the link as the first column, href.

Details

This is the efficient way to get, say, the buildings behind a list of addresses or units: each link is fetched directly, so nothing else is downloaded. The link is the only key there is: a feature does not carry the linked feature's own id (a verblijfsobject has no building identificatie), and the id in the link is a server-internal one that cannot be filtered on. When you do have the ids of the target layer itself, a filter with pdok_where() (identificatie %in% ids) is the faster route, as it fetches hundreds of features per request.

Following links takes one request per distinct link. The requests are small and are sent with bounded concurrency and a rate limit (max_active, rate) so that a long list stays well within what PDOK can comfortably serve; a few thousand links take about a minute.

See also

pdok_read() to read a layer, whose result may carry link columns.

Examples

# \donttest{
# The units of use at one postal code, with the building each one is in
units <- pdok_read(
  "kadaster/bag", "verblijfsobject",
  filter = pdok_where(postcode == "3811MZ")
)
with_buildings <- pdok_read_href(units, "pand")
with_buildings[, c("identificatie", "pand.identificatie", "bouwjaar")]
#> Simple feature collection with 5 features and 3 fields
#> Geometry type: POLYGON
#> Dimension:     XY
#> Bounding box:  xmin: 5.378328 ymin: 52.15382 xmax: 5.379189 ymax: 52.15444
#> Geodetic CRS:  WGS 84
#>      identificatie pand.identificatie bouwjaar                       geometry
#> 1 0307010000550915   0307100000346608     2001 POLYGON ((5.378379 52.15418...
#> 2 0307010000550917   0307100000346608     2001 POLYGON ((5.378379 52.15418...
#> 3 0307010000596802   0307100000346608     2001 POLYGON ((5.378379 52.15418...
#> 4 0307010000606107   0307100000346608     2001 POLYGON ((5.378379 52.15418...
#> 5 0307010000445569   0307100000346608     2001 POLYGON ((5.378379 52.15418...

# Just the distinct buildings
buildings <- pdok_read_href(units, "pand", keep = FALSE)
nrow(buildings)
#> [1] 1
# }