Created
May 20, 2020 15:40
-
-
Save statnmap/9d7b4e1082c2f86692aacbd8c02ab85c to your computer and use it in GitHub Desktop.
Find overlapping polygons after buffer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(sf) | |
library(ggplot2) | |
library(dplyr) | |
# Get data | |
extraWD <- "." | |
if (!file.exists(file.path(extraWD, "departement.zip"))) { | |
githubURL <- "https://github.com/statnmap/blog_tips/raw/master/2018-07-14-introduction-to-mapping-with-sf-and-co/data/departement.zip" | |
download.file(githubURL, file.path(extraWD, "departement.zip")) | |
unzip(file.path(extraWD, "departement.zip"), exdir = extraWD) | |
} | |
departements_L93 <- st_read(dsn = extraWD, layer = "DEPARTEMENT", | |
quiet = TRUE) %>% | |
st_transform(2154) | |
# Reduce dataset | |
dep_bretagne <- departements_L93 %>% | |
filter(NOM_REG == "BRETAGNE") | |
# Create buffer | |
dept_buf <- dep_bretagne %>% | |
st_buffer( | |
dist = | |
units::set_units(30, km) | |
) | |
ggplot(dept_buf) + | |
geom_sf(fill = NA) | |
dept_buf_overlap <- dept_buf %>% | |
st_intersection() %>% | |
st_collection_extract("POLYGON") | |
ggplot(dept_buf_overlap) + | |
geom_sf(aes(fill = n.overlaps)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tried Voronoi over the buffer, but that may be a little more complicated....