get_area_collection.RdGet a collection of areas defined by a level and nested within a collection of higher level area(s).
get_area_collection(areas, level = NULL, area_scope = NULL)This function recursively expands the area hierarchy to identify all areas in
area_level level which are nested within areas defined by area_scope.
If level = NULL areas are returned at the lowest level of the hierarchy.
An error is thrown if level is not reflected in the hierarchy.
If area_scope = NULL all areas at area_level level are returned. In this case
the recursion is shortcut and simply filters the hierarchy to the desired
level for efficiency, but it is equivalent to initialising the recursion
at the highest level of the hierarchy.
If area_scope is not null, a column area_scope is returned indicating the
area in which each returned area is nesteed. area_scope can accept a vector
of area_ids and they do not have to be
at the same level. If the level of an area in area_scope is higher than
area_level level, nothing is returned. An error is thrown if any area_scope
are not recognized.
TODO: Should be an example - where is demo_areas, demo_area_geom? data(demo_areas, demo_area_geom)
areas <- get_area_collection(demo_areas, level = 3, area_scope = c("MWI.1", "MWI.3.5")) areas %>% left_join(demo_area_geom %>% filter(type == "boundary")) %>% sf::st_as_sf() %>% ggplot() + geom_sf()