diff --git a/geau/DESCRIPTION b/geau/DESCRIPTION index 4d2c9d0b4daf3dee006adb83e9729819b5a91033..e2b401e646a675a46ea7a9183fb4923c78e66dd2 100644 --- a/geau/DESCRIPTION +++ b/geau/DESCRIPTION @@ -1,6 +1,6 @@ Package: geau Title: Utilities very useful to share within geau-inondation team -Version: 1.0.0.0 +Version: 1.0.1.0 Authors@R: person(given = "Frédéric", family = "Grelot", @@ -17,8 +17,9 @@ Imports: kableExtra, knitr, rio, - terra, - sf + scales, + sf, + terra Suggests: rmarkdown, testthat diff --git a/geau/R/data.r b/geau/R/data.r index 63f3ababe02f537f00681a7cc588d366f512c1ad..09a94a9470fe62cd2c5bd4cb2a31d85e3bb6a9db 100644 --- a/geau/R/data.r +++ b/geau/R/data.r @@ -9,8 +9,8 @@ #' List of all collectivities included in so-ii #' #' A dataset containing the INSEE code of all local collectivities -#' included in so-ii -#' +#' included in so-ii. +#' #' Basically this dataset is obtained as a selection from the layer #' COMMUNE in ADMIN EXPRESS, more a renaming of variables. #' @@ -18,19 +18,21 @@ #' \describe{ #' \item{id}{id, from IGN ADMIN EXPRESS} #' \item{commune}{character, official name of the commune} -#' \item{commune_majuscule}{character, official capitalized name of the commune} +#' \item{commune_majuscule}{character, official capitalized name of the +#' commune} #' \item{code}{character, INSEE code of the commune} -#' \{statut}{character, "statut" of the commune} -#' \{pop_yyy}{integer, official population of year yyyy in the commune} -#' \{epci}{characeter, INSEE ID of the EPCI of the commune} +#' \item{statut}{character, statut of the commune} +#' \item{pop_yyy}{integer, official population of year yyyy in the commune} +#' \item{epci}{character, INSEE ID of the EPCI of the commune} #' } +#' #' @source \url{https://www.data.gouv.fr/fr/datasets/admin-express/} "so_ii_commune" #' Spatial perimeter of so-ii #' #' A dataset containing the perimeter of so-ii. -#' +#' #' Basically, this dataset is obtained as #' \code{sf::st_union(so_ii_commune)} #' @@ -46,4 +48,19 @@ #' \item{clc_2018}{character, classification from CLC 2018} #' \item{color}{character, default color to be used to plot so_ii_clc} #' } -"so_ii_limit" \ No newline at end of file +"so_ii_limit" + +#' Flood frequency for the municipalities of so-ii +#' +#' A dataset containing the flood frequency by year and so-ii municipality +#' according to the GASPAR database. +#' +#' @format matrix 78 rows, 41 variables +"so_ii_gaspar" + +#' CLC information for so-ii +#' +#' A dataset containing the 2018 version of CLC information for so-ii +#' +#' @format sf object +"so_ii_clc" \ No newline at end of file diff --git a/geau/R/map_so_ii.r b/geau/R/map_so_ii.r index df6a9a27eb8b19abec0303a63ae8bd2f15932ce3..21aec3d839a00dfb78ba2e101c90d173d6179ec7 100644 --- a/geau/R/map_so_ii.r +++ b/geau/R/map_so_ii.r @@ -5,6 +5,7 @@ #' @param theme character, choice for the theme (if any) #' @param bar logical, should a bar be plotted #' @param path character, the name of the file to save the plot +#' @param gaspar_year character, the year chosen for gaspar theme #' @param ... some parameters that will be used by plot (from sf) #' #' @return Nothing useful. @@ -20,7 +21,15 @@ #' # To be added (soon) #' } -map_so_ii = function(dataset, dataset_legend = NULL, theme = "clc", bar = TRUE, path = NULL, ...) { +map_so_ii = function( + dataset, + dataset_legend = NULL, + theme = c("clc", "gaspar"), + bar = TRUE, + path = NULL, + gaspar_year, + ... +) { if (!is.null(path)) { switch( @@ -29,12 +38,12 @@ map_so_ii = function(dataset, dataset_legend = NULL, theme = "clc", bar = TRUE, "png" = grDevices::png(path), stop(sprintf("%s not recognized", tolower(tools::file_ext(path)))) ) + on.exit(grDevices::dev.off()) } ## Init map graphics::par(mai = c(.65, .60, .50, .15)) plot(geau::so_ii_limit, axes = TRUE) - plot(geau::so_ii_limit, lwd = 2, add = TRUE) if ("clc" %in% theme) { plot( @@ -45,10 +54,38 @@ map_so_ii = function(dataset, dataset_legend = NULL, theme = "clc", bar = TRUE, ) } + if ("gaspar" %in% theme) { + border = NA + color = NA + if (!missing(gaspar_year)) { + border = "grey80" + color = ifelse( + geau::so_ii_gaspar[ , as.character(gaspar_year)] > 0, + scales::alpha("grey80", .5), + NA + ) + } + + plot( + geau::so_ii_commune[["geometry"]], + border = border, + col = color, + add = TRUE + ) + } + plot(dataset[["geometry"]], add = TRUE, ...) + plot(geau::so_ii_limit, lwd = 2, add = TRUE) + if (bar == TRUE) { - terra::sbar(10, c(3.55, 43.47), type = "bar", below = "km", label = c(0, 5, 10), cex = .8) + terra::sbar( + 10, c(3.55, 43.47), + type = "bar", + below = "km", + label = c(0, 5, 10), + cex = .8 + ) } if (!is.null(dataset_legend)) { @@ -61,5 +98,5 @@ map_so_ii = function(dataset, dataset_legend = NULL, theme = "clc", bar = TRUE, do.call(graphics::legend, dataset_legend) } - if (!is.null(path)) invisible(grDevices::dev.off()) -} \ No newline at end of file + return(invisible(NULL)) +} diff --git a/geau/data-raw/so_ii_scope.R b/geau/data-raw/so_ii_scope.R index 6c286a2cb182d9620a16f0d209283ff7bba30578..7fe7810642921ee083db74ccd4e05f138535aad2 100644 --- a/geau/data-raw/so_ii_scope.R +++ b/geau/data-raw/so_ii_scope.R @@ -1,6 +1,10 @@ # code to prepare `so_ii_scope` dataset goes here -so_ii_scope = read.csv2(current_version("data-common/so-ii/scope"), colClasses = "character")[["code"]] +so_ii_scope = read.csv2( + current_version("data-common/so-ii/scope"), + colClasses = "character" +)[["code"]] +so_ii_scope = sort(so_ii_scope) # code to prepare `so_ii_commune` dataset goes here @@ -8,7 +12,8 @@ admin_express = current_version("data-common/data/IGN/ADMIN-EXPRESS/version") selection = c("ID", "NOM", "NOM_M", "INSEE_COM", "STATUT", "POPULATION", "SIREN_EPCI") so_ii_commune = sf::st_read(file.path(admin_express, "COMMUNE.shp"))[selection] names(so_ii_commune) = c("id", "commune", "commune_majuscule", "code", "statut", "pop_2021", "epci", "geometry") -so_ii_commune = so_ii_commune[so_ii_commune[["code"]] %in% so_ii_scope, ] +rownames(so_ii_commune) = so_ii_commune[["code"]] +so_ii_commune = so_ii_commune[so_ii_scope, ] # code to prepare `so_ii_limit` dataset goes here @@ -28,6 +33,17 @@ so_ii_clc[["color"]] = as.character( ) ) +# code to prepare `so_ii_gaspar` dataset goes here + +so_ii_gaspar = read.csv2( + current_version("data-common/so-ii/gaspar", "catnat_year_n"), + header = TRUE, + row.names = 1 +) +so_ii_gaspar = as.matrix(so_ii_gaspar) +colnames(so_ii_gaspar) = gsub("^X", "", colnames(so_ii_gaspar)) +so_ii_gaspar = so_ii_gaspar[so_ii_scope, ] + # updating datasets # actual = setwd(file.path(system.file(package = "geau"), "..")) @@ -36,4 +52,5 @@ usethis::use_data(so_ii_scope, internal = FALSE, overwrite = TRUE) usethis::use_data(so_ii_commune, internal = FALSE, overwrite = TRUE) usethis::use_data(so_ii_limit, internal = FALSE, overwrite = TRUE) usethis::use_data(so_ii_clc, internal = FALSE, overwrite = TRUE) +usethis::use_data(so_ii_gaspar, internal = FALSE, overwrite = TRUE) setwd(actual) diff --git a/geau/data/so_ii_commune.rda b/geau/data/so_ii_commune.rda index 3379d330d2daa7cd1c5d33b2882f207518c99338..af05cfa70cffbcb870553a80ea3a611a38c6bc58 100644 Binary files a/geau/data/so_ii_commune.rda and b/geau/data/so_ii_commune.rda differ diff --git a/geau/data/so_ii_gaspar.rda b/geau/data/so_ii_gaspar.rda new file mode 100644 index 0000000000000000000000000000000000000000..b043d07338c1978285be83914c7af4282819f5b2 Binary files /dev/null and b/geau/data/so_ii_gaspar.rda differ diff --git a/geau/data/so_ii_limit.rda b/geau/data/so_ii_limit.rda index c412150f92e981ed28e586cf1d53f19502fe0840..63af11c4fe98d021e2c1686807faece9025379c6 100644 Binary files a/geau/data/so_ii_limit.rda and b/geau/data/so_ii_limit.rda differ diff --git a/geau/man/map_so_ii.Rd b/geau/man/map_so_ii.Rd index e30453a3b42e3674ab0b86de7f484777abf7e37a..118e7364f46086f91332be470f91fd97b6d03e80 100644 --- a/geau/man/map_so_ii.Rd +++ b/geau/man/map_so_ii.Rd @@ -8,9 +8,10 @@ map_so_ii( dataset, dataset_legend = NULL, - theme = "clc", + theme = c("clc", "gaspar"), bar = TRUE, path = NULL, + gaspar_year, ... ) } @@ -25,6 +26,8 @@ map_so_ii( \item{path}{character, the name of the file to save the plot} +\item{gaspar_year}{character, the year chosen for gaspar theme} + \item{...}{some parameters that will be used by plot (from sf)} } \value{ diff --git a/geau/man/so_ii_clc.Rd b/geau/man/so_ii_clc.Rd new file mode 100644 index 0000000000000000000000000000000000000000..0d62e5c3312b105257842ef172f80c92eb82a5d3 --- /dev/null +++ b/geau/man/so_ii_clc.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/data.r +\docType{data} +\name{so_ii_clc} +\alias{so_ii_clc} +\title{CLC information for so-ii} +\format{ +sf object +} +\usage{ +so_ii_clc +} +\description{ +A dataset containing the 2018 version of CLC information for so-ii +} +\keyword{datasets} diff --git a/geau/man/so_ii_commune.Rd b/geau/man/so_ii_commune.Rd index 979256feec766e313c71d63a228553c115b2afbf..1a1052133369797131767da0795b29f437b70cca 100644 --- a/geau/man/so_ii_commune.Rd +++ b/geau/man/so_ii_commune.Rd @@ -9,11 +9,12 @@ sf data.frame 69 rows, 7 variables \describe{ \item{id}{id, from IGN ADMIN EXPRESS} \item{commune}{character, official name of the commune} -\item{commune_majuscule}{character, official capitalized name of the commune} +\item{commune_majuscule}{character, official capitalized name of the +commune} \item{code}{character, INSEE code of the commune} -\{statut}{character, "statut" of the commune} -\{pop_yyy}{integer, official population of year yyyy in the commune} -\{epci}{characeter, INSEE ID of the EPCI of the commune} +\item{statut}{character, statut of the commune} +\item{pop_yyy}{integer, official population of year yyyy in the commune} +\item{epci}{character, INSEE ID of the EPCI of the commune} } } \source{ @@ -24,7 +25,7 @@ so_ii_commune } \description{ A dataset containing the INSEE code of all local collectivities -included in so-ii +included in so-ii. } \details{ Basically this dataset is obtained as a selection from the layer diff --git a/geau/man/so_ii_gaspar.Rd b/geau/man/so_ii_gaspar.Rd new file mode 100644 index 0000000000000000000000000000000000000000..dcf936d10f9d2ae5f621b8c24e8f4abfb2b66904 --- /dev/null +++ b/geau/man/so_ii_gaspar.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/data.r +\docType{data} +\name{so_ii_gaspar} +\alias{so_ii_gaspar} +\title{Flood frequency for the municipalities of so-ii} +\format{ +matrix 78 rows, 41 variables +} +\usage{ +so_ii_gaspar +} +\description{ +A dataset containing the flood frequency by year and so-ii municipality +according to the GASPAR database. +} +\keyword{datasets} diff --git a/map_so_ii.rmd b/map_so_ii.rmd index 7b34aae51df2f463ed5c06b1e724970a393937f7..870f96a2a8424433d1c6d9f691ed32ae47ae398e 100644 --- a/map_so_ii.rmd +++ b/map_so_ii.rmd @@ -24,4 +24,5 @@ dataset_legend = list( map_so_ii(dataset, dataset_legend, path = "toto.pdf", bg = bg, cex = cex, col = col, pch = pch) map_so_ii(dataset, dataset_legend, path = "toto.png", bg = bg, cex = cex, col = col, pch = pch) -map_so_ii(dataset, dataset_legend, path = "toto.pdf", bg = bg, pch = 22) \ No newline at end of file +map_so_ii(dataset, dataset_legend, path = "toto.pdf", bg = bg, pch = 22) +map_so_ii(dataset, dataset_legend, path = "toto.pdf", bg = bg, pch = 22, theme = "gaspar") \ No newline at end of file