library(dplyr)
library(purrr)
library(sf)

DRC groud truth.

Forget about meta-data files. Everything is now derived from Moritz's shape files.

drc <- here::here("data/Geography/drc_moritz/shp",
                  "congo_angola.shp") %>%
    st_read() 

drc <- filter(drc, ISO == "COD") 

Area

drc_split <- split(drc, drc$NAME_2)

drc_areas <- purrr::map_dfr(drc_split, ~ st_union(.x) %>% st_area) %>%
    tidyr::gather(adm2, area) %>%
    filter(area > 0)

drc_population <- purrr::map_dfr(drc_split, ~ sum(.x$X_populatio)) %>%
    tidyr::gather(adm2, pop) %>%
    filter(pop > 0)

We have to get the centroids from meta-data file for now.

drc_centroids <- here::here("data/Geography/GravityModel/raw",
                             "adm2-fixed.txt") %>%
    readr::read_tsv(.) %>%
    filter(ADM0 == "Democratic Republic of the Congo")

And put them together.

drc_metadata <- left_join(drc_population, drc_areas)
drc_metadata <- left_join(drc_metadata,
                          drc_centroids,
                          by = c("adm2" = "ADM2"))
readr::write_csv(drc_metadata, path = here::here("data/Geography/GravityModel/processed",
                                                 "drc_metadata.csv"))


annecori/mRIIDSprocessData documentation built on May 29, 2019, 1:16 p.m.