Skip to content

Instantly share code, notes, and snippets.

@mdsumner
Last active April 3, 2024 10:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdsumner/7c48610505165604a4c9efb559229f30 to your computer and use it in GitHub Desktop.
Save mdsumner/7c48610505165604a4c9efb559229f30 to your computer and use it in GitHub Desktop.

phwoar, this is a bit exciting, how about convert all those GADM files to one (Geo)Parquet and open it lazily:

url <- "https://geodata.ucdavis.edu/gadm/gadm4.1/gpkg"
f <- readLines(url)
files <- gsub("\"", "", na.omit(stringr::str_extract(f, "gadm.*\\.gpkg\"")))
gpkgs <- file.path(url, files)     


dir.create("raw")
curl::multi_download(gpkgs, file.path("raw", basename(gpkgs)), multiplex = TRUE)

## system("ogrmerge.py  -single -o gadm41.parquet raw/*.gpkg -src_layer_field_name country")


library(arrow, warn.conflicts = FALSE)
library(dplyr, warn.conflicts = FALSE)
d <- open_dataset("gadm41.parquet",  partitioning = c("country", "GID_0"))
oz <- filter(d, GID_0 == "AUS") |> select(geom, country, NAME_1) |> collect()
plot(wk::wkb(oz$geom[oz$NAME_1 == "Western Australia"]))

I'll do this more carefully and put the file up on source.coop

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment