diff --git a/geau/DESCRIPTION b/geau/DESCRIPTION index c78a0cfc46e3fabfb87fd63f2a32ced593dc3a6f..f5e3174b19de938b56a11cfad52f2ec3f27179fc 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.6.0 Authors@R: c( person(given = "Frédéric", diff --git a/geau/R/data.r b/geau/R/data.r index 6a25759cbac25eda96f5ce56a21eeb094e8e14bc..7528b6f313e944575e18c91854743041aa3057ca 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 #' @@ -100,9 +108,12 @@ #' @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} +#' \item{name}{character, name of the hydrographic elements in the BD TOPAGE} +#' \item{degre}{factor, level of importance of the hydrographic element +#' used to plot the hydrographic network with different levels of +#' detail ("1", "2", "3").} +#' \item{type}{factor, type of hydrographic element ("canal", "river", +#' "waterbody")} #' } #' #' @source \url{http://bdtopage.eaufrance.fr/page/objectifs} @@ -111,13 +122,18 @@ #' 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. +#' 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)} -#' \item{name}{character, name of the catchment area in BD TOPAGE} -#' \item{degre}{character, level of detail to plot the catchment area} +#' \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} diff --git a/geau/R/map_so_ii.r b/geau/R/map_so_ii.r index 69b9aa0ef5ab10bef2c94d39066806839d4dc5b3..66e247c4a8452e50b11b0fefb3e05913f01059d9 100644 --- a/geau/R/map_so_ii.r +++ b/geau/R/map_so_ii.r @@ -1,9 +1,32 @@ #' @title Plot a thematic map of so-ii #' -#' @details -#' 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". +#' @details +#' \subsection{detail specification}{ +#' For the specification of detail, it depends on the theme chosen. +#' \itemize{ +#' \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.} +#' \item{\strong{hydro}: detail must be chosen in "none", "1", "2", "3" for +#' levels of detail or "canal", "river", "waterbody" for types of +#' hydrographic elements. If missing, "none" will be chosen, and +#' everything is plotted.} +#' } +#' } +#' \subsection{year specification}{ +#' For the specification of year, it depends on the theme chosen. +#' \itemize{ +#' \item{\strong{catnat}: year corresponds to the year of data. If missing, +#' nothing is plotted.} +#' \item{\strong{population}: year corresponds to the year of data. If +#' missing, last available year is plotted.} +#' } +#' } #' #' @param dataset sf objectf, data to be plotted #' @param dataset_legend list of parameters to be passed to legend @@ -12,7 +35,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 detail character, detail for theme, depends on theme +#' @param detail character, detail for theme, depends on theme. See details. #' @param ... some parameters that will be used by plot (from sf) #' #' @return Nothing useful. @@ -21,6 +44,7 @@ #' #' @encoding UTF-8 #' @author Frédéric Grelot +#' @author David Nortes Martinez #' #' @examples #' @@ -31,7 +55,7 @@ map_so_ii = function( dataset, dataset_legend = NULL, - theme = c("none", "clc", "catnat", "hydro", "population", "catchment"), + theme = c("none", "collectivity", "catchment", "catnat", "clc", "hydro", "population"), bar = TRUE, path = NULL, legend_theme = FALSE, @@ -55,6 +79,63 @@ 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"]] + plot(geometry, border = border, col = color, add = TRUE) + + 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 +170,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 +236,7 @@ map_so_ii = function( } plot( - geau::so_ii_commune[["geometry"]], + geau::so_ii_collectivity[["geometry"]], border = border, col = color, add = TRUE @@ -164,63 +245,71 @@ map_so_ii = function( if ("hydro" %in% theme) { if (missing(detail)) { - detail = "0" + detail = "none" } detail = match.arg( as.character(detail), - choices = c("0", "1", "2", "3", "canal") + choices = c( + "none", + levels(geau::so_ii_hydro[["degre"]]), + levels(geau::so_ii_hydro[["type"]]) + ) ) - 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) - + color = scales::alpha("blue", .3) + bg = scales::alpha("blue", .3) + border = NA + selection = seq(nrow(geau::so_ii_hydro)) theme_legend = list( title = sprintf("R\u00e9seau hydrographique"), - legend = ifelse(detail == "canal", "canal", "cours d'eau"), + legend = "\u00e9l\u00e9ment du r\u00e9seau", x = "topright", cex = .8, bg = "white", inset = 0.01, col = color, - lwd = 2 + lwd = 1 ) + if (detail %in% levels(geau::so_ii_hydro[["type"]])) { + selection = as.character(geau::so_ii_hydro[["type"]]) == detail + theme_legend[["legend"]] = detail + } + if (detail %in% levels(geau::so_ii_hydro[["degre"]])) { + selection = as.character(geau::so_ii_hydro[["degre"]]) <= detail + } + geometry = geau::so_ii_hydro[["geometry"]][selection] + lwd = 4 - as.numeric(geau::so_ii_hydro[["degre"]][selection]) + + plot(geometry, col = color, lwd = lwd, border = border, add = TRUE) } if ("catchment" %in% theme) { if (missing(detail)) { - detail = "0" + detail = "1" } detail = match.arg( - as.character(detail), - choices = c("0", "1", "2") + 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" - color = scales::alpha("grey80", .5) - lwd = 1 - plot(geometry, border = border, col = color, lwd = lwd, add = TRUE) - + lwd = 2 theme_legend = list( - title = sprintf("Unit\u00e9 administrative"), - legend = "Bassin versant", + title = sprintf("Bassin versant"), + legend = levels(catchment), x = "topright", cex = .8, bg = "white", inset = 0.01, - fill = unique(color), + 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, ...) diff --git a/geau/data-raw/so_ii_catchment.R b/geau/data-raw/so_ii_catchment.R index c5045c36bfa205217b599e1ddddc95b77bcb0087..4939f3a3b9e33d190204655e843af9720b39fc87 100644 --- a/geau/data-raw/so_ii_catchment.R +++ b/geau/data-raw/so_ii_catchment.R @@ -5,11 +5,13 @@ file_dir = current_version( "data-common/so-ii/topage", pattern = "^[0-9-]+$" ) -so_ii_catchment = sf::st_read(file.path(file_dir, "bassin_versant_so_ii.shp")) +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(file.path(system.file(package = "geau"), "..")) actual = setwd("geau") usethis::use_data(so_ii_catchment, internal = FALSE, overwrite = TRUE) setwd(actual) 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_hydro.R b/geau/data-raw/so_ii_hydro.R index f86ebcc6ce1f13d0132d128dbdd3bc66a4b9f3d5..f3eb9d79adabb5e81da0e8fe145b0acdcdbbd128 100644 --- a/geau/data-raw/so_ii_hydro.R +++ b/geau/data-raw/so_ii_hydro.R @@ -1,27 +1,41 @@ # code to prepare `so_ii_hydro` dataset goes here selection = c("CdOH", "TopoOH") -file_dir = current_version( +file_dir = geau::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], +river = sf::st_read(file.path(file_dir, "cours_eau.shp")) +river = sf::st_transform( + river[selection], sf::st_crs(geau::so_ii_limit) ) -names(so_ii_hydro) = c("id", "name", "geometry") +names(river) = c("id", "name", "geometry") classification = read.csv2( - current_version("data-common/so-ii/topage", pattern = "courseau"), + geau::current_version("data-common/so-ii/topage", pattern = "cours_eau"), + colClasses = "character", + row.names = 1 +) +river = merge(river, classification) + +waterbody = sf::st_read(file.path(file_dir, "plan_eau.shp")) +waterbody[["name"]] = gsub("C[?]ur", "Cœur", waterbody[["name"]]) + +classification = read.csv2( + geau::current_version("data-common/so-ii/topage", pattern = "plan_eau"), colClasses = "character" -)[c("id", "name", "degre")] +) +waterbody = merge(waterbody, classification) + +so_ii_hydro = rbind(river, waterbody) -so_ii_hydro = merge(so_ii_hydro, classification) +so_ii_hydro[["degre"]] = factor(so_ii_hydro[["degre"]]) +so_ii_hydro[["type"]] = factor(so_ii_hydro[["type"]]) +Encoding(waterbody[["name"]]) = "UTF-8" # 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-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_catchment.rda b/geau/data/so_ii_catchment.rda index 2d8ff3549205ff6f16b0b6df3a6f5ab4f8a3b05d..4b567b77c387dae46c70acbd261594288a68f480 100644 Binary files a/geau/data/so_ii_catchment.rda and b/geau/data/so_ii_catchment.rda differ 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/data/so_ii_hydro.rda b/geau/data/so_ii_hydro.rda index 07c507b7dee470b6d8fdfe7c38fb9ca8a8a4ee90..1f6235f046cd315fc11ea7a7d3b01ae917596108 100644 Binary files a/geau/data/so_ii_hydro.rda 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 e2c1ac696702834840d863d455056d39fe9d1fbb..63263ef27e28e12b0f64d7351fd4254be0512250 100644 --- a/geau/man/map_so_ii.Rd +++ b/geau/man/map_so_ii.Rd @@ -8,7 +8,8 @@ map_so_ii( dataset, dataset_legend = NULL, - theme = c("none", "clc", "catnat", "hydro"), + theme = c("none", "collectivity", "catchment", "catnat", "clc", "hydro", + "population"), bar = TRUE, path = NULL, legend_theme = FALSE, @@ -32,7 +33,7 @@ map_so_ii( \item{year}{character, the year chosen for some themes (catnat, population)} -\item{detail}{character, detail for theme, depends on theme} +\item{detail}{character, detail for theme, depends on theme. See details.} \item{...}{some parameters that will be used by plot (from sf)} } @@ -43,9 +44,32 @@ Nothing useful. Plot a thematic map of so-ii } \details{ -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". +\subsection{detail specification}{ +For the specification of detail, it depends on the theme chosen. +\itemize{ +\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.} +\item{\strong{hydro}: detail must be chosen in "none", "1", "2", "3" for +levels of detail or "canal", "river", "waterbody" for types of +hydrographic elements. If missing, "none" will be chosen, and +everything is plotted.} +} +} +\subsection{year specification}{ +For the specification of year, it depends on the theme chosen. +\itemize{ +\item{\strong{catnat}: year corresponds to the year of data. If missing, +nothing is plotted.} +\item{\strong{population}: year corresponds to the year of data. If +missing, last available year is plotted.} +} +} } \examples{ @@ -55,4 +79,6 @@ For theme "hydro" detail must be chosen in "0", "1", "2", "3" or "canal". } \author{ Frédéric Grelot + +David Nortes Martinez } diff --git a/geau/man/so_ii_catchment.Rd b/geau/man/so_ii_catchment.Rd new file mode 100644 index 0000000000000000000000000000000000000000..0cfe4ebe5646c2bb3ef083c5be367f97a8bbdcf7 --- /dev/null +++ b/geau/man/so_ii_catchment.Rd @@ -0,0 +1,30 @@ +% 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} 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_hydro.Rd b/geau/man/so_ii_hydro.Rd index 58325f5936d98b4edf2b331f1f9bae4f271d38ef..8af21fddb61aa39d694ccc101e7c9462672a8011 100644 --- a/geau/man/so_ii_hydro.Rd +++ b/geau/man/so_ii_hydro.Rd @@ -8,9 +8,12 @@ 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} +\item{name}{character, name of the hydrographic elements in the BD TOPAGE} +\item{degre}{factor, level of importance of the hydrographic element +used to plot the hydrographic network with different levels of +detail ("1", "2", "3").} +\item{type}{factor, type of hydrographic element ("canal", "river", +"waterbody")} } } \source{ 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 diff --git a/map_so_ii.rmd b/map_so_ii.rmd index b77ea05555b2049509db4395312065b02bf9a597..7938eb84adfed38244d9f737d3513649ca2a4cf9 100644 --- a/map_so_ii.rmd +++ b/map_so_ii.rmd @@ -1,3 +1,14 @@ +library(sf) + +map_so_ii() +map_so_ii(theme = "collectivity") +map_so_ii(theme = "collectivity", detail = "syble") +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", detail = 3) + # Can only work if data-common is a symbolic link # Data to be plotted diff --git a/script/admin_express.R b/script/admin_express.R new file mode 100644 index 0000000000000000000000000000000000000000..626120f9805b76278f9741c96e7f960f5e7e8576 --- /dev/null +++ b/script/admin_express.R @@ -0,0 +1,33 @@ +# Functions + +# Data +input_dir = geau::current_version("data-common/data/IGN/ADMIN-EXPRESS/version") + +commune = sf::st_read(file.path(input_dir, "COMMUNE.shp")) +commune = sf::st_drop_geometry(commune) +commune = commune[c("NOM", "NOM_M", "INSEE_COM", "INSEE_DEP", "INSEE_REG", "SIREN_EPCI")] +names(commune) = c("commune_name", "commune_nam_cap", "commune", "departement", "region", "epci") +rownames(commune) = commune[["commune"]] +commune = commune[geau::so_ii_scope, ] + +commune_so_ii = read.csv2(geau::current_version("data-common/so-ii/commune")) +commune_so_ii = merge(commune_so_ii[c("commune", "syble", "symbo")], commune) + +epci = sf::st_read(file.path(input_dir, "EPCI.shp")) +epci = sf::st_drop_geometry(epci) +names(epci) = c("id", "epci", "epci_name", "epci_nature") +rownames(epci) = epci[["epci"]] +epci = epci[unique(commune[["epci"]]), c("epci", "epci_name", "epci_nature")] + +# Save +today = Sys.Date() +write.csv2( + commune_so_ii, + sprintf("data-common/so-ii/commune/commune-%s.csv", today), + row.names = FALSE +) +write.csv2( + epci, + sprintf("data-common/so-ii/epci/epci-%s.csv", today), + row.names = FALSE +) \ No newline at end of file diff --git a/script/classif_bassins.r b/script/classif_bassins.r deleted file mode 100644 index 68df3ceec545c3c944e6dfd6f1176d43f03506db..0000000000000000000000000000000000000000 --- a/script/classif_bassins.r +++ /dev/null @@ -1,72 +0,0 @@ -# loading libraries -library(sf) -library(geau) - -# loading dataset -bassin = sf::st_read("/home/dnm/Seafile/data-common/data/topage/bassin_versant/2019/06_RhУne-MВditerranВe_BassinVersantTopographique.shp") - -# checking and adjusting crs (if needed) -if (!sf::st_crs(bassin) == sf::st_crs(geau::so_ii_limit)) { - bassin = sf::st_transform(bassin, crs = sf::st_crs(geau::so_ii_limit)) -} - -if (!sf::st_crs(subsector) == sf::st_crs(geau::so_ii_limit)) { - subsector = sf::st_transform(subsector, crs = sf::st_crs(geau::so_ii_limit)) -} - -# data manipulation -selection_col = c("CdOH", "TopoOH", "geometry") -selection_row = list( - mosson = c( - '06B0000002150456066', - '06B0000002150458403', - '06B0000002150458401', - '06B0000002150456007', - '06B0000002150455994' - ), - lez = c( - '06B0000002150456086', - '06B0000002150456009' - ), - lor = c( - '06B0000002150456068', - '06B0000002150456055', - '06B0000002150456053', - '06B0000002150461370', - '06B0000002150457044' - ) -) - -bassin_so_ii = bassin[bassin[["CdOH"]] %in% unlist(unname(selection_row)), selection_col] -names(bassin_so_ii) = c("id", "bassin", "geometry") -bassin_so_ii[["degre"]] = 2 - -bassin_mosson_geom = bassin[bassin[["CdOH"]] %in% unlist(unname(selection_row[["mosson"]])), selection_col] |> sf::st_union() -bassin_mosson_df = data.frame( - id = "soii01", - bassin = "Bassin Mosson", - degre = 1 -) -bassin_mosson = sf::st_set_geometry(bassin_mosson_df, bassin_mosson_geom) - -bassin_lez_geom = bassin[bassin[["CdOH"]] %in% unlist(unname(selection_row[["lez"]])), selection_col] |> sf::st_union() -bassin_lez_df = data.frame( - id = "soii02", - bassin = "Bassin Lez", - degre = 1 -) -bassin_lez = sf::st_set_geometry(bassin_lez_df, bassin_lez_geom) - -bassin_lor_geom = bassin[bassin[["CdOH"]] %in% unlist(unname(selection_row[["lor"]])), selection_col] |> sf::st_union() -bassin_lor_df = data.frame( - id = "soii03", - bassin = "Bassin L'or", - degre = 1 -) -bassin_lor = sf::st_set_geometry(bassin_lor_df, bassin_lor_geom) - -bassin_so_ii = rbind(bassin_so_ii, bassin_mosson) -bassin_so_ii = rbind(bassin_so_ii, bassin_lez) -bassin_so_ii = rbind(bassin_so_ii, bassin_lor) - -sf::st_write(bassin_so_ii, dsn = "data-common/so-ii/topage/2021-09/bassin_versant_so_ii.shp") diff --git a/script/topage.R b/script/topage.R new file mode 100644 index 0000000000000000000000000000000000000000..72984ddd0e6f65d3bdc88b55b1aab74d034c8715 --- /dev/null +++ b/script/topage.R @@ -0,0 +1,90 @@ +# Libraries + +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[ + lengths(sf::st_intersects(waterbody, geau::so_ii_limit)) > 0, + c("CdOH", "TopoOH") +] +names(waterbody) = c("id", "name", "geometry") +waterbody = sf::st_intersection(waterbody, geau::so_ii_limit) + +## 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 +)