sevel-atlas/scripts/enporzhiañ_kartenn.R

75 lines
2.3 KiB
R
Raw Normal View History

2022-11-04 06:05:29 +00:00
library(osmdata)
library(sf)
library(magrittr)
library(dplyr)
library(tidyr)
library(ggplot2)
2022-11-04 05:30:54 +00:00
##############################
## Arventennoù
# Cheñch teuliad
source_path <- rstudioapi::getActiveDocumentContext()$path
setwd(dirname(dirname(source_path)))
## Kemer an data
# An harzoù
2022-11-04 06:05:29 +00:00
if (!file.exists("./tmp/kumuniou.RData")) {
2022-11-04 05:30:54 +00:00
kumuniou_22 <- opq(bbox="Côtes-d'Armor") %>%
add_osm_feature(key = 'boundary', value = 'administrative') %>%
add_osm_feature(key = 'admin_level', value = '8') %>%
osmdata_sf
kumuniou_29 <- opq(bbox="Finistère") %>%
add_osm_feature(key = 'boundary', value = 'administrative') %>%
add_osm_feature(key = 'admin_level', value = '8') %>%
osmdata_sf
kumuniou_56 <- opq(bbox="Morbihan") %>%
add_osm_feature(key = 'boundary', value = 'administrative') %>%
add_osm_feature(key = 'admin_level', value = '8') %>%
osmdata_sf
kumuniou <- c(kumuniou_22,
kumuniou_29,
kumuniou_56
) %>% unique_osmdata
kumuniou_poly <- kumuniou$osm_multipolygons
kumuniou_poly <- kumuniou_poly %>%
mutate(ref.INSEE = as.numeric(as.character(ref.INSEE))) %>%
filter(grepl("^(22|29|56)", ref.INSEE))
2022-11-04 06:05:29 +00:00
ggplot(kumuniou_poly)+
2022-11-04 05:30:54 +00:00
geom_sf()
dept_22 <- opq(bbox = "Côtes-d'Armor") %>%
add_osm_feature(key = 'boundary', value = 'administrative') %>%
add_osm_feature(key = 'admin_level', value = '6') %>%
osmdata_sf %>% unique_osmdata
dept_29 <- opq(bbox = "Finistère") %>%
add_osm_feature(key = 'boundary', value = 'administrative') %>%
add_osm_feature(key = 'admin_level', value = '6') %>%
osmdata_sf %>% unique_osmdata
dept_56 <- opq(bbox = "Morbihan") %>%
add_osm_feature(key = 'boundary', value = 'administrative') %>%
add_osm_feature(key = 'admin_level', value = '6') %>%
osmdata_sf %>% unique_osmdata
2022-11-04 06:05:29 +00:00
dept <- c(dept_22, dept_29, dept_56) %>%
2022-11-04 05:30:54 +00:00
unique_osmdata
dept_poly <- dept$osm_multipolygons
dept_poly <- dept_poly %>%
filter(grepl("^(22|29|56)", ref.INSEE))
save(kumuniou, kumuniou_poly,
dept, dept_poly,
file = "./tmp/kumuniou.RData")
} else {
2022-11-04 06:05:29 +00:00
load(file = "./tmp/kumuniou.RData")
2022-11-04 05:30:54 +00:00
}
2022-11-04 06:05:29 +00:00
kumuniou_poly_simple <- st_simplify(kumuniou_poly, preserveTopology = TRUE, dTolerance = 0.001)
dept_poly_simple <- st_simplify(dept_poly, preserveTopology = TRUE, dTolerance = 0.001)