Skip to content

Instantly share code, notes, and snippets.

@ateucher
Created May 6, 2021 23:36
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 ateucher/87108078255c34744c3456d57adfd477 to your computer and use it in GitHub Desktop.
Save ateucher/87108078255c34744c3456d57adfd477 to your computer and use it in GitHub Desktop.
bc-hydro-outages.R
library(sf)
library(jsonlite)
library(purrr)
library(mapview)
f <- read_json("https://www.bchydro.com/power-outages/app/outages-map-data.json")
polys <- lapply(f, function(x) {
mat <- matrix(unlist(x$polygon), ncol = 2, byrow = TRUE)
st_polygon(list(rbind(mat, mat[1,])))
})
attrs <- map_dfr(f, function(x) unlist(x[names(x) != "polygon"]))
attrs <- do.call("rbind", lapply(f, function(x) unlist(x[names(x) != "polygon"])))
outages <- st_sf(cbind(attrs, st_sfc(polys, crs = 4326)))
mapview(outages)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment