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

Version: 1.0.3.0

Merge branch '2-add-hydrography-data' into 'master'

Resolve "add hydrography data"

Closes #2

See merge request !3
Showing with 146 additions and 34 deletions
+146 -34
Package: geau
Title: Utilities very useful to share within geau-inondation team
Version: 1.0.2.0
Authors@R:
person(given = "Frédéric",
family = "Grelot",
role = c("aut", "cre"),
email = "frederic.grelot@inrae.fr",
comment = c(ORCID = "YOUR-ORCID-ID"))
Version: 1.0.3.0
Authors@R:
c(
person(given = "Frédéric",
family = "Grelot",
role = c("aut", "cre"),
email = "frederic.grelot@inrae.fr",
comment = c(ORCID = "0000-0003-2638-8114")),
person(given = "David",
family = "Nortes Martinez",
role = c("aut"),
email = "david.nortes-martinez@inrae.fr",
comment = c(ORCID = "0000-0002-0711-5885"))
)
Description: This package collects some very useful utilities to work in a
collaborative way within geau-inondation.
License: GPL (>= 3)
......
......@@ -75,7 +75,7 @@
#' \item{third}{type of hazard}
#' }
#'
#' @source \url{https://www.georisques.gouv.fr/donnees/bases-de-donnees/base-gaspar}
#' @source \url{https://www.georisques.gouv.fr/donnees/bases-de-donnees/base-gaspar} # nolint
"so_ii_catnat"
#' CLC information for so-ii
......@@ -90,4 +90,20 @@
#' A dataset proposing default colors and labels for plotting CLC
#'
#' @format data.frame 5 rows, 3 variables
"clc_color"
\ No newline at end of file
"clc_color"
#' Hydrographic network within the so-ii perimeter
#'
#' A dataset containing the official hydrographic network from the BD TOPAGE
#' within the so-ii perimeter.
#'
#' @format sf data.frame 125 rows, 4 variables
#' \describe{
#' \item{id}{id, from BD TOPAGE (corresponding to CdOh)}
#' \item{name}{character, name of the river or part of the river in BD
#' TOPAGE}
#' \item{degre}{character, level of detail to plot the hydrographic network}
#' }
#'
#' @source \url{http://bdtopage.eaufrance.fr/page/objectifs}
"so_ii_hydro"
\ No newline at end of file
#' @title Plot a thematic map of so-ii
#'
#' @details
#' hazard must be chosen in c("inondation", "submersion", "nappe").
#' For theme "catnat", detail must be chosen in c("inondation", "submersion",
#' "nappe").
#' For theme "hydro" detail must be chosen in "0", "1", "2", "3" or "canal".
#'
#' @param dataset sf objectf, data to be plotted
#' @param dataset_legend list of parameters to be passed to legend
......@@ -10,7 +12,7 @@
#' @param path character, the name of the file to save the plot
#' @param legend_theme logical, should a legend be plotted for the theme
#' @param year character, the year chosen for some themes (catnat, population)
#' @param hazard character, type of hazard chosen (if any). See details.
#' @param detail character, detail for theme, depends on theme
#' @param ... some parameters that will be used by plot (from sf)
#'
#' @return Nothing useful.
......@@ -29,14 +31,15 @@
map_so_ii = function(
dataset,
dataset_legend = NULL,
theme = "clc",
theme = c("none", "clc", "catnat", "hydro"),
bar = TRUE,
path = NULL,
legend_theme = FALSE,
year,
hazard,
detail,
...
) {
theme = match.arg(theme)
if (!is.null(path)) {
switch(
......@@ -117,24 +120,20 @@ map_so_ii = function(
}
if ("catnat" %in% theme) {
if (missing(detail)) {
detail = dimnames(geau::so_ii_catnat)[["hazard"]]
}
detail = match.arg(
detail,
dimnames(geau::so_ii_catnat)[["hazard"]],
several.ok = TRUE
)
border = NA
color = NA
if (!missing(year)) {
border = "grey80"
if (missing(hazard)) {
hazard = dimnames(geau::so_ii_catnat)[["hazard"]]
} else {
hazard = intersect(
hazard,
dimnames(geau::so_ii_catnat)[["hazard"]]
)
if (length(hazard) == 0) {
hazard = dimnames(geau::so_ii_catnat)[["hazard"]]
}
}
catnat = apply(
geau::so_ii_catnat[, as.character(year), hazard, drop = FALSE],
geau::so_ii_catnat[, as.character(year), detail, drop = FALSE],
1:2,
sum
)
......@@ -143,7 +142,6 @@ map_so_ii = function(
scales::alpha("grey80", .5),
NA
)
theme_legend = list(
title = sprintf("Cat-Nat %s", year),
legend = c("Sans d\u00e9claration", "Avec d\u00e9claration"),
......@@ -164,7 +162,41 @@ map_so_ii = function(
)
}
plot(dataset[["geometry"]], add = TRUE, ...)
if ("hydro" %in% theme) {
if (missing(detail)) {
detail = "0"
}
detail = match.arg(
as.character(detail),
choices = c("0", "1", "2", "3", "canal")
)
if (detail == "canal") {
selection = geau::so_ii_hydro[["degre"]] == detail
geometry = geau::so_ii_hydro[["geometry"]][selection]
color = scales::alpha("red", .3)
lwd = 1
} else {
selection = geau::so_ii_hydro[["degre"]] <= detail
geometry = geau::so_ii_hydro[["geometry"]][selection]
color = scales::alpha("blue", .3)
lwd = 4 - as.numeric(geau::so_ii_hydro[["degre"]][selection])
}
plot(geometry, col = color, lwd = lwd, add = TRUE)
theme_legend = list(
title = sprintf("R\u00e9seau hydrographique"),
legend = ifelse(detail == "canal", "canal", "cours d'eau"),
x = "topright",
cex = .8,
bg = "white",
inset = 0.01,
col = color,
lwd = 2
)
}
if (!missing(dataset)) plot(dataset[["geometry"]], add = TRUE, ...)
plot(geau::so_ii_limit, lwd = 2, add = TRUE)
......
# code to prepare `so_ii_hydro` dataset goes here
selection = c("CdOH", "TopoOH")
file_dir = current_version(
"data-common/so-ii/topage",
pattern = "^[0-9-]+$"
)
so_ii_hydro = sf::st_read(file.path(file_dir, "cours-eau-so-ii.shp"))
so_ii_hydro = sf::st_transform(
so_ii_hydro[selection],
sf::st_crs(geau::so_ii_limit)
)
names(so_ii_hydro) = c("id", "name", "geometry")
classification = read.csv2(
current_version("data-common/so-ii/topage", pattern = "courseau"),
colClasses = "character"
)[c("id", "name", "degre")]
so_ii_hydro = merge(so_ii_hydro, classification)
# updating datasets
# actual = setwd(file.path(system.file(package = "geau"), ".."))
actual = setwd("geau")
usethis::use_data(so_ii_hydro, internal = FALSE, overwrite = TRUE)
setwd(actual)
File added
......@@ -8,12 +8,12 @@
map_so_ii(
dataset,
dataset_legend = NULL,
theme = "clc",
theme = c("none", "clc", "catnat", "hydro"),
bar = TRUE,
path = NULL,
legend_theme = FALSE,
year,
hazard,
detail,
...
)
}
......@@ -32,7 +32,7 @@ map_so_ii(
\item{year}{character, the year chosen for some themes (catnat, population)}
\item{hazard}{character, type of hazard chosen (if any). See details.}
\item{detail}{character, detail for theme, depends on theme}
\item{...}{some parameters that will be used by plot (from sf)}
}
......@@ -43,7 +43,9 @@ Nothing useful.
Plot a thematic map of so-ii
}
\details{
hazard must be chosen in c("inondation", "submersion", "nappe").
For theme "catnat", detail must be chosen in c("inondation", "submersion",
"nappe").
For theme "hydro" detail must be chosen in "0", "1", "2", "3" or "canal".
}
\examples{
......
......@@ -13,7 +13,7 @@ array with 3 dimensions
}
}
\source{
\url{https://www.georisques.gouv.fr/donnees/bases-de-donnees/base-gaspar}
\url{https://www.georisques.gouv.fr/donnees/bases-de-donnees/base-gaspar} # nolint
}
\usage{
so_ii_catnat
......
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/data.r
\docType{data}
\name{so_ii_hydro}
\alias{so_ii_hydro}
\title{Hydrographic network within the so-ii perimeter}
\format{
sf data.frame 125 rows, 4 variables
\describe{
\item{id}{id, from BD TOPAGE (corresponding to CdOh)}
\item{name}{character, name of the river or part of the river in BD
TOPAGE}
\item{degre}{character, level of detail to plot the hydrographic network}
}
}
\source{
\url{http://bdtopage.eaufrance.fr/page/objectifs}
}
\usage{
so_ii_hydro
}
\description{
A dataset containing the official hydrographic network from the BD TOPAGE
within the so-ii perimeter.
}
\keyword{datasets}
......@@ -12,12 +12,14 @@ bg[dataset[["habitant"]]] = "cornflowerblue"
col = "black"
cex = 1.4
pch = 21
pch[dataset[["viticulture"]]] = 21
pch[dataset[["habitant"]]] = 22
# Legend definition
dataset_legend = list(
title = "Enquêtes du REX 19 septembre 2020",
legend = c("Agriculteur", "Habitant"),
pch = pch,
pch = c(21, 22),
pt.bg = c("deeppink4", "cornflowerblue"),
pt.cex = cex
)
......
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