Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ Suggests:
terra,
sf,
exactextractr,
arrow
arrow,
countrycode
Config/testthat/edition: 3
Imports:
dplyr,
Expand Down
5 changes: 5 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ export(gen_naturalearth_cover_share)
export(gen_ne_disputed_area_share)
export(gen_ruggedterrain_elevation_mean)
export(gen_shdi)
export(gen_side_excluded)
export(gen_side_included)
export(gen_side_irrelevant)
export(gen_speibase6_mean)
export(gen_traveltime_mean)
export(gen_traveltime_min)
Expand Down Expand Up @@ -92,13 +95,15 @@ export(read_ruggedterrain)
export(read_shdi)
export(read_shdi_csv)
export(read_shdi_shapefile)
export(read_side)
export(read_speibase)
export(read_traveltime)
export(read_ucdp_ged)
export(robust_transformation)
export(ruggedterrain_variable)
export(save_pgvariable)
export(shdi)
export(side)
export(speibaseN)
export(ucdp_ged)
export(ucdpged_distance_within_country)
Expand Down
19 changes: 18 additions & 1 deletion R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,21 @@
#' }
"pgchecksum"


#' SIDE-LEDA Match Table
#'
#' Preprocessed annual links between SIDE ethnic groups and their annual
#' political relevance categories derived from LEDA/EPR matching.
#'
#' This dataset is bundled with the package so the expensive LEDA matching
#' workflow does not have to run every time SIDE is aggregated to PRIO-GRID.
#'
#' @format ## `leda_matches`
#' A data frame with 5 columns:
#' \describe{
#' \item{iso3c}{Three-letter country code.}
#' \item{side_group}{SIDE ethnic group label.}
#' \item{year}{Calendar year.}
#' \item{link_year_source}{Whether the SIDE-EPR year match was observed or carried by the upstream workflow.}
#' \item{status3}{Collapsed EPR status category: included, excluded, or irrelevant.}
#' }
"leda_matches"
177 changes: 133 additions & 44 deletions R/data_cshapes.R

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions R/data_ghs_wup.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#'
#' @return A \code{SpatRaster} object with DEGURBA classification codes
#'
#' @param config A \code{pg_config} object. Defaults to \code{\link{pg_current_config}()}.
#'
#' @note
#' \itemize{
#' \item Files are automatically extracted from zip archives and cached locally
Expand Down Expand Up @@ -116,6 +118,7 @@ read_ghs_wup_degurba <- function(config = pg_current_config()){
#'
#' @param urban_definition Numeric vector of DEGURBA codes to classify as urban.
#' Valid codes are: 10, 11, 12, 13, 21, 22, 23, 30. See Details for code meanings.
#' @param config A \code{pg_config} object. Defaults to \code{\link{pg_current_config}()}.
#'
#' @details
#' The DEGURBA classification codes represent:
Expand Down Expand Up @@ -183,7 +186,7 @@ ghs_wup_degurba <- function(urban_definition, config = pg_current_config()){
r <- read_ghs_wup_degurba(config = config)

temporary_directory <- file.path(pg_rawfolder(), "tmp", tempdir() |> basename())
dir.create(temporary_directory)
dir.create(temporary_directory, recursive = TRUE)
tmp1 <- tempfile(pattern = "urban_classification", fileext = ".tif", tmpdir = temporary_directory)

r <- terra::classify(r, cl_mat, filename = tmp1)
Expand Down Expand Up @@ -427,7 +430,7 @@ gen_ghs_wup_degurba_urban <- function(config = pg_current_config()){
#' \insertRef{schiavinaGHSWUPDEGURBAR2025AGHSWUP2025}{priogrid}
#'
#' \insertRef{europeancommissionApplyingDegreeUrbanisation2021}{priogrid}
urban_extent <- function(lon, lat, measurement_date, urban_definition = c(21, 22, 23, 30), max_extent = 1000e3){
urban_extent <- function(lon, lat, measurement_date, urban_definition = c(21, 22, 23, 30), max_extent = 1000e3, config = pg_current_config()){
# lat <- 59.935320; lon <- 10.763063 Oslo
# lat <- 28.612738 lon <- 77.231487 New Delhi

Expand All @@ -452,6 +455,6 @@ urban_extent <- function(lon, lat, measurement_date, urban_definition = c(21, 22
urban_extent_raster <- terra::ifel(urban_patches == center_patch_id, 1, NA)
urban_extent_raster <- terra::trim(urban_extent_raster)
res <- terra::as.polygons(urban_extent_raster, dissolve = TRUE) |> sf::st_as_sf()
res <- sf::st_transform(res, pg_current_config()$crs)
res <- sf::st_transform(res, sf::st_crs(config$crs))
res
}
Loading