Skip to content

Instantly share code, notes, and snippets.

@boshek
Created July 31, 2020 17:09
Show Gist options
  • Save boshek/673fc3e2d68326b838db047773224723 to your computer and use it in GitHub Desktop.
Save boshek/673fc3e2d68326b838db047773224723 to your computer and use it in GitHub Desktop.
library(sf)
library(dplyr)
library(bcdata)
get_bc_fsa <- function() {
x <- 'http://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/2016/lfsa000b16a_e.zip'
temp_zip <- file.path(tempdir(), basename(x))
export_dir <- tempdir()
shp_path <- list.files(export_dir, pattern = "*.shp", full.names = TRUE)
if (!isTRUE(file.exists(shp_path))) {
download.file(x, temp_zip)
unzip_path <- unzip(temp_zip, exdir = export_dir)
message(paste0("File successfully unzipped to ", export_dir))
}
dat <- sf::read_sf(shp_path)
dat <- dat[dat$PRNAME == "British Columbia / Colombie-Britannique",]
sf::st_transform(dat, 3005)
}
bc_fsa <- get_bc_fsa()
V0M <- bc_fsa %>%
filter(CFSAUID == "V0M")
abb <- bcdc_query_geodata('municipalities-legally-defined-administrative-areas-of-bc') %>%
filter(ADMIN_AREA_ABBREVIATION == "Abbotsford") %>%
collect()
plot(V0M$geometry, col = "red")
plot(abb$geometry, add = TRUE, col = "blue")
inter <- st_intersection(V0M, abb)
plot(inter$geometry)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment