diff --git a/script/topage.R b/script/topage.R deleted file mode 100644 index 72984ddd0e6f65d3bdc88b55b1aab74d034c8715..0000000000000000000000000000000000000000 --- a/script/topage.R +++ /dev/null @@ -1,90 +0,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 -)