diff --git a/geau/DESCRIPTION b/geau/DESCRIPTION index d913df801dbe20453f95a5160aa953ea1da43944..4fcb4ddff47937e8af395bf91b7f8670635e9896 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.4.0 +Version: 1.0.5.0 Authors@R: c( person(given = "Frédéric", diff --git a/geau/R/data.r b/geau/R/data.r index 02b5851b80a6988a853333422ba25a7873593c7e..52896c81d1c949cb9f60246a05250a8d161c206a 100644 --- a/geau/R/data.r +++ b/geau/R/data.r @@ -108,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} diff --git a/geau/R/map_so_ii.r b/geau/R/map_so_ii.r index 323a2906fcf285cdab7ea5e54695b17ceb7c845f..7d8be39e4c6db955f86e137d40f2d58f2d8ba915 100644 --- a/geau/R/map_so_ii.r +++ b/geau/R/map_so_ii.r @@ -4,12 +4,25 @@ #' \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.} -#' \item{\strong{collectivity}: detail must be chosen in "none", "syble", "symbo", -#' "epci" or "syndicate". If missing "none" will be chosen.} -#' \item{\strong{hydro}: detail must be chosen in "0", "1", "2", "3" or "canal". -#' If missing "0" will be chosen.} +#' \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{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.} #' } #' } #' @@ -87,7 +100,8 @@ map_so_ii = function( 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( @@ -229,36 +243,41 @@ 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 (!missing(dataset)) plot(dataset[["geometry"]], add = TRUE, ...) 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/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 6543883e2d84f1edd800e91656817cc05e172759..1f525ed2f3d8b9fc658d96f87672f73fe84a3e6c 100644 --- a/geau/man/map_so_ii.Rd +++ b/geau/man/map_so_ii.Rd @@ -46,12 +46,25 @@ Plot a thematic map of so-ii \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.} -\item{\strong{collectivity}: detail must be chosen in "none", "syble", "symbo", -"epci" or "syndicate". If missing "none" will be chosen.} -\item{\strong{hydro}: detail must be chosen in "0", "1", "2", "3" or "canal". -If missing "0" will be chosen.} +\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{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.} } } } 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/script/topage.R b/script/topage.R new file mode 100644 index 0000000000000000000000000000000000000000..86e617b727536ae1590b49e905e76f5fc5a49c52 --- /dev/null +++ b/script/topage.R @@ -0,0 +1,17 @@ +# Functions + +# Data +library(geau) +library(sf) + +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)