Commit 342bb4e5 authored by Grelot Frederic's avatar Grelot Frederic :swimmer_tone5:
Browse files

Ajout des fonctions pour les cartes et documentation des données

Showing with 139 additions and 0 deletions
+139 -0
#' @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)
)
}
geau/R/data.r 0 → 100644
#' 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
File moved
#' @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
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment