Skip to content

Commit

Permalink
[#107] added function geoshapesExport
Browse files Browse the repository at this point in the history
this function provides a provisory export of geo shapes from the folder data/geo.
  • Loading branch information
DavidSoSiZoch committed Dec 10, 2021
1 parent 5641a7f commit 4cac992
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sormas-stats-sitrep/sitrep-app/loading_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions sormas-stats-sitrep/sitrep-app/loading_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 ----

Expand Down
31 changes: 31 additions & 0 deletions sormas-stats-sitrep/sitrep-app/utils/geoshapesExport.R
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 4cac992

Please sign in to comment.