diff --git a/geau/DESCRIPTION b/geau/DESCRIPTION index ce9d0515d68b2bd19f4dc1adc9219b332ba08b10..c78a0cfc46e3fabfb87fd63f2a32ced593dc3a6f 100644 --- a/geau/DESCRIPTION +++ b/geau/DESCRIPTION @@ -1,12 +1,19 @@ 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) diff --git a/geau/R/data.r b/geau/R/data.r index 339597270b987ab363ada35854809d1386eeb5ee..c2e33bbde6e587c4faef5c001a87a2a12d41f752 100644 --- a/geau/R/data.r +++ b/geau/R/data.r @@ -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 diff --git a/geau/R/map_so_ii.r b/geau/R/map_so_ii.r index 23713be56955b86fd7961c48fe5e4970e1ce1998..43771ca1828e5f474d0806f10aef5c789b9d1423 100644 --- a/geau/R/map_so_ii.r +++ b/geau/R/map_so_ii.r @@ -1,7 +1,9 @@ #' @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) diff --git a/geau/data-raw/so_ii_hydro.R b/geau/data-raw/so_ii_hydro.R new file mode 100644 index 0000000000000000000000000000000000000000..f86ebcc6ce1f13d0132d128dbdd3bc66a4b9f3d5 --- /dev/null +++ b/geau/data-raw/so_ii_hydro.R @@ -0,0 +1,27 @@ +# 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) diff --git a/geau/data/so_ii_hydro.rda b/geau/data/so_ii_hydro.rda new file mode 100644 index 0000000000000000000000000000000000000000..07c507b7dee470b6d8fdfe7c38fb9ca8a8a4ee90 Binary files /dev/null and b/geau/data/so_ii_hydro.rda differ diff --git a/geau/man/map_so_ii.Rd b/geau/man/map_so_ii.Rd index b063bfd86ca154bb8d0b971d78369d9fdb9bc2fc..e2c1ac696702834840d863d455056d39fe9d1fbb 100644 --- a/geau/man/map_so_ii.Rd +++ b/geau/man/map_so_ii.Rd @@ -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{ diff --git a/geau/man/so_ii_catnat.Rd b/geau/man/so_ii_catnat.Rd index 8fd9e9087ccf4c23d707697c6b1456d430868997..50b2aab612ad4afa953986d39234eed25cf48de1 100644 --- a/geau/man/so_ii_catnat.Rd +++ b/geau/man/so_ii_catnat.Rd @@ -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 diff --git a/geau/man/so_ii_hydro.Rd b/geau/man/so_ii_hydro.Rd new file mode 100644 index 0000000000000000000000000000000000000000..58325f5936d98b4edf2b331f1f9bae4f271d38ef --- /dev/null +++ b/geau/man/so_ii_hydro.Rd @@ -0,0 +1,26 @@ +% 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} diff --git a/map_so_ii.rmd b/map_so_ii.rmd index d6d6a50d813d956a2ae7a15cbe726bf55a7bf05d..b77ea05555b2049509db4395312065b02bf9a597 100644 --- a/map_so_ii.rmd +++ b/map_so_ii.rmd @@ -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 )