diff --git a/geau/R/current_version.r b/geau/R/current_version.r new file mode 100644 index 0000000000000000000000000000000000000000..bbff4ecacd9e95ed120fce1887312668e5b54e01 --- /dev/null +++ b/geau/R/current_version.r @@ -0,0 +1,25 @@ +#' @title Find the current version of some data +#' +#' @param path character path to a directory where to find data +#' @param ... some extra parameters that will be passed to dir(path, ...) +#' +#' @return character path of the file corresponding the current version of the data +#' +#' @export +#' +#' @encoding UTF-8 +#' @author Frédéric Grelot +#' +#' @examples +#' +#' \dontrun{ +#' # To be added (soon) +#' } + +current_version = function(path, ...) { + path = as.character(path)[1] + file.path( + path, + utils::head(sort(dir(path, ...), decreasing = TRUE), 1) + ) +} diff --git a/geau/R/data.r b/geau/R/data.r new file mode 100644 index 0000000000000000000000000000000000000000..63f3ababe02f537f00681a7cc588d366f512c1ad --- /dev/null +++ b/geau/R/data.r @@ -0,0 +1,49 @@ +#' Local collectivities included in so-ii +#' +#' A dataset containing the INSEE code of all local collectivities +#' (communes) included in so-ii +#' +#' @format a vector of 69 INSEE code +"so_ii_scope" + +#' List of all collectivities included in so-ii +#' +#' A dataset containing the INSEE code of all local collectivities +#' included in so-ii +#' +#' Basically this dataset is obtained as a selection from the layer +#' COMMUNE in ADMIN EXPRESS, more a renaming of variables. +#' +#' @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} +#' \{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} +#' } +#' @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)} +#' +#' @format sfc_POLYGON of length 1 +"so_ii_limit" + +#' CLC information for so-ii +#' +#' A dataset containing the Corine Land Cover information on so-ii. +#' +#' @format sf data.frame 1337 rows, 2 variables +#' \describe{ +#' \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 diff --git a/geau/R/kable_units.R b/geau/R/kable_units.r similarity index 100% rename from geau/R/kable_units.R rename to geau/R/kable_units.r diff --git a/geau/R/map_so_ii.r b/geau/R/map_so_ii.r new file mode 100644 index 0000000000000000000000000000000000000000..df6a9a27eb8b19abec0303a63ae8bd2f15932ce3 --- /dev/null +++ b/geau/R/map_so_ii.r @@ -0,0 +1,65 @@ +#' @title Plot a thematic map of so-ii +#' +#' @param dataset sf objectf, data to be plotted +#' @param dataset_legend list of parameters to be passed to legend +#' @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 ... some parameters that will be used by plot (from sf) +#' +#' @return Nothing useful. +#' +#' @export +#' +#' @encoding UTF-8 +#' @author Frédéric Grelot +#' +#' @examples +#' +#' \dontrun{ +#' # To be added (soon) +#' } + +map_so_ii = function(dataset, dataset_legend = NULL, theme = "clc", bar = TRUE, path = NULL, ...) { + + if (!is.null(path)) { + switch( + EXPR = tolower(tools::file_ext(path)), + "pdf" = grDevices::pdf(path), + "png" = grDevices::png(path), + stop(sprintf("%s not recognized", tolower(tools::file_ext(path)))) + ) + } + + ## 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( + geau::so_ii_clc[["geometry"]], + border = NA, + col = geau::so_ii_clc[["color"]], + add = TRUE + ) + } + + plot(dataset[["geometry"]], add = TRUE, ...) + + if (bar == TRUE) { + terra::sbar(10, c(3.55, 43.47), type = "bar", below = "km", label = c(0, 5, 10), cex = .8) + } + + if (!is.null(dataset_legend)) { + dataset_legend = c( + x = "bottomright", + cex = .8, + bg = "white", + inset = 0.01, + dataset_legend) + do.call(graphics::legend, dataset_legend) + } + + if (!is.null(path)) invisible(grDevices::dev.off()) +} \ No newline at end of file