mdsumner / geobs

What the Package Does (One Line, Title Case)
Other
1 stars 0 forks source link

build a bbox layer of the boundaries so we can use extent without codes #2

Open mdsumner opened 1 year ago

mdsumner commented 1 year ago

done here, was stymied for a bit because "BHS" is inconsistent and I went down a rabbit hole

here just the geometry read out, though probably the repo has this somewhere?

  library(geobs)
get_all_codes <- function() {
  b <- "https://github.com/wmgeolab/geoBoundaries/raw/main/releaseData"

  codes <- readr::read_csv(file.path(b, "geoBoundariesOpen-meta.csv"))
  dplyr::group_by(codes, boundaryISO) |> dplyr::select(boundaryName, boundaryISO, boundaryType) |> dplyr::distinct()
}

d <-get_all_codes() |> dplyr::slice_min(boundaryType) |> dplyr::ungroup()
#> Rows: 712 Columns: 28
#> ── Column specification ────────────────────────────────────────────────────────
#> Delimiter: ","
#> chr (18): boundaryID, boundaryName, boundaryISO, boundaryYearRepresented, bo...
#> dbl (10): admUnitCount, meanVertices, minVertices, maxVertices, meanPerimete...
#> 
#> ℹ Use `spec()` to retrieve the full column specification for this data.
#> ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
library(furrr) 
#> Loading required package: future
plan(multisession)

lall <- future_map(split(d, d$boundaryISO), \(.x) get_bounds(.x$boundaryISO, .x$boundaryType, simplified = TRUE))
plan(sequential)

## we aren't rbinding because of https://github.com/wmgeolab/geoBoundaries/issues/2288
g <- do.call(c, lapply(lall, \(.x) .x$geometry))
plot(do.call(c, lapply(g, wk::wk_bbox)))

Created on 2023-03-07 with reprex v2.0.2