Use an existing tibble as the basis for a spatial query
add_geometry_to_table.Rd
If you have a tibble such as those produced by lookup()
- that is, there is
a column of geographical ONS codes ending in 'cd' - simply use this table as
the basis for retrieving the relevant boundaries or centroids.
add_geometry_to_table()
will use the lefthand-most column ending with
"cd".
Usage
add_geometry_to_table(
tbl,
opts = boundr_options(),
geometry = c("boundaries", "centroids")
)
add_geometry(
tbl,
opts = boundr_options(),
geometry = c("boundaries", "centroids")
)
Arguments
- tbl
A tibble with a column containing ONS geographical codes.
- opts
Should be set with the
boundr_options()
function. See?boundr_options
for detail on what can be set by the user, and on the default values.- geometry
character. Two options: "boundaries" (the default) and "centroids". By default,
bounds()
will return area boundaries. Set this explicitly to "centroids" to get area centroids instead.
Value
If successful, will return the initial table with an additional geometry column added. Duplicate rows will be removed.
Examples
tibble::tibble(wd23cd = c("S13003001", "N08000520", "W05001522")) |>
add_geometry_to_table()
#> Simple feature collection with 3 features and 1 field
#> Geometry type: MULTIPOLYGON
#> Dimension: XY
#> Bounding box: xmin: -7.345709 ymin: 52.91026 xmax: -4.104477 ymax: 57.51088
#> Geodetic CRS: WGS 84
#> # A tibble: 3 × 2
#> wd23cd geometry
#> <chr> <MULTIPOLYGON [°]>
#> 1 N08000520 (((-7.327748 55.00978, -7.330063 55.00857, -7.332083 55.00825, -7.3…
#> 2 S13003001 (((-4.432355 57.49436, -4.435513 57.49461, -4.429433 57.4938, -4.43…
#> 3 W05001522 (((-4.265797 52.91221, -4.264972 52.91141, -4.263611 52.91087, -4.2…