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

Merge branch '4-add-catchment-data' into 'master'

Resolve "add catchment data"

Closes #4

See merge request !6
Showing with 185 additions and 7 deletions
+185 -7
Package: geau
Title: Utilities very useful to share within geau-inondation team
Version: 1.0.5.0
Version: 1.0.6.0
Authors@R:
c(
person(given = "Frédéric",
......
......@@ -117,4 +117,24 @@
#' }
#'
#' @source \url{http://bdtopage.eaufrance.fr/page/objectifs}
"so_ii_hydro"
\ No newline at end of file
"so_ii_hydro"
#' Catchment areas of interest within the so-ii perimeter
#'
#' A dataset containing the official catchments areas of interest from the BD
#' TOPAGE within the so-ii perimeter. For degre = 3, the data are basically
#' what is found in BD TOPAGE. For degres 1 and 2, the data result from
#' sf::st_union of data of degre 3 to give a more synthetic representation.
#'
#' @format sf data.frame 15 rows, 4 variables
#' \describe{
#' \item{id}{id, from BD TOPAGE (corresponding to CdOh) or NA when catchment
#' is constructed by so-ii team.}
#' \item{name}{character, name of the catchment area in BD TOPAGE, or given
#' name for catchments constructed by so-ii team.}
#' \item{degre}{factor, importance of the catchment used to plot the
#' catchment areas with different levels of detail ("1", "2", "3").}
#' }
#'
#' @source \url{http://bdtopage.eaufrance.fr/page/objectifs}
"so_ii_catchment"
\ No newline at end of file
......@@ -7,6 +7,8 @@
#' \item{\strong{catnat}: detail must be chosen in "inondation",
#' "submersion", or "nappe". If missing all type will be chosen and
#' aggregated before plotting.}
#' \item{\strong{catchment}: detail must be chosen in "none", "1", "2", "3"
#' for levels of detail. If missing, "1" will be chosen.}
#' \item{\strong{collectivity}: detail must be chosen in "none", "syble",
#' "symbo", "epci" or "syndicate". If missing, "none" will be chosen,
#' and only the boundaries of collectivities are plotted.}
......@@ -53,7 +55,7 @@
map_so_ii = function(
dataset,
dataset_legend = NULL,
theme = c("none", "collectivity", "clc", "catnat", "hydro", "population"),
theme = c("none", "collectivity", "catchment", "catnat", "clc", "hydro", "population"),
bar = TRUE,
path = NULL,
legend_theme = FALSE,
......@@ -280,6 +282,36 @@ map_so_ii = function(
plot(geometry, col = color, lwd = lwd, border = border, add = TRUE)
}
if ("catchment" %in% theme) {
if (missing(detail)) {
detail = "1"
}
detail = match.arg(
as.character(detail),
choices = levels(geau::so_ii_catchment[["degre"]])
)
selection = geau::so_ii_catchment[["degre"]] == detail
geometry = geau::so_ii_catchment[["geometry"]][selection]
catchment = as.factor(geau::so_ii_catchment[["catchment_name"]][selection])
color_legend = grDevices::hcl.colors(nlevels(catchment), "Pastel 1", alpha = .3)
color = color_legend[catchment]
border = "grey80"
lwd = 2
theme_legend = list(
title = sprintf("Bassin versant"),
legend = levels(catchment),
x = "topright",
cex = .8,
bg = "white",
inset = 0.01,
fill = color_legend,
border = border
)
if (detail == "3") rm(theme_legend)
plot(geometry, border = border, col = color, lwd = lwd, add = TRUE)
}
if (!missing(dataset)) plot(dataset[["geometry"]], add = TRUE, ...)
plot(geau::so_ii_limit, lwd = 2, add = TRUE)
......
# code to prepare `so_ii_catchment` dataset goes here
file_dir = geau::current_version(
"data-common/so-ii/topage",
pattern = "^[0-9-]+$"
)
so_ii_catchment = sf::st_read(file.path(file_dir, "bassin_versant.shp"))
names(so_ii_catchment) = c("id", "catchment_name", "degre", "geometry")
Encoding(so_ii_catchment[["catchment_name"]]) = "UTF-8"
so_ii_catchment[["degre"]] = factor(so_ii_catchment[["degre"]])
# updating datasets
actual = setwd("geau")
usethis::use_data(so_ii_catchment, internal = FALSE, overwrite = TRUE)
setwd(actual)
File added
......@@ -8,7 +8,8 @@
map_so_ii(
dataset,
dataset_legend = NULL,
theme = c("none", "collectivity", "clc", "catnat", "hydro", "population"),
theme = c("none", "collectivity", "catchment", "catnat", "clc", "hydro",
"population"),
bar = TRUE,
path = NULL,
legend_theme = FALSE,
......@@ -49,6 +50,8 @@ For the specification of detail, it depends on the theme chosen.
\item{\strong{catnat}: detail must be chosen in "inondation",
"submersion", or "nappe". If missing all type will be chosen and
aggregated before plotting.}
\item{\strong{catchment}: detail must be chosen in "none", "1", "2", "3"
for levels of detail. If missing, "1" will be chosen.}
\item{\strong{collectivity}: detail must be chosen in "none", "syble",
"symbo", "epci" or "syndicate". If missing, "none" will be chosen,
and only the boundaries of collectivities are plotted.}
......
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/data.r
\docType{data}
\name{so_ii_catchment}
\alias{so_ii_catchment}
\title{Catchment areas of interest within the so-ii perimeter}
\format{
sf data.frame 15 rows, 4 variables
\describe{
\item{id}{id, from BD TOPAGE (corresponding to CdOh) or NA when catchment
is constructed by so-ii team.}
\item{name}{character, name of the catchment area in BD TOPAGE, or given
name for catchments constructed by so-ii team.}
\item{degre}{factor, importance of the catchment used to plot the
catchment areas with different levels of detail ("1", "2", "3").}
}
}
\source{
\url{http://bdtopage.eaufrance.fr/page/objectifs}
}
\usage{
so_ii_catchment
}
\description{
A dataset containing the official catchments areas of interest from the BD
TOPAGE within the so-ii perimeter. For degre = 3, the data are basically
what is found in BD TOPAGE. For degres 1 and 2, the data result from
sf::st_union of data of degre 3 to give a more synthetic representation.
}
\keyword{datasets}
......@@ -7,7 +7,11 @@ map_so_ii(theme = "collectivity", detail = "symbo")
map_so_ii(theme = "clc")
map_so_ii(theme = "population")
map_so_ii(theme = "catnat", year = 2019)
map_so_ii(theme = "hydro")
map_so_ii(theme = "hydro", detail = 3)
map_so_ii(theme = "catchment")
map_so_ii(theme = "catchment", detail = 2, legend_theme = TRUE)
map_so_ii(theme = "catchment", detail = 3)
# Can only work if data-common is a symbolic link
......
# Functions
# Libraries
# Data
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[
......@@ -13,5 +16,75 @@ waterbody = waterbody[
names(waterbody) = c("id", "name", "geometry")
waterbody = sf::st_intersection(waterbody, geau::so_ii_limit)
# Save
## 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