diff --git a/geau/R/data.r b/geau/R/data.r index 0dd80478d6416359ac78e29a856f923ebfd89baf..014c91020381b3f21c6565e03932b946e402674a 100644 --- a/geau/R/data.r +++ b/geau/R/data.r @@ -71,4 +71,12 @@ #' 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" diff --git a/geau/R/map_so_ii.r b/geau/R/map_so_ii.r index d3c31628e23686f655a0cfddb3b3a5036007f737..3d434ef9f3b8587b942d7dc306e40a81340a3a1f 100644 --- a/geau/R/map_so_ii.r +++ b/geau/R/map_so_ii.r @@ -6,12 +6,13 @@ #' @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 hydro_detail character, the niveau of detail in the representation of the hydrographic network +#' @param detail character, detail for theme, depends on theme #' @param ... some parameters that will be used by plot (from sf) #' #' @return Nothing useful. #' -#' @details hydro_detail takes values "1", "2", "3" or "canal" +#' @details +#' For theme "hydro" detail takes values "1", "2", "3" or "canal" #' #' @export #' @@ -27,13 +28,14 @@ map_so_ii = function( dataset, dataset_legend = NULL, - theme = c("clc", "gaspar", "hydro"), + theme = c("", "clc", "gaspar", "hydro"), bar = TRUE, path = NULL, gaspar_year, - hydro_detail, + detail, ... ) { + theme = match.arg(theme) if (!is.null(path)) { switch( @@ -79,28 +81,23 @@ map_so_ii = function( } if ("hydro" %in% theme) { - if(missing(hydro_detail)) { - hydro_detail = "0" + if (missing(detail)) { + detail = "0" } - - if(hydro_detail == "canal") { + detail = match.arg(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) - so_ii_hydro_toplot = geau::so_ii_hydro[["geometry"]][geau::so_ii_hydro[["degre"]] == hydro_detail] lwd = 1 } else { - #color = "#dbe8f0" + selection = geau::so_ii_hydro[["degre"]] <= detail + geometry = geau::so_ii_hydro[["geometry"]][] color = scales::alpha("blue", .3) - so_ii_hydro_toplot = geau::so_ii_hydro[["geometry"]][geau::so_ii_hydro[["degre"]] <= hydro_detail] - lwd = 4 - as.numeric(geau::so_ii_hydro[["degre"]][geau::so_ii_hydro[["degre"]] <= hydro_detail]) - + lwd = 4 - as.numeric(geau::so_ii_hydro[["degre"]][selection]) } - plot( - so_ii_hydro_toplot, - col = color, - lwd = lwd, - add=TRUE - ) + plot(geometry, col = color, lwd = lwd, add = TRUE) } plot(dataset[["geometry"]], add = TRUE, ...) diff --git a/geau/data-raw/so_ii_hydro.R b/geau/data-raw/so_ii_hydro.R index 13ddf91fed723182344e14b89919778bc5fbb671..f86ebcc6ce1f13d0132d128dbdd3bc66a4b9f3d5 100644 --- a/geau/data-raw/so_ii_hydro.R +++ b/geau/data-raw/so_ii_hydro.R @@ -1,22 +1,23 @@ # code to prepare `so_ii_hydro` dataset goes here -selection = c("gid", "CdOH", "TopoOH") -version = current_version("data-common/so-ii/topage", - pattern = "^[0-9]") -so_ii_hydro = sf::st_read(file.path(version, "cours-eau-so-ii.shp"))[selection] -so_ii_hydro = sf::st_transform(so_ii_hydro, sf::st_crs(geau::so_ii_limit)) +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") -classif_hydro = read.csv2( +classification = read.csv2( current_version("data-common/so-ii/topage", pattern = "courseau"), - colClasses = "character", - row.names = 1 -) + colClasses = "character" +)[c("id", "name", "degre")] -so_ii_hydro = merge( - so_ii_hydro, classif_hydro, - by.x = selection, - by.y = c("id_1", "id_2", "cours_eau") - ) +so_ii_hydro = merge(so_ii_hydro, classification) # updating datasets diff --git a/geau/data/so_ii_hydro.rda b/geau/data/so_ii_hydro.rda index d7b18197ef9580478c0fa5aba971f38cbc896979..07c507b7dee470b6d8fdfe7c38fb9ca8a8a4ee90 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 118e7364f46086f91332be470f91fd97b6d03e80..be4ec5f6d5b5e1fe3de12c5c299187e75fdf1f31 100644 --- a/geau/man/map_so_ii.Rd +++ b/geau/man/map_so_ii.Rd @@ -8,10 +8,11 @@ map_so_ii( dataset, dataset_legend = NULL, - theme = c("clc", "gaspar"), + theme = c("", "clc", "gaspar", "hydro"), bar = TRUE, path = NULL, gaspar_year, + detail, ... ) } @@ -28,6 +29,8 @@ map_so_ii( \item{gaspar_year}{character, the year chosen for gaspar theme} +\item{detail}{character, detail for theme, depends on theme} + \item{...}{some parameters that will be used by plot (from sf)} } \value{ @@ -36,6 +39,9 @@ Nothing useful. \description{ Plot a thematic map of so-ii } +\details{ +For theme "hydro" detail takes values "1", "2", "3" or "canal" +} \examples{ \dontrun{ 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}