This vignette provides some guidance to USAID/OHA Data Analysts on how to extract geospatial data from different sources
PEPFAR/ICPI GIS Cluster provides a global geospatial data set that define the boundaries of PEPFAR countries organizational units. This data set contains all country, SNU, PSNU and Community boundaries along with their respective unique identification id (uid) and have been used thematic mapping and other spatial analyses. Other external data sources such as Naturalearh and GADM have also been very helpful.
Below are different ways analysts could / should be using this package to extract PEPFAR geodata for their respective countries.
Current PEPFAR Geospatial data sets can be found under OHA/SI Google
Drive SI Folder
and in Spatial Files
sub-folder.
In order to take full advantage of all the OHA/SI R packages, it’s
recommended to setup the location of your data directories. These should
ideally be outside your github projects directory. One of the
directories should be dedicated to geospatial data and should be set
using
glamr::set_paths(folderpath_vector = "<my-geodata-folder>")
.
Below is an example. This assumes your R / Github projects folder is
under Documents
folder on your local computer and your
working off a R Project in a sub-folder. In this example, your
geospatial data folder will be a sibling of your R / Github projects
folder.
curr_path <- "C:/Users/<username>/Documents/projects/gisr" # Windows
#or
#curr_path <- "~/Documents/projects/gisr" # Mac or linux
geopath <- "../../Geodata"
glamr::set_paths(folderpath_vector = geopath)
# verify path
glamr::si_path(type = "path_vector")
The geospatial data path is now set. Download PEPFAR
VcPepfarPolygons.shp
file from the above mentioned Google
Drive to the newly set local folder.
Time to test some of the gisr
functions. Let
# this works for the perfect setup with the default parameters values
spdf_pepfar <- get_vcpolygons(folderpath = geopath)
# for custom use, you will need to specify the path and name of the file
spdf_pepfar <- get_vcpolygons(folderpath = "../myshapefiles", name = "pepfar.shp")
# Explore outputs
spdf_pepfar %>% glimpse()
spdf_pepfar
Now that the PEPFAR Boundaries shapefile can be accessed and read in R, how does one extract specific boundaries for their countries?
In order to extract country specific boundaries, you will need to provide the country name and the orgunit level. Below is an example for South Africa.
Extract country boundaries
cntry_lvl <- grabr::get_ouorglevel(
operatingunit = cntry,
country = cntry,
org_type = "country",
username = datim_user(),
password = datim_pwd()
)
# Country boundaries
spdf_cntry <- spdf_pepfar %>%
extract_boundaries(country = cntry,
level = cntry_lvl,
username = datim_user(),
password = datim_pwd())
spdf_cntry
Extract PSNU boundaries
psnu_lvl <- grabr::get_ouorglevel(
operatingunit = cntry,
country = cntry,
org_type = "prioritization",
username = datim_user(),
password = datim_pwd()
)
# psnu boundaries
spdf_psnu <- spdf_pepfar %>%
extract_boundaries(country = cntry,
level = cntry_lvl,
username = datim_user(),
password = datim_pwd())
spdf_psnu
Extract all country boundaries
PEPFAR Geospatial dataset have already been parsed out and can be downloaded to a local directory.
Contextual geospatial data sets can also be extracted from external
sources using get_admin0()
, get_admin1()
,
get_adm_boundaries()
Take a look at spdf_export()