I have to shapefiles 2 Simple feature collections in R (one for districts and one for regions) and I need to combine them into a single GeoJSON FeatureCollection in R with different property names (such that I can filter the data layers later in a MapBox map, see https://stackoverflow.com/a/74615216/10624798). For example, one layer might give the population per district and the other the population per region. This seems related to: How to make a GeometryCollection in GeoJSON with a single point + polygon?
This is what I have so far
library(sf)
library(dplyr)
library(sfheaders)
library(geojsonio)
path_to_data <- "Ghana_261"
sf_use_s2(FALSE)
districts <-
read_sf(path_to_data) %>%
select(DIST_NAME = Name, REGION = Pcode) %>%
st_make_valid() %>%
sf_remove_holes()
regions <-
districts %>%
group_by(REGION) %>%
summarise() %>%
sf_remove_holes()
plot(regions)
# how do I combine these into a single geojson?
districts_json <- geojson_json(districts)
regions_json <- geojson_json(regions)
Data can be downloaded here: https://drive.google.com/file/d/1fOzxnA_vaOJi97EVPAMlquegAaoCW2Ow/view?usp=sharing