From 4cac9926cc924d6985475e6c97aa82f6aa0e8e11 Mon Sep 17 00:00:00 2001 From: DavidSoSiZoch Date: Fri, 10 Dec 2021 11:12:04 +0100 Subject: [PATCH] [#107] added function geoshapesExport this function provides a provisory export of geo shapes from the folder data/geo. --- sormas-stats-sitrep/sitrep-app/loading_data.R | 2 +- .../sitrep-app/loading_functions.R | 1 + .../sitrep-app/utils/geoshapesExport.R | 31 +++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 sormas-stats-sitrep/sitrep-app/utils/geoshapesExport.R diff --git a/sormas-stats-sitrep/sitrep-app/loading_data.R b/sormas-stats-sitrep/sitrep-app/loading_data.R index 0a09204..efd809c 100644 --- a/sormas-stats-sitrep/sitrep-app/loading_data.R +++ b/sormas-stats-sitrep/sitrep-app/loading_data.R @@ -15,7 +15,7 @@ caseData = caseExportLineList(sormas_db = sormas_db, fromDate = fromDate, toDate populationData = populationExport(sormas_db = sormas_db) # Import shape files - +geoshapesData = geoshapesExport(sormas_db = sormas_db) # Disconnect from sormas_db ---- dbDisconnect(sormas_db) diff --git a/sormas-stats-sitrep/sitrep-app/loading_functions.R b/sormas-stats-sitrep/sitrep-app/loading_functions.R index d5ce7ff..20a58a3 100644 --- a/sormas-stats-sitrep/sitrep-app/loading_functions.R +++ b/sormas-stats-sitrep/sitrep-app/loading_functions.R @@ -6,6 +6,7 @@ # base::source(file.path("./utils", "function_name.R")) base::source("utils/caseExportLineList.R") base::source("utils/populationExport.R") +base::source("utils/geoshapesExport.R") ## Functions for data analysis ---- diff --git a/sormas-stats-sitrep/sitrep-app/utils/geoshapesExport.R b/sormas-stats-sitrep/sitrep-app/utils/geoshapesExport.R new file mode 100644 index 0000000..b27503e --- /dev/null +++ b/sormas-stats-sitrep/sitrep-app/utils/geoshapesExport.R @@ -0,0 +1,31 @@ +geoshapesExport <- function(sormas_db){ + # This function outputs a table containing geoshapes of each district. + + ## Provisory geo shapes export: + # Loading geoshapes from folder, not part of SORMAS data for now + # geo_shapes data needs to be placed in data/geo folder and table key needs + # to be placed in data/key folder. + # data source: https://gadm.org/download_country.html + + files_geo <- list.files('data/geo', full.names = TRUE) + + # Reading in geo_shapes data + geoshapes_data <- readRDS(files_geo) %>% + dplyr::select(NAME_2, geometry) %>% + dplyr::rename(district_name_geo = NAME_2) + + ## Merging geo data and sormas district names using a table key + + # Loading key table from folder + files_key <- list.files('data/key', full.names = TRUE) + + # Reading in key table + key <- readxl::read_xlsx(files_key) + + # Merging key and geo_shapes data + geoshapes_data <- key %>% + dplyr::left_join(., geoshapes_data, by = 'district_name_geo') # joining w/ the matching key + + #returning output table + return(geoshapes_data) +} \ No newline at end of file