Commit 20cde0d8 authored by Grelot Frederic's avatar Grelot Frederic :swimmer_tone5:
Browse files

Merge branch 'master' into map_production

Showing with 90 additions and 0 deletions
+90 -0
# Libraries
library(geau)
library(sf)
# Waterbody
## Data
waterbody = sf::st_read(geau::current_version("data-common/data/topage/plan_eau", "shp"))
waterbody = sf::st_transform(waterbody, crs = st_crs(geau::so_ii_limit))
waterbody = waterbody[
lengths(sf::st_intersects(waterbody, geau::so_ii_limit)) > 0,
c("CdOH", "TopoOH")
]
names(waterbody) = c("id", "name", "geometry")
waterbody = sf::st_intersection(waterbody, geau::so_ii_limit)
## Save
sf::st_write(waterbody, "data-common/so-ii/topage/2021-09/plan_eau.shp", append = FALSE)
# Catchment
## Functions
prepare_catchment = function (sf_data, name, degre) {
selection = sf_data[[sprintf("detail_%s", degre)]] == name
sf::st_sf(
"id" = NA,
"catchment_name" = name,
"degre" = degre,
"geometry" = sf::st_union(sf_data[selection, ])
)
}
## Data
input_dir = geau::current_version("data-common/data/topage/bassin_versant")
catchment = sf::st_read(file.path(input_dir, "06_Rhone-Mediterranee_BassinVersantTopographique.shp"))
classification = read.csv2(geau::current_version("data-common/so-ii/topage", "bassin"))
## Treatments
### CRS
if (!sf::st_crs(catchment) == sf::st_crs(geau::so_ii_limit)) {
catchment = sf::st_transform(catchment, crs = sf::st_crs(geau::so_ii_limit))
}
### Selection & renaming
selection_col = c("CdOH", "geometry")
selection_row = classification[["id"]]
catchment = catchment[catchment[["CdOH"]] %in% unlist(unname(selection_row)), selection_col]
names(catchment) = c("id", "geometry")
catchment = merge(catchment, classification)
### Making catchments
detail_1 = do.call(rbind,
lapply(
unique(catchment[[sprintf("detail_%s", 1)]]),
prepare_catchment,
sf_data = catchment,
degre = 1
)
)
detail_2 = do.call(rbind,
lapply(
unique(catchment[[sprintf("detail_%s", 2)]]),
prepare_catchment,
sf_data = catchment,
degre = 2
)
)
detail_3 = catchment[c("id", "catchment_name")]
detail_3[["degre"]] = "3"
detail_3 = detail_3[names(detail_1)]
catchment = do.call(rbind, list(detail_1, detail_2, detail_3))
### Save
sf::st_write(
catchment,
"data-common/so-ii/topage/2021-09/bassin_versant.shp",
append = FALSE
)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment