Commit 20cde0d8 authored by Grelot Frederic's avatar Grelot Frederic :swimmer_tone5:
Browse files

Merge branch 'master' into map_production

Showing with 959 additions and 225 deletions
+959 -225
...@@ -8,11 +8,11 @@ devtools::build_vignettes(package) ...@@ -8,11 +8,11 @@ devtools::build_vignettes(package)
# devtools::run_examples(package) # devtools::run_examples(package)
### Checks ### Checks
# system("mv ~/.Rprofile ~/.Rprofile-temp");devtools::check(package);system("mv ~/.Rprofile-temp ~/.Rprofile") # system("mv ~/.Rprofile ~/.Rprofile-temp");devtools::check(package);system("mv ~/.Rprofile-temp ~/.Rprofile") # nolint
### Build ### Build
devtools::build(package, path = "library", vignettes = TRUE) devtools::build(package, path = "library", vignettes = TRUE)
### install -> sudo ### install -> sudo
# devtools::install_local(package) # devtools::install_local(package)
sudo su - -c "R -e \"devtools::install_gitlab('geau-inondation/geau-utility', subdir = 'geau', host = 'gitlab.irstea.fr', upgrade = 'never', auth_token = 'rCEfcrjoms9UNykCuM5c')\"" sudo su - -c "R -e \"devtools::install_gitlab('geau-inondation/geau-utility', subdir = 'geau', host = 'gitlab.irstea.fr', upgrade = 'never', auth_token = 'rCEfcrjoms9UNykCuM5c')\"" # nolint
\ No newline at end of file \ No newline at end of file
Package: geau Package: geau
Title: Utilities very useful to share within geau-inondation team Title: Utilities very useful to share within geau-inondation team
Version: 1.0.3.0 Version: 1.0.15.0
Authors@R: Authors@R:
c( c(
person(given = "Frédéric", person(given = "Frédéric",
...@@ -23,6 +23,7 @@ LazyData: true ...@@ -23,6 +23,7 @@ LazyData: true
Imports: Imports:
kableExtra, kableExtra,
knitr, knitr,
readODS,
rio, rio,
scales, scales,
sf, sf,
......
...@@ -3,5 +3,6 @@ ...@@ -3,5 +3,6 @@
export(add.inset) export(add.inset)
export(current_version) export(current_version)
export(estimate_catnat_freq) export(estimate_catnat_freq)
export(format_presence)
export(kable_units) export(kable_units)
export(map_so_ii) export(map_so_ii)
#' Local collectivities included in so-ii #' Color and label for CLC
#' #'
#' A dataset containing the INSEE code of all local collectivities #' A dataset proposing default colors and labels for plotting CLC
#' (communes) included in so-ii
#' #'
#' @format a vector of 69 INSEE code #' @format data.frame 5 rows, 3 variables
"so_ii_scope" "clc_color"
#' List of all collectivities included in so-ii #' Catchment areas of interest within the so-ii perimeter
#'
#' 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 #' A dataset containing the official catchments areas of interest from the BD
#' COMMUNE in ADMIN EXPRESS, more a renaming of variables. #' 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 69 rows, 7 variables #' @format sf data.frame 15 rows, 4 variables
#' \describe{ #' \describe{
#' \item{id}{id, from IGN ADMIN EXPRESS} #' \item{id}{id, from BD TOPAGE (corresponding to CdOh) or NA when catchment
#' \item{commune}{character, official name of the commune} #' is constructed by so-ii team.}
#' \item{commune_majuscule}{character, official capitalized name of the #' \item{name}{character, name of the catchment area in BD TOPAGE, or given
#' commune} #' name for catchments constructed by so-ii team.}
#' \item{code}{character, INSEE code of the commune} #' \item{degre}{factor, importance of the catchment used to plot the
#' \item{statut}{character, statut of the commune} #' catchment areas with different levels of detail ("1", "2", "3").}
#' \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/} #' @source \url{http://bdtopage.eaufrance.fr/page/objectifs}
"so_ii_commune" "so_ii_catchment"
#' Spatial perimeter of so-ii #' Number of Cat Nat events for the municipalities of so-ii
#' #'
#' A dataset containing the perimeter of so-ii. #' A dataset containing the number of Cat Nat events (linked to flood) by year
#' and so-ii municipality according to the GASPAR database.
#' #'
#' Basically, this dataset is obtained as #' @format array with 3 dimensions
#' \code{sf::st_union(so_ii_commune)} #' \describe{
#' \item{first}{commune as in so_ii_scope}
#' \item{second}{year of Cat Nat events}
#' \item{third}{type of hazard}
#' }
#' #'
#' @format sfc_POLYGON of length 1 #' @source \url{https://www.georisques.gouv.fr/donnees/bases-de-donnees/base-gaspar} # nolint
"so_ii_limit" "so_ii_catnat"
#' CLC information for so-ii #' CLC information for so-ii
#' #'
...@@ -48,62 +49,140 @@ ...@@ -48,62 +49,140 @@
#' \item{clc_2018}{character, classification from CLC 2018} #' \item{clc_2018}{character, classification from CLC 2018}
#' \item{color}{character, default color to be used to plot so_ii_clc} #' \item{color}{character, default color to be used to plot so_ii_clc}
#' } #' }
"so_ii_limit" "so_ii_clc"
#' Population for so-ii #' Spatial definition of collectivities included in so-ii
#' #'
#' A dataset containing the population of commune in so-ii according to INSEE. #' 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.
#' #'
#' @format numeric matrix #' @format sf data.frame 78 rows, 11 variables
#' \describe{ #' \describe{
#' \item{row}{commune as in so_ii_scope} #' \item{commune_name}{character, INSEE code of the collectivity}
#' \item{column}{year} #' \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.insee.fr/fr/statistiques/2522602} #' @source \url{https://www.data.gouv.fr/fr/datasets/admin-express/}
"so_ii_population" "so_ii_collectivity"
#' Number of Cat Nat events for the municipalities of so-ii #' Hydrographic network within the so-ii perimeter
#' #'
#' A dataset containing the number of Cat Nat events (linked to flood) by year #' A dataset containing the official hydrographic network from the BD TOPAGE
#' and so-ii municipality according to the GASPAR database. #' within the so-ii perimeter.
#' #'
#' @format array with 3 dimensions #' @format sf data.frame 125 rows, 4 variables
#' \describe{ #' \describe{
#' \item{first}{commune as in so_ii_scope} #' \item{id}{id, from BD TOPAGE (corresponding to CdOh)}
#' \item{second}{year of Cat Nat events} #' \item{name}{character, name of the hydrographic elements in the BD TOPAGE}
#' \item{third}{type of hazard} #' \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{https://www.georisques.gouv.fr/donnees/bases-de-donnees/base-gaspar} # nolint #' @source \url{http://bdtopage.eaufrance.fr/page/objectifs}
"so_ii_catnat" "so_ii_hydro"
#' CLC information for so-ii #' Spatial perimeter of so-ii
#' #'
#' A dataset containing the 2018 version of CLC information for so-ii #' A dataset containing the perimeter of so-ii.
#' #'
#' @format sf object #' Basically, this dataset is obtained as
"so_ii_clc" #' \code{sf::st_union(so_ii_commune)}
#'
#' @format sfc_POLYGON of length 1
"so_ii_limit"
#' Color and label for CLC #' Spatial definition of districts of Montpellier city
#' #'
#' A dataset proposing default colors and labels for plotting CLC #' A dataset containing the spatial definition of all districts
#' for Montpellier.
#' #'
#' @format data.frame 5 rows, 3 variables #' @format sf data.frame 31 rows, 2 variables
"clc_color" #' \describe{
#' \item{district}{character, id of each district as given by montpellier3m}
#' \item{district_name}{character, name of each district}
#' \item{district_group}{character, how districts are grouped by montpellier3m}
#' }
#'
#' @source \url{https://data.montpellier3m.fr/dataset/sous-quartiers-de-montpellier}
"so_ii_montpellier"
#' Hydrographic network within the so-ii perimeter #' Local collectivities included in so-ii
#' #'
#' A dataset containing the official hydrographic network from the BD TOPAGE #' A dataset containing the INSEE code of all local collectivities
#' within the so-ii perimeter. #' (communes) included in so-ii
#' #'
#' @format sf data.frame 125 rows, 4 variables #' @format a vector of 78 INSEE code
"so_ii_scope"
#' ONRN information for so-ii
#'
#' A dataset containing part of the information available at the ONRN for so-ii
#' communities. The information chosen is exclusively related to floods. It is
#' mainly related to impacts and therefore to the claims in from the Cat-Nat
#' system. These data on claims are taken from the CCR, the others from the
#' gaspar database.
#'
#' @format data.frame 78 rows, 23 variables
#' \describe{ #' \describe{
#' \item{id}{id, from BD TOPAGE (corresponding to CdOh)} #' \item{n_catnat}{Number of Cat Nat events}
#' \item{name}{character, name of the river or part of the river in BD #' \item{freq_sin}{Number of claims divided by number of contracts
#' TOPAGE} #' for 1995 to 2018. freq_sin is calculated as the mean of freq_sin_min
#' \item{degre}{character, level of detail to plot the hydrographic network} #' and freq_sin_max (range for each category).}
#' \item{cost}{Cumulative cost of claims for 1995 to 2018. Cost is calculated
#' as the mean of cost_min and cost_max (range for each category).}
#' \item{cost_mean}{Mean cost of claims (cost divided by claims) for 1995 to
#' 2018. cost_mean is calculated as the mean of cost_mean_min and
#' cost_mean_max (range for each category).}
#' \item{cost_hab}{Cost divided by the population for 1995 to 2018. cost_hab
#' is calculated as the mean of cost_hab_min and cost_hab_max (range for
#' each category).}
#' \item{ratio}{Cost divided by premium for 1995 to 2018. ratio is calculated
#' as the mean of cost_hab_min and cost_hab_max (range for each
#' category).}
#' \item{balance}{Cost minus premium for 1995 to 2018. This is an estimation
#' made by so-ii team by considering a mean premium for each habitant
#' of 24.92829 euro per habitant (total premium in 2018 divided by
#' total population)}
#' \item{ppri_year}{Year given for the last PPRI.}
#' \item{ppri_state}{State of the last PPRI.}
#' \item{ppri_state_sub}{Some details on the state of the last PPRI.}
#' \item{ppri_state_age}{State of the last PPRI for age information.}
#' \item{ppri_age_min}{Lower boundary for the age of the PPRI.}
#' \item{ppri_age_min}{Upper boundary for the age of the PPRI..}
#' } #' }
#' #'
#' @source \url{http://bdtopage.eaufrance.fr/page/objectifs} #' @source \url{https://www.georisques.gouv.fr/articles-risques/acceder-aux-indicateurs-sinistralite}
"so_ii_hydro" "so_ii_onrn"
\ No newline at end of file
#' Population for so-ii
#'
#' A dataset containing the population of commune in so-ii according to INSEE.
#'
#' @format numeric matrix 78 rows, 33 columns
#' \describe{
#' \item{row}{commune as in so_ii_scope}
#' \item{column}{year}
#' }
#'
#' @source \url{https://www.insee.fr/fr/statistiques/2522602}
"so_ii_population"
\ No newline at end of file
#' @title Transform ods table presence in md table (for Mattermost)
#'
#' @param x character or data.frame, path of the ods table or the table itself
#'
#' @return character, md version of table behind x.
#'
#' @export
#'
#' @encoding UTF-8
#' @author Frédéric Grelot
format_presence = function(x) {
result = if (is.character(x)) readODS::read_ods(x[1]) else x
result[] = lapply(result, gsub, pattern = "B", replacement = "**B**")
result[] = lapply(result, gsub, pattern = "C", replacement = "*C*")
knitr::kable(result, align = c("l", rep("c", length(result) - 1)))
}
#' @title Plot a thematic map of so-ii #' @title Plot a thematic map of so-ii
#' #'
#' @details #' @details
#' For theme "catnat", detail must be chosen in c("inondation", "submersion", #' \subsection{theme specification}{
#' "nappe"). #' For the specification of detail, it depends on the theme chosen.
#' For theme "hydro" detail must be chosen in "0", "1", "2", "3" or "canal". #' \itemize{
#' #' \item{\strong{none}: perimeter of so_ii is plotted.}
#' \item{\strong{catchment}: The area of catchments are plotted with a scope
#' depending on detail. At least, a division between Lez and
#' Bassin de l'Or is plotted.}
#' \item{\strong{catnat}: Informations on the number of "Arrêtés Cat
#' Nat are provided at the scale of collectivities."}
#' \item{\strong{collectivty}: Boundaries of collectivities are plotted, more
#' some administrative informations depending on detail.}
#' \item{\strong{hydro}: The hydrophic network is plotted. Depending on
#' detail, only a part (rivers, canals, water bodies) or a degre of detail
#' is plotted.}
#' \item{\strong{onrn}: Informations on the claims coming from Cat Nat system
#' are plotted at the scale of the collectivities. With detail a selection
#' of the data is made, with year a selection of the period.}
#' \item{\strong{osm}: A tile from OSM is plotted.}
#' \item{\strong{population}: Informations on the population coming from
#' INSEE are plotted at the scale of the collectivities. With year a
#' selection of the period is made, with detail a selection of how
#' evolution between 2 years.}
#' }
#' }
#' \subsection{detail specification}{
#' For the specification of detail, it depends on the theme chosen.
#' \itemize{
#' \item{\strong{catchment}: detail must be chosen in "none", "1", "2", "3"
#' for levels of detail. If missing, "1" 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.}
#' \item{\strong{onrn}: detail must be chosen in "n_catnat", "freq_sin",
#' "cost", "cost_hab", "cost_mean", "ratio", "balance", "ppri_year".}
#' \item{\strong{population}: detail must be chosen in "absolute",
#' "relative". It used only when more than one year is provided to plot
#' aither absolute or relative evolution.}
#' }
#' }
#' \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 2 or more
#' years are given, the sum of the period corresponding to the range of
#' given years is plotted. If missing, the whole available period is
#' plotted.}
#' \item{\strong{population}: year corresponds to the year of data. If
#' missing, last available year is plotted. If 2 or more years are
#' provided an analysis of the evolution between the range of given
#' years is plotted.}
#' }
#' }
#' \subsection{path specification}{
#' Depending on the extension a device is chosen.
#' \itemize{
#' \item{\strong{pdf}: grDevices::cairo_pdf}
#' \item{\strong{png}: grDevices::png}
#' \item{\strong{svg}: grDevices::svg}
#' }
#' If path is NULL, standard plotting is used. If an extension is not managed,
#' an error is raised.
#' }
#'
#' @param dataset sf objectf, data to be plotted #' @param dataset sf objectf, data to be plotted
#' @param dataset_legend list of parameters to be passed to legend #' @param dataset_legend list of parameters to be passed to legend
#' @param theme character, choice for the theme (if any) #' @param theme character, choice for the theme (if any). See details.
#' @param theme_legend logical, should a legend be plotted for the theme
#' @param detail character, detail for theme, depends on theme. See details.
#' @param year character, the year chosen for some themes. See details.
#' @param bar logical, should a bar be plotted for the dataset #' @param bar logical, should a bar be plotted for the dataset
#' @param path character, the name of the file to save the plot #' @param path character, the name of the file to save the plot. Graphical
#' @param legend_theme logical, should a legend be plotted for the theme #' device is chosen depending on extension. See details.
#' @param year character, the year chosen for some themes (catnat, population)
#' @param detail character, detail for theme, depends on theme
#' @param ... some parameters that will be used by plot (from sf) #' @param ... some parameters that will be used by plot (from sf)
#' #'
#' @return Nothing useful. #' @return Nothing useful.
#' #'
#' @export #' @export map_so_ii
#' #'
#' @encoding UTF-8 #' @encoding UTF-8
#' @author Frédéric Grelot #' @author Frédéric Grelot
#' @author David Nortes Martinez
#' #'
#' @examples #' @examples
#' #'
...@@ -31,12 +99,12 @@ ...@@ -31,12 +99,12 @@
map_so_ii = function( map_so_ii = function(
dataset, dataset,
dataset_legend = NULL, dataset_legend = NULL,
theme = c("none", "clc", "catnat", "hydro", "population"), theme = c("none", "collectivity", "catchment", "catnat", "clc", "hydro", "onrn", "osm", "population"),
theme_legend = FALSE,
detail,
year,
bar = TRUE, bar = TRUE,
path = NULL, path = NULL,
legend_theme = FALSE,
year,
detail,
... ...
) { ) {
theme = match.arg(theme) theme = match.arg(theme)
...@@ -44,8 +112,9 @@ map_so_ii = function( ...@@ -44,8 +112,9 @@ map_so_ii = function(
if (!is.null(path)) { if (!is.null(path)) {
switch( switch(
EXPR = tolower(tools::file_ext(path)), EXPR = tolower(tools::file_ext(path)),
"pdf" = grDevices::pdf(path), "pdf" = grDevices::cairo_pdf(path),
"png" = grDevices::png(path), "png" = grDevices::png(path),
"svg" = grDevices::svg(path),
stop(sprintf("%s not recognized", tolower(tools::file_ext(path)))) stop(sprintf("%s not recognized", tolower(tools::file_ext(path))))
) )
on.exit(grDevices::dev.off()) on.exit(grDevices::dev.off())
...@@ -53,52 +122,497 @@ map_so_ii = function( ...@@ -53,52 +122,497 @@ map_so_ii = function(
## Init map ## Init map
graphics::par(mai = c(.65, .60, .50, .15)) graphics::par(mai = c(.65, .60, .50, .15))
plot(geau::so_ii_limit, axes = TRUE) plot(geau::so_ii_limit, axes = TRUE, main = list(...)[["main"]], cex.main = 3)
if ("clc" %in% theme) { ## Plot theme if any, return theme_legend
plot( theme_legend = switch(
geau::so_ii_clc[["geometry"]], EXPR = theme,
border = NA, "catchment" = map_theme_catchment(detail, theme_legend),
col = geau::so_ii_clc[["color"]], "catnat" = map_theme_catnat(detail, year, theme_legend),
add = TRUE "clc" = map_theme_clc(theme_legend),
"collectivity" = map_theme_collectivity(detail, theme_legend),
"hydro" = map_theme_hydro(detail, theme_legend),
"onrn" = map_theme_onrn(detail, theme_legend),
"osm" = map_theme_osm(),
"population" = map_theme_population(detail, year, theme_legend),
NULL
)
## Plot dataset if any
if (!missing(dataset)) plot(dataset[["geometry"]], add = TRUE, ...)
## Make so_ii_limit visible
plot(geau::so_ii_limit, lwd = 2, add = TRUE)
## Plot bar
if (bar == TRUE) {
terra::sbar(
10, c(3.55, 43.47),
type = "bar",
below = "km",
label = c(0, 5, 10),
cex = .8
) )
}
theme_legend = list( ## Plotdataset_legend if any
title = "CLC (2018)", if (!is.null(dataset_legend)) {
legend = geau::clc_color[["label_fr"]], dataset_legend = c(
x = "topright", x = "bottomright",
cex = .8, cex = .8,
bg = "white", bg = "white",
inset = 0.01, inset = 0.01,
fill = geau::clc_color[["color"]] dataset_legend)
) do.call(graphics::legend, dataset_legend)
} }
if ("population" %in% theme) { ## Plot theme_legend if any
if (missing(year)) { if (!is.null(theme_legend)) {
year = utils::tail(sort(colnames(geau::so_ii_population)), 1) if (!is.null(theme_legend[["text.width"]])) {
text_legend = theme_legend[["legend"]]
theme_legend[["legend"]] = rep("", length(text_legend))
}
temp = do.call(graphics::legend, theme_legend)
if (!is.null(theme_legend[["text.width"]])) {
graphics::text(
x = temp[["rect"]][["left"]] + temp[["rect"]][["w"]],
y = temp[["text"]][["y"]],
labels = text_legend,
pos = 2
)
} }
population_palette = scales::colour_ramp(c("white", "red"), alpha = .5) }
return(invisible(NULL))
}
map_theme_catchment = function(detail, add_legend) {
if (missing(detail)) {
detail = "1"
}
detail = match.arg(
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"
lwd = 2
theme_legend = list(
title = sprintf("Bassin versant"),
legend = levels(catchment),
x = "topright",
cex = .8,
bg = "white",
inset = 0.01,
fill = color_legend,
border = border
)
plot(geometry, border = border, col = color, lwd = lwd, add = TRUE)
if (add_legend == TRUE && detail != "3") {
return(theme_legend)
} else {
return(NULL)
}
}
map_theme_catnat = function(detail, year, add_legend) {
if (missing(detail)) {
detail = dimnames(geau::so_ii_catnat)[["hazard"]]
}
detail = match.arg(
detail,
dimnames(geau::so_ii_catnat)[["hazard"]],
several.ok = TRUE
)
if (missing(year)) {
year = range(dimnames(geau::so_ii_catnat)[["period"]])
}
year = match.arg(
as.character(year),
dimnames(geau::so_ii_catnat)[["period"]],
several.ok = TRUE
)
year = as.character(seq(min(year), max(year)))
catnat = apply(
geau::so_ii_catnat[, year, detail, drop = FALSE],
1,
sum
)
border = "grey80"
catnat_palette = scales::colour_ramp(c("white", "grey50"), alpha = .5)
color = scales::cscale(
c(0, catnat),
catnat_palette
)[-1]
plot(
geau::so_ii_collectivity[["geometry"]],
border = border,
col = color,
add = TRUE
)
legend_title = sprintf(
"Cat Nat %s",
if (length(detail) == 3) "" else paste(sort(detail), collapse = " & ")
)
legend_title = sprintf(
"%s [%s]",
legend_title,
if (length(year) == 1) year else paste(range(year), collapse = "-")
)
value_legend = unique(sort(c(min(catnat), round(seq(0, max(catnat), length.out = 5)))))
color_legend = scales::cscale(
value_legend,
catnat_palette
)
theme_legend = list(
title = legend_title,
legend = value_legend,
x = "topright",
cex = .8,
bg = "white",
inset = 0.01,
fill = color_legend,
border = border,
text.width = max(graphics::strwidth(value_legend))
)
if (add_legend == TRUE) {
return(theme_legend)
} else {
return(NULL)
}
}
map_theme_clc = function(add_legend) {
plot(
geau::so_ii_clc[["geometry"]],
border = NA,
col = geau::so_ii_clc[["color"]],
add = TRUE
)
theme_legend = list(
title = "CLC (2018)",
legend = geau::clc_color[["label_fr"]],
x = "topright",
cex = .8,
bg = "white",
inset = 0.01,
fill = geau::clc_color[["color"]]
)
if (add_legend == TRUE) {
return(theme_legend)
} else {
return(NULL)
}
}
map_theme_collectivity = function(detail, add_legend) {
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 (add_legend == TRUE) {
return(theme_legend)
} else {
return(NULL)
}
}
map_theme_hydro = function(detail, add_legend) {
if (missing(detail)) {
detail = "none"
}
detail = match.arg(
as.character(detail),
choices = c(
"none",
levels(geau::so_ii_hydro[["degre"]]),
levels(geau::so_ii_hydro[["type"]])
)
)
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 = "\u00e9l\u00e9ment du r\u00e9seau",
x = "topright",
cex = .8,
bg = "white",
inset = 0.01,
col = color,
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 (add_legend == TRUE) {
return(theme_legend)
} else {
return(NULL)
}
}
map_theme_onrn = function(detail, add_legend) {
if (missing(detail)) {
detail = "cost"
}
detail = match.arg(
as.character(detail),
sort(colnames(geau::so_ii_onrn)[1:8])
)
onrn_palette = switch(
EXPR = detail,
"n_catnat" = scales::colour_ramp(c("white", "red"), alpha = .5),
"freq_sin" = scales::colour_ramp(c("white", "red"), alpha = .5),
"cost" = scales::colour_ramp(c("white", "red"), alpha = .5),
"cost_hab" = scales::colour_ramp(c("white", "red"), alpha = .5),
"cost_mean" = scales::colour_ramp(c("white", "red"), alpha = .5),
"ratio" = scales::colour_ramp(c("green", "white", "red"), alpha = .5),
"balance" = scales::colour_ramp(c("red", "white", "green"), alpha = .5),
"ppri_year" = scales::colour_ramp(c("grey80", "grey50"), alpha = .5),
NULL
)
onrn_trans = switch(
EXPR = detail,
"n_catnat" = scales::identity_trans(),
"freq_sin" = scales::identity_trans(),
"cost" = scales::sqrt_trans(),
"cost_hab" = scales::sqrt_trans(),
"cost_mean" = scales::sqrt_trans(),
"ratio" = scales::sqrt_trans(),
"balance" = scales::modulus_trans(.5),
"ppri_year" = scales::identity_trans(),
NULL
)
onrn_range = switch(
EXPR = detail,
"ratio" = c(0, 4),
"balance" = max(abs(range(geau::so_ii_onrn[["balance"]]))) * c(-1, 1),
NULL
)
color = scales::cscale(
c(onrn_range, geau::so_ii_onrn[[detail]]),
onrn_palette,
trans = onrn_trans)
if (length(onrn_range) > 0) {
color = color[-seq(onrn_range)]
}
border = "grey80"
plot(
geau::so_ii_collectivity[["geometry"]],
border = border,
col = color,
add = TRUE
)
if (sprintf("%s_min", detail) %in% names(geau::so_ii_onrn)) {
selection = c(detail, sprintf("%s_min", detail), sprintf("%s_max", detail))
temp = unique(geau::so_ii_onrn[selection])
temp = temp[order(temp[[detail]]), ]
text_legend = gsub("0 - 0", "0",
sprintf(
"%s - %s",
temp[[sprintf("%s_min", detail)]],
temp[[sprintf("%s_max", detail)]]
)
)
value_legend = temp[[detail]]
}
if (detail %in% c("n_catnat", "ppri_year")) {
value_legend = round(
seq(
min(geau::so_ii_onrn[[detail]], na.rm = TRUE),
max(geau::so_ii_onrn[[detail]], na.rm = TRUE),
length.out = 5
)
)
text_legend = value_legend
}
if (detail %in% c("balance")) {
value_legend = unique(
c(
seq(min(geau::so_ii_onrn[[detail]]), 0, length.out = 4),
seq(0, max(geau::so_ii_onrn[[detail]]), length.out = 4)
)
)
text_legend = formatC(
as.integer(signif(round(value_legend), 2)),
big.mark = " "
)
text.width = max(graphics::strwidth(text_legend))
}
color_legend = scales::cscale(
c(onrn_range, value_legend),
onrn_palette,
trans = onrn_trans
)
if (length(onrn_range) > 0) {
color_legend = color_legend[-seq(onrn_range)]
}
title_onrn = switch(
EXPR = detail,
"n_catnat" = "Arr\u00eat\u00e9s Cat-Nat [1982-2021]",
"freq_sin" = "Sinistre / Risque [1995-2018]",
"cost" = "Co\u00fbt cumul\u00e9 (\u20AC) [1995-2018]",
"cost_hab" = "Co\u00fbt / hab (\u20ac) [1995-2018]",
"cost_mean" = "Co\u00fbt / sinistre (\u20ac) [1995-2018]",
"ratio" = "Co\u00fbt / Prime [1995-2018]",
"balance" = "Co\u00fbt - Prime (\u20ac) [1995-2018]",
"ppri_year" = "Ann\u00e9e des PPRI",
NULL
)
theme_legend = list(
title = title_onrn,
legend = text_legend,
x = "topright",
cex = .8,
bg = "white",
inset = 0.01,
fill = color_legend,
border = border
)
if (detail %in% c("balance", "cost")) {
theme_legend[["text.width"]] = max(graphics::strwidth(text_legend))
}
if (add_legend == TRUE) {
return(theme_legend)
} else {
return(NULL)
}
}
map_theme_osm = function() {
so_ii_osm = terra::rast(
system.file("extdata", "so_ii_osm.tif", package = "geau", mustWork = TRUE)
)
try(terra::plot(so_ii_osm, add = TRUE), silent = TRUE)
graphics::mtext(
text = "Fond de carte : \u00a9 Contributeurs OpenStreetMap",
side = 1, line = -1, adj = 1, cex = .6, font = 3
)
return(NULL)
}
map_theme_population = function(detail, year, add_legend) {
if (missing(year)) {
year = utils::tail(sort(colnames(geau::so_ii_population)), 1)
}
year = match.arg(
as.character(year),
sort(colnames(geau::so_ii_population)),
several.ok = TRUE
)
border = "grey80"
if (length(year) == 1) {
pop_palette = scales::colour_ramp(c("white", "red"), alpha = .5)
color = matrix( color = matrix(
scales::cscale( scales::cscale(
geau::so_ii_population, geau::so_ii_population,
population_palette, pop_palette,
trans = scales::log_trans()), trans = scales::log_trans()),
nrow = nrow(geau::so_ii_population), nrow = nrow(geau::so_ii_population),
dimnames = dimnames(geau::so_ii_population) dimnames = dimnames(geau::so_ii_population)
) )
border = "grey80"
plot( plot(
geau::so_ii_commune[["geometry"]], geau::so_ii_collectivity[["geometry"]],
border = border, border = border,
col = color[ , year], col = color[ , year],
add = TRUE add = TRUE
) )
max_pop = max(geau::so_ii_population[ , year])
min_pop = min(geau::so_ii_population[ , year])
base = 10
value_legend = c(100, 1000, 10000, 100000, 250000) value_legend = unique(c(
min_pop,
base^(ceiling(log(min_pop)/log(base)):floor(log(max_pop)/log(base))),
max_pop
))
color_legend = scales::cscale( color_legend = scales::cscale(
c(range(geau::so_ii_population), value_legend), c(range(geau::so_ii_population), value_legend),
population_palette, pop_palette,
trans = scales::log_trans() trans = scales::log_trans()
)[-(1:2)] )[-(1:2)]
text_legend = formatC( text_legend = formatC(
...@@ -108,129 +622,145 @@ map_so_ii = function( ...@@ -108,129 +622,145 @@ map_so_ii = function(
theme_legend = list( theme_legend = list(
title = sprintf("Population %s", year), title = sprintf("Population %s", year),
legend = rep("", length(text_legend)), legend = text_legend,
x = "topright", x = "topright",
cex = .8, cex = .8,
bg = "white", bg = "white",
inset = 0.01, inset = 0.01,
fill = color_legend, fill = color_legend,
border = border, border = border,
text.width = graphics::strwidth(utils::tail(text_legend, 1)) text.width = max(graphics::strwidth(text_legend))
) )
} }
if ("catnat" %in% theme) { if (length(year) > 1) {
if (missing(detail)) { if (missing(detail)) {
detail = dimnames(geau::so_ii_catnat)[["hazard"]] detail = "absolute"
}
detail = match.arg(
detail,
dimnames(geau::so_ii_catnat)[["hazard"]],
several.ok = TRUE
)
border = NA
color = NA
if (!missing(year)) {
border = "grey80"
catnat = apply(
geau::so_ii_catnat[, as.character(year), detail, drop = FALSE],
1:2,
sum
)
color = ifelse(
catnat > 0,
scales::alpha("grey80", .5),
NA
)
theme_legend = list(
title = sprintf("Cat-Nat %s", year),
legend = c("Sans d\u00e9claration", "Avec d\u00e9claration"),
x = "topright",
cex = .8,
bg = "white",
inset = 0.01,
fill = unique(color),
border = border
)
} }
detail = match.arg(as.character(detail), c("absolute", "relative"))
year = range(year)
pop_palette = scales::colour_ramp(
c("red", "white", "green"),
alpha = .5
)
pop_data = switch(
EXPR = detail,
"absolute" = geau::so_ii_population[ , year[2]] -
geau::so_ii_population[ , year[1]],
"relative" = (geau::so_ii_population[ , year[2]] -
geau::so_ii_population[ , year[1]]) /
geau::so_ii_population[ , year[1]]
)
range_data = max(abs(range(pop_data))) * c(-1, 1)
pop_trans = switch(
EXPR = detail,
"absolute" = scales::modulus_trans(0.2),
"relative" = scales::modulus_trans(0.1),
NULL
)
color = scales::cscale(
c(range_data, pop_data),
pop_palette,
trans = pop_trans
)[-(1:2)]
plot( plot(
geau::so_ii_commune[["geometry"]], geau::so_ii_collectivity[["geometry"]],
border = border, border = border,
col = color, col = color,
add = TRUE add = TRUE
) )
}
if ("hydro" %in% theme) { max_pop = max(pop_data)
if (missing(detail)) { min_pop = min(pop_data)
detail = "0"
} if (detail == "absolute") {
detail = match.arg( range_pop = max(abs(c(max_pop, min_pop)))
as.character(detail), base = max(10, 10^floor(ceiling(log(range_pop)/log(10)) / 2))
choices = c("0", "1", "2", "3", "canal")
) if (sign(min_pop) == -1) {
if (detail == "canal") { value_legend = c(
selection = geau::so_ii_hydro[["degre"]] == detail -base^(floor(log(abs(min_pop))/log(base)):1),
geometry = geau::so_ii_hydro[["geometry"]][selection] base^(1:floor(log(max_pop)/log(base)))
color = scales::alpha("red", .3) )
lwd = 1 value_legend = value_legend[
} else { value_legend < max_pop &
selection = geau::so_ii_hydro[["degre"]] <= detail value_legend > min_pop &
geometry = geau::so_ii_hydro[["geometry"]][selection] abs(value_legend) >= base
color = scales::alpha("blue", .3) ]
lwd = 4 - as.numeric(geau::so_ii_hydro[["degre"]][selection]) value_legend = sort(c(0, range(pop_data), value_legend))
} else {
value_legend = unique(c(
min_pop,
base^(ceiling(log(min_pop)/log(base)):floor(log(max_pop)/log(base))),
max_pop
))
}
color_legend = scales::cscale(
c(range_data, value_legend),
pop_palette,
trans = pop_trans
)[-(1:2)]
text_legend = formatC(
as.integer(value_legend),
big.mark = " "
)
title_legend = sprintf("Population \u00e9volution [%s-%s]", year[1], year[2])
} }
plot(geometry, col = color, lwd = lwd, add = TRUE) if (detail == "relative") {
max_pop = max(pop_data) * 100
min_pop = min(pop_data) * 100
range_pop = max(abs(c(max_pop, min_pop)))
base = max(10, 10^floor(ceiling(log(range_pop)/log(10)) / 2))
if (sign(min_pop) == -1) {
value_legend = unique(c(
min_pop,
-base^(floor(log(abs(min_pop))/log(base)):0),
0,
base^(0:floor(log(max_pop)/log(base))),
max_pop
))
} else {
value_legend = unique(c(
min_pop,
base^(ceiling(log(min_pop)/log(base)):floor(log(max_pop)/log(base))),
max_pop
))
}
color_legend = scales::cscale(
c(range_data, value_legend / 100),
pop_palette,
trans = pop_trans
)[-(1:2)]
text_legend = sprintf(
"%s %%",
formatC(
signif(value_legend, 3),
digits = 2, format = "f", flag = "+",
big.mark = " "
)
)
title_legend = sprintf("Population \u00e9volution [%s-%s]", year[1], year[2])
}
theme_legend = list( theme_legend = list(
title = sprintf("R\u00e9seau hydrographique"), title = title_legend,
legend = ifelse(detail == "canal", "canal", "cours d'eau"), legend = text_legend,
x = "topright", x = "topright",
cex = .8, cex = .8,
bg = "white", bg = "white",
inset = 0.01, inset = 0.01,
col = color, fill = color_legend,
lwd = 2 border = border,
) text.width = max(graphics::strwidth(text_legend))
}
if (!missing(dataset)) plot(dataset[["geometry"]], add = TRUE, ...)
plot(geau::so_ii_limit, lwd = 2, 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)) { if (add_legend == TRUE) {
dataset_legend = c( return(theme_legend)
x = "bottomright", } else {
cex = .8, return(NULL)
bg = "white",
inset = 0.01,
dataset_legend)
do.call(graphics::legend, dataset_legend)
}
if (legend_theme == TRUE && exists("theme_legend")) {
temp = do.call(graphics::legend, theme_legend)
if (exists("text_legend")) {
graphics::text(
x = temp[["rect"]][["left"]] + temp[["rect"]][["w"]],
y = temp[["text"]][["y"]],
labels = text_legend,
pos = 2
)
}
} }
return(invisible(NULL))
} }
# code to prepare `so_ii_catchment` dataset goes here
file_dir = geau::current_version(
"data-common/so-ii/topage",
pattern = "^[0-9-]+$"
)
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("geau")
usethis::use_data(so_ii_catchment, internal = FALSE, overwrite = TRUE)
setwd(actual)
# 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)
# code to prepare `so_ii_hydro` dataset goes here # code to prepare `so_ii_hydro` dataset goes here
selection = c("CdOH", "TopoOH") selection = c("CdOH", "TopoOH")
file_dir = current_version( file_dir = geau::current_version(
"data-common/so-ii/topage", "data-common/so-ii/topage",
pattern = "^[0-9-]+$" pattern = "^[0-9-]+$"
) )
so_ii_hydro = sf::st_read(file.path(file_dir, "cours-eau-so-ii.shp")) river = sf::st_read(file.path(file_dir, "cours_eau.shp"))
so_ii_hydro = sf::st_transform( river = sf::st_transform(
so_ii_hydro[selection], river[selection],
sf::st_crs(geau::so_ii_limit) sf::st_crs(geau::so_ii_limit)
) )
names(so_ii_hydro) = c("id", "name", "geometry") names(river) = c("id", "name", "geometry")
classification = read.csv2( 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" 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 # updating datasets
# actual = setwd(file.path(system.file(package = "geau"), ".."))
actual = setwd("geau") actual = setwd("geau")
usethis::use_data(so_ii_hydro, internal = FALSE, overwrite = TRUE) usethis::use_data(so_ii_hydro, internal = FALSE, overwrite = TRUE)
setwd(actual) setwd(actual)
# code to prepare `so_ii_onrn` dataset goes here
so_ii_montpellier = sf::st_read(
geau::current_version("data-common/so-ii/montpellier", "shp")
)
so_ii_montpellier = sf::st_transform(
so_ii_montpellier,
crs = sf::st_crs(geau::so_ii_limit)
)
so_ii_montpellier = so_ii_montpellier[c("SQUARTIER_", "LIBSQUART", "QUARTIER")]
names(so_ii_montpellier) = c("district", "district_name", "district_group", "geometry")
Encoding(so_ii_montpellier[["district_name"]]) = "UTF-8"
so_ii_montpellier[["district"]] = formatC(so_ii_montpellier[["district"]], flag = "0", width = 2)
so_ii_montpellier[["district_group"]] = as.character(so_ii_montpellier[["district_group"]])
# updating datasets
# actual = setwd(file.path(system.file(package = "geau"), ".."))
actual = setwd("geau")
usethis::use_data(so_ii_montpellier, internal = FALSE, overwrite = TRUE)
setwd(actual)
# code to prepare `so_ii_onrn` dataset goes here
so_ii_onrn = read.csv2(
geau::current_version("data-common/so-ii/onrn"),
row.names = 1
)
so_ii_onrn = so_ii_onrn[geau::so_ii_scope, ]
# updating datasets
# actual = setwd(file.path(system.file(package = "geau"), ".."))
actual = setwd("geau")
usethis::use_data(so_ii_onrn, internal = FALSE, overwrite = TRUE)
setwd(actual)
# code to prepare `so_ii_osm` dataset goes here
library(sf)
library(maptiles)
so_ii_osm = maptiles::get_tiles(geau::so_ii_limit, zoom = 10, crop = TRUE)
# updating datasets
actual = setwd("geau")
terra::writeRaster(so_ii_osm, "inst/extdata/so_ii_osm.tif", overwrite = TRUE)
setwd(actual)
...@@ -11,7 +11,7 @@ so_ii_population = readxl::read_xlsx( ...@@ -11,7 +11,7 @@ so_ii_population = readxl::read_xlsx(
class(so_ii_population) = "data.frame" class(so_ii_population) = "data.frame"
rownames(so_ii_population) = so_ii_population[["CODGEO"]] rownames(so_ii_population) = so_ii_population[["CODGEO"]]
selection = grep( selection = grep(
"PMUN|PSCDC|PTOT", "PMUN|PSDC|PTOT",
colnames(so_ii_population), colnames(so_ii_population),
value = TRUE value = TRUE
) )
...@@ -19,6 +19,7 @@ so_ii_population = as.matrix( ...@@ -19,6 +19,7 @@ so_ii_population = as.matrix(
so_ii_population[geau::so_ii_scope, selection] so_ii_population[geau::so_ii_scope, selection]
) )
year = gsub("PMUN", "20", selection) year = gsub("PMUN", "20", selection)
year = gsub("PSDC", "19", year)
year = gsub("PTOT", "19", year) year = gsub("PTOT", "19", year)
year = gsub("1919", "19", year) year = gsub("1919", "19", year)
year = gsub("1918", "18", year) year = gsub("1918", "18", year)
......
...@@ -6,19 +6,6 @@ so_ii_scope = read.csv2( ...@@ -6,19 +6,6 @@ so_ii_scope = read.csv2(
)[["code"]] )[["code"]]
so_ii_scope = sort(so_ii_scope) 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 # code to prepare `so_ii_clc` dataset goes here
so_ii_clc = readRDS("data-common/data/so-ii/so-ii_clc.rds") so_ii_clc = readRDS("data-common/data/so-ii/so-ii_clc.rds")
...@@ -63,8 +50,6 @@ so_ii_clc[["color"]] = as.character( ...@@ -63,8 +50,6 @@ so_ii_clc[["color"]] = as.character(
# actual = setwd(file.path(system.file(package = "geau"), "..")) # actual = setwd(file.path(system.file(package = "geau"), ".."))
actual = setwd("geau") actual = setwd("geau")
usethis::use_data(so_ii_scope, internal = FALSE, overwrite = TRUE) 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(so_ii_clc, internal = FALSE, overwrite = TRUE)
usethis::use_data(clc_color, internal = FALSE, overwrite = TRUE) usethis::use_data(clc_color, internal = FALSE, overwrite = TRUE)
setwd(actual) setwd(actual)
File added
File added
File deleted
No preview for this file type
File added
File added
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