A level can have several geometries (point or polygon). This function adds the geometry of the layer to the level.
Usage
add_geometry(gl, layer, layer_key, level_key)
# S3 method for geolevel
add_geometry(gl, layer = NULL, layer_key = NULL, level_key = NULL)
Arguments
- gl
A
geolevel
object.- layer
A
sf
object.- layer_key
A vector of string.
- level_key
A vector of string.
Details
The association of the geometry to the existing instances is done through join using the level and layer keys.
If none is indicated, by default the key defined in the level is considered.
See also
Other geolevel definition functions:
check_key()
,
complete_point_geometry()
,
coordinates_to_geometry()
,
geolevel()
,
get_empty_geometry_instances()
,
get_geometry()
Examples
layer_us_state <-
dplyr::inner_join(
get_level_data_geo(gd_us, "state"),
get_level_layer(gd_us, "state"),
by = c("statefp", "division", "region", "stusps", "name")
) |>
sf::st_as_sf()
us_state_point <-
coordinates_to_geometry(layer_us_state,
lon_lat = c("intptlon", "intptlat"))
state <-
geolevel(name = "state",
layer = layer_us_state,
key = "statefp",
snake_case = TRUE) |>
add_geometry(layer = us_state_point)