diff --git a/geau/DESCRIPTION b/geau/DESCRIPTION index c78a0cfc46e3fabfb87fd63f2a32ced593dc3a6f..d913df801dbe20453f95a5160aa953ea1da43944 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.3.0 +Version: 1.0.4.0 Authors@R: c( person(given = "Frédéric", diff --git a/geau/R/data.r b/geau/R/data.r index c2e33bbde6e587c4faef5c001a87a2a12d41f752..02b5851b80a6988a853333422ba25a7873593c7e 100644 --- a/geau/R/data.r +++ b/geau/R/data.r @@ -3,31 +3,39 @@ #' A dataset containing the INSEE code of all local collectivities #' (communes) included in so-ii #' -#' @format a vector of 69 INSEE code +#' @format a vector of 78 INSEE code "so_ii_scope" -#' List of all collectivities included in so-ii +#' Spatial definition of collectivities included in so-ii #' -#' A dataset containing the INSEE code of all local collectivities -#' included in so-ii. +#' A dataset containing the spatial definition of all collectivities +#' included in so-ii and some administrative informations. #' +#' @details #' Basically this dataset is obtained as a selection from the layer -#' COMMUNE in ADMIN EXPRESS, more a renaming of variables. +#' COMMUNE in ADMIN EXPRESS, more a renaming of variables. It is then added +#' information from EPCI in ADMIN EXPRESS and the membership to SYBLE and +#' SYMBO. #' -#' @format sf data.frame 69 rows, 7 variables +#' @format sf data.frame 78 rows, 11 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{code}{character, INSEE code 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} +#' \item{commune_name}{character, INSEE code of the collectivity} +#' \item{syble}{logical, membership in SYBLE} +#' \item{symbo}{logical, membership in SYMBO} +#' \item{commune_name}{character, official name of the collectivity} +#' \item{commune_name_cap}{character, official capitalized name of the +#' collectivity} +#' \item{departement}{character, INSEE code of the departement of the +#' collectivity} +#' \item{region}{character, INSEE code of the region of the +#' collectivity} +#' \item{epci}{character, INSEE code of the EPCI of the collectivity} +#' \item{epci_name}{character, Name of the EPCI of the collectivity} +#' \item{epci_nature}{character, Nature of the EPCI of the collectivity} #' } #' #' @source \url{https://www.data.gouv.fr/fr/datasets/admin-express/} -"so_ii_commune" +"so_ii_collectivity" #' Spatial perimeter of so-ii #' diff --git a/geau/R/map_so_ii.r b/geau/R/map_so_ii.r index b1edc391c566ed460827bf2e4f4b906dd86c4b4a..7b4d10cfea280f0650e3d2a30833f4703b3f5974 100644 --- a/geau/R/map_so_ii.r +++ b/geau/R/map_so_ii.r @@ -1,8 +1,10 @@ #' @title Plot a thematic map of so-ii #' -#' @details +#' @details +#' For theme "collectivity" detail must be chosen in c("none", "syble", "symbo", +#' "epci", "syndicate"). #' For theme "catnat", detail must be chosen in c("inondation", "submersion", -#' "nappe"). +#' "nappe"). #' For theme "hydro" detail must be chosen in "0", "1", "2", "3" or "canal". #' #' @param dataset sf objectf, data to be plotted @@ -31,7 +33,7 @@ map_so_ii = function( dataset, dataset_legend = NULL, - theme = c("none", "clc", "catnat", "hydro", "population"), + theme = c("none", "collectivity", "clc", "catnat", "hydro", "population"), bar = TRUE, path = NULL, legend_theme = FALSE, @@ -55,6 +57,62 @@ map_so_ii = function( graphics::par(mai = c(.65, .60, .50, .15)) plot(geau::so_ii_limit, axes = TRUE) + if ("collectivity" %in% theme) { + if (missing(detail)) { + detail = "none" + } + detail = match.arg( + detail, + c("none", "syble", "symbo", "epci", "syndicate") + ) + + border = "grey80" + color = NA + + theme_legend = list( + title = "Caract\u00e9ristiques des communes", + legend = "Commune", + x = "topright", + cex = .8, + bg = "white", + inset = 0.01, + fill = color, + border = border + ) + geometry = geau::so_ii_collectivity[["geometry"]] + + if (detail %in% c("syble", "syndicate")) { + color_legend = scales::alpha("orange", .3) + color = ifelse( + geau::so_ii_collectivity[["syble"]], + color_legend, + NA + ) + plot(geometry, border = border, col = color, add = TRUE) + theme_legend[["legend"]] = c(theme_legend[["legend"]], "SYBLE") + theme_legend[["fill"]] = c(theme_legend[["fill"]], color_legend) + } + if (detail %in% c("symbo", "syndicate")) { + color_legend = scales::alpha("green", .3) + color = ifelse( + geau::so_ii_collectivity[["symbo"]], + color_legend, + NA + ) + plot(geometry, border = border, col = color, add = TRUE) + theme_legend[["legend"]] = c(theme_legend[["legend"]], "SYMBO") + theme_legend[["fill"]] = c(theme_legend[["fill"]], color_legend) + } + if (detail == "epci") { + epci = as.factor(geau::so_ii_collectivity[["epci_name"]]) + color_legend = grDevices::hcl.colors(nlevels(epci), "Lisbon", alpha = .3) + color = color_legend[epci] + plot(geometry, border = border, col = color, add = TRUE) + theme_legend[["legend"]] = levels(epci) + theme_legend[["fill"]] = color_legend + } + } + if ("clc" %in% theme) { plot( geau::so_ii_clc[["geometry"]], @@ -89,7 +147,7 @@ map_so_ii = function( ) border = "grey80" plot( - geau::so_ii_commune[["geometry"]], + geau::so_ii_collectivity[["geometry"]], border = border, col = color[ , year], add = TRUE @@ -155,7 +213,7 @@ map_so_ii = function( } plot( - geau::so_ii_commune[["geometry"]], + geau::so_ii_collectivity[["geometry"]], border = border, col = color, add = TRUE diff --git a/geau/data-raw/so_ii_collectivity.R b/geau/data-raw/so_ii_collectivity.R new file mode 100644 index 0000000000000000000000000000000000000000..842007b2080b5f0a6b4dbd95eb8ffc73c835afae --- /dev/null +++ b/geau/data-raw/so_ii_collectivity.R @@ -0,0 +1,44 @@ +# code to prepare `so_ii_collectivity` and `so_ii_limit` datasets goes here + +## epci + +so_ii_epci = read.csv2( + geau::current_version("data-common/so-ii/epci") +) +rownames(so_ii_epci) = so_ii_epci[["epci"]] +epci = names(so_ii_epci) + +## collectivity + +admin_express = geau::current_version("data-common/data/IGN/ADMIN-EXPRESS/version") +so_ii_collectivity = sf::st_read(file.path(admin_express, "COMMUNE.shp")) +so_ii_collectivity = so_ii_collectivity["INSEE_COM"] +names(so_ii_collectivity) = c("commune", "geometry") +rownames(so_ii_collectivity) = so_ii_collectivity[["commune"]] +so_ii_collectivity = so_ii_collectivity[geau::so_ii_scope, ] + +so_ii_collectivity = merge( + so_ii_collectivity[geau::so_ii_scope, ], + read.csv2(geau::current_version("data-common/so-ii/commune")) +) +collectivity = names(so_ii_collectivity)[-length(names(so_ii_collectivity))] + +so_ii_collectivity = merge(so_ii_collectivity, so_ii_epci) + +rownames(so_ii_collectivity) = so_ii_collectivity[["commune"]] +so_ii_collectivity = so_ii_collectivity[ + geau::so_ii_scope, + union(collectivity, epci) +] +Encoding(so_ii_collectivity[["commune_name"]]) = "UTF-8" +Encoding(so_ii_collectivity[["epci_name"]]) = "UTF-8" +Encoding(so_ii_collectivity[["epci_nature"]]) = "UTF-8" + +so_ii_limit = sf::st_union(so_ii_collectivity) + +# updating dataset + +actual = setwd("geau") +usethis::use_data(so_ii_collectivity, internal = FALSE, overwrite = TRUE) +usethis::use_data(so_ii_limit, internal = FALSE, overwrite = TRUE) +setwd(actual) diff --git a/geau/data-raw/so_ii_scope.R b/geau/data-raw/so_ii_scope.R index c69a3905d4c0de33c6a14c4f4cc948e612bfa742..d058bd0758b3fc3ee9aa65c8e441efe98bce110a 100644 --- a/geau/data-raw/so_ii_scope.R +++ b/geau/data-raw/so_ii_scope.R @@ -6,19 +6,6 @@ so_ii_scope = read.csv2( )[["code"]] so_ii_scope = sort(so_ii_scope) -# code to prepare `so_ii_commune` dataset goes here - -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") -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 - -so_ii_limit = sf::st_union(so_ii_commune) - # code to prepare `so_ii_clc` dataset goes here so_ii_clc = readRDS("data-common/data/so-ii/so-ii_clc.rds") @@ -63,8 +50,6 @@ so_ii_clc[["color"]] = as.character( # actual = setwd(file.path(system.file(package = "geau"), "..")) actual = setwd("geau") 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(clc_color, internal = FALSE, overwrite = TRUE) setwd(actual) diff --git a/geau/data/so_ii_collectivity.rda b/geau/data/so_ii_collectivity.rda new file mode 100644 index 0000000000000000000000000000000000000000..521aceb0657d4da464d8dd2536c6740d6748afa8 Binary files /dev/null and b/geau/data/so_ii_collectivity.rda differ diff --git a/geau/data/so_ii_commune.rda b/geau/data/so_ii_commune.rda deleted file mode 100644 index af05cfa70cffbcb870553a80ea3a611a38c6bc58..0000000000000000000000000000000000000000 Binary files a/geau/data/so_ii_commune.rda and /dev/null differ diff --git a/geau/man/map_so_ii.Rd b/geau/man/map_so_ii.Rd index e2c1ac696702834840d863d455056d39fe9d1fbb..3ff733788f0fbbdfe571fc42ba96250d4f69d747 100644 --- a/geau/man/map_so_ii.Rd +++ b/geau/man/map_so_ii.Rd @@ -8,7 +8,7 @@ map_so_ii( dataset, dataset_legend = NULL, - theme = c("none", "clc", "catnat", "hydro"), + theme = c("none", "collectivity", "clc", "catnat", "hydro", "population"), bar = TRUE, path = NULL, legend_theme = FALSE, @@ -43,6 +43,8 @@ Nothing useful. Plot a thematic map of so-ii } \details{ +For theme "collectivity" detail must be chosen in c("none", "syble", "symbo", +"epci", "syndicate"). 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". diff --git a/geau/man/so_ii_collectivity.Rd b/geau/man/so_ii_collectivity.Rd new file mode 100644 index 0000000000000000000000000000000000000000..28fb45833f55ca9eea6371451d6b0fff4e19aac0 --- /dev/null +++ b/geau/man/so_ii_collectivity.Rd @@ -0,0 +1,41 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/data.r +\docType{data} +\name{so_ii_collectivity} +\alias{so_ii_collectivity} +\title{Spatial definition of collectivities included in so-ii} +\format{ +sf data.frame 78 rows, 11 variables +\describe{ +\item{commune_name}{character, INSEE code of the collectivity} +\item{syble}{logical, membership in SYBLE} +\item{symbo}{logical, membership in SYMBO} +\item{commune_name}{character, official name of the collectivity} +\item{commune_name_cap}{character, official capitalized name of the +collectivity} +\item{departement}{character, INSEE code of the departement of the +collectivity} +\item{region}{character, INSEE code of the region of the +collectivity} +\item{epci}{character, INSEE code of the EPCI of the collectivity} +\item{epci_name}{character, Name of the EPCI of the collectivity} +\item{epci_nature}{character, Nature of the EPCI of the collectivity} +} +} +\source{ +\url{https://www.data.gouv.fr/fr/datasets/admin-express/} +} +\usage{ +so_ii_collectivity +} +\description{ +A dataset containing the spatial definition of all collectivities +included in so-ii and some administrative informations. +} +\details{ +Basically this dataset is obtained as a selection from the layer +COMMUNE in ADMIN EXPRESS, more a renaming of variables. It is then added +information from EPCI in ADMIN EXPRESS and the membership to SYBLE and +SYMBO. +} +\keyword{datasets} diff --git a/geau/man/so_ii_commune.Rd b/geau/man/so_ii_commune.Rd deleted file mode 100644 index 1a1052133369797131767da0795b29f437b70cca..0000000000000000000000000000000000000000 --- a/geau/man/so_ii_commune.Rd +++ /dev/null @@ -1,34 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/data.r -\docType{data} -\name{so_ii_commune} -\alias{so_ii_commune} -\title{List of all collectivities included in so-ii} -\format{ -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{code}{character, INSEE code 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/} -} -\usage{ -so_ii_commune -} -\description{ -A dataset containing the INSEE code of all local collectivities -included in so-ii. -} -\details{ -Basically this dataset is obtained as a selection from the layer -COMMUNE in ADMIN EXPRESS, more a renaming of variables. -} -\keyword{datasets} diff --git a/geau/man/so_ii_scope.Rd b/geau/man/so_ii_scope.Rd index ad9328056d38f4c9e9c46d8e2ed0d425bf9d3bb4..270cf442bc19555c283abef0f203eeaa47d32d15 100644 --- a/geau/man/so_ii_scope.Rd +++ b/geau/man/so_ii_scope.Rd @@ -5,7 +5,7 @@ \alias{so_ii_scope} \title{Local collectivities included in so-ii} \format{ -a vector of 69 INSEE code +a vector of 78 INSEE code } \usage{ so_ii_scope