diff --git a/geau/DESCRIPTION b/geau/DESCRIPTION index e2b401e646a675a46ea7a9183fb4923c78e66dd2..ce9d0515d68b2bd19f4dc1adc9219b332ba08b10 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.1.0 +Version: 1.0.2.0 Authors@R: person(given = "Frédéric", family = "Grelot", diff --git a/geau/NAMESPACE b/geau/NAMESPACE index 28624094617a8d4897a2d52d6bcbf411202043d4..f4d57d02574fc4c75a14bf7043817f4494019914 100644 --- a/geau/NAMESPACE +++ b/geau/NAMESPACE @@ -2,5 +2,6 @@ export(add.inset) export(current_version) +export(estimate_catnat_freq) export(kable_units) export(map_so_ii) diff --git a/geau/R/data.r b/geau/R/data.r index 014c91020381b3f21c6565e03932b946e402674a..c2e33bbde6e587c4faef5c001a87a2a12d41f752 100644 --- a/geau/R/data.r +++ b/geau/R/data.r @@ -50,13 +50,33 @@ #' } "so_ii_limit" -#' Flood frequency for the municipalities of so-ii +#' Population for so-ii #' -#' A dataset containing the flood frequency by year and so-ii municipality -#' according to the GASPAR database. +#' A dataset containing the population of commune in so-ii according to INSEE. #' -#' @format matrix 78 rows, 41 variables -"so_ii_gaspar" +#' @format numeric matrix +#' \describe{ +#' \item{row}{commune as in so_ii_scope} +#' \item{column}{year} +#' } +#' +#' @source \url{https://www.insee.fr/fr/statistiques/2522602} +"so_ii_population" + +#' Number of Cat Nat events for the municipalities 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. +#' +#' @format array with 3 dimensions +#' \describe{ +#' \item{first}{commune as in so_ii_scope} +#' \item{second}{year of Cat Nat events} +#' \item{third}{type of hazard} +#' } +#' +#' @source \url{https://www.georisques.gouv.fr/donnees/bases-de-donnees/base-gaspar} # nolint +"so_ii_catnat" #' CLC information for so-ii #' @@ -65,6 +85,13 @@ #' @format sf object "so_ii_clc" +#' Color and label for CLC +#' +#' A dataset proposing default colors and labels for plotting CLC +#' +#' @format data.frame 5 rows, 3 variables +"clc_color" + #' Hydrographic network within the so-ii perimeter #' #' A dataset containing the official hydrographic network from the BD TOPAGE @@ -77,6 +104,6 @@ #' TOPAGE} #' \item{degre}{character, level of detail to plot the hydrographic network} #' } -#' +#' #' @source \url{http://bdtopage.eaufrance.fr/page/objectifs} -"so_ii_hydro" +"so_ii_hydro" \ No newline at end of file diff --git a/geau/R/estimate_catnat_freq.R b/geau/R/estimate_catnat_freq.R new file mode 100644 index 0000000000000000000000000000000000000000..4a1c45797adea3165979dd31d6bace9b4d6bcdae --- /dev/null +++ b/geau/R/estimate_catnat_freq.R @@ -0,0 +1,47 @@ +#' @title Estimate frequency of Cat Nat events +#' +#' @param commune factor, commune +#' @param period POSIXct, a date for the event +#' @param hazard factor, type of hazard +#' @param period_format character, format to extract information from period +#' +#' @return array fivving frequency of Cat Nat events with 3 dimensions +#' (commune, period, hazard) +#' +#' @export +#' +#' @encoding UTF-8 +#' @author Frédéric Grelot +#' @author David Nortes Martinez +#' +#' @examples +#' +#' \dontrun{ +#' # To be added (soon) +#' } + +estimate_catnat_freq = function( + commune, + period, + hazard, + period_format = "%Y" +) { + period = format(as.Date(period), period_format) + period_levels = switch( + EXPR = period_format, + "%Y" = formatC( + 1982:as.integer(format(Sys.Date(),"%Y")), + width = 4, format = "d", flag = "0" + ), + "%m" = formatC(1:12, width = 2, format = "d", flag = "0"), + sort(unique(as.character(period))) + ) + result = data.frame( + commune = commune, + period = factor(period, levels = period_levels), + hazard = hazard + ) + result = table(result) + class(result) = "array" + return(result) +} diff --git a/geau/R/map_so_ii.r b/geau/R/map_so_ii.r index 3d434ef9f3b8587b942d7dc306e40a81340a3a1f..43771ca1828e5f474d0806f10aef5c789b9d1423 100644 --- a/geau/R/map_so_ii.r +++ b/geau/R/map_so_ii.r @@ -1,19 +1,22 @@ #' @title Plot a thematic map of so-ii #' +#' @details +#' For theme "catnat", detail must be chosen in c("inondation", "submersion", +#' "nappe"). +#' For theme "hydro" detail must be chosen in "0", "1", "2", "3" or "canal". +#' #' @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 bar logical, should a bar be plotted for the dataset #' @param path character, the name of the file to save the plot -#' @param gaspar_year character, the year chosen for gaspar theme +#' @param legend_theme logical, should a legend be plotted for the theme +#' @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) #' #' @return Nothing useful. #' -#' @details -#' For theme "hydro" detail takes values "1", "2", "3" or "canal" -#' #' @export #' #' @encoding UTF-8 @@ -28,10 +31,11 @@ map_so_ii = function( dataset, dataset_legend = NULL, - theme = c("", "clc", "gaspar", "hydro"), + theme = c("none", "clc", "catnat", "hydro"), bar = TRUE, path = NULL, - gaspar_year, + legend_theme = FALSE, + year, detail, ... ) { @@ -58,18 +62,96 @@ map_so_ii = function( 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 ("gaspar" %in% theme) { + if ("population" %in% theme) { + if (missing(year)) { + year = utils::tail(sort(colnames(geau::so_ii_population)), 1) + } + population_palette = scales::colour_ramp(c("white", "red"), alpha = .5) + color = matrix( + scales::cscale( + geau::so_ii_population, + population_palette, + trans = scales::log_trans()), + nrow = nrow(geau::so_ii_population), + dimnames = dimnames(geau::so_ii_population) + ) + border = "grey80" + plot( + geau::so_ii_commune[["geometry"]], + border = border, + col = color[ , year], + add = TRUE + ) + + value_legend = c(100, 1000, 10000, 100000, 250000) + color_legend = scales::cscale( + c(range(geau::so_ii_population), value_legend), + population_palette, + trans = scales::log_trans() + )[-(1:2)] + text_legend = formatC( + as.integer(value_legend), + big.mark = " " + ) + + theme_legend = list( + title = sprintf("Population %s", year), + legend = rep("", length(text_legend)), + x = "topright", + cex = .8, + bg = "white", + inset = 0.01, + fill = color_legend, + border = border, + text.width = graphics::strwidth(utils::tail(text_legend, 1)) + ) + } + + if ("catnat" %in% theme) { + if (missing(detail)) { + detail = dimnames(geau::so_ii_catnat)[["hazard"]] + } + detail = match.arg( + detail, + dimnames(geau::so_ii_catnat)[["hazard"]], + several.ok = TRUE + ) border = NA color = NA - if (!missing(gaspar_year)) { + if (!missing(year)) { border = "grey80" + catnat = apply( + geau::so_ii_catnat[, as.character(year), detail, drop = FALSE], + 1:2, + sum + ) color = ifelse( - geau::so_ii_gaspar[ , as.character(gaspar_year)] > 0, + 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 + ) } plot( @@ -84,7 +166,10 @@ map_so_ii = function( if (missing(detail)) { detail = "0" } - detail = match.arg(detail, choices = c("0", "1", "2", "3", "canal")) + detail = match.arg( + as.character(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] @@ -92,15 +177,26 @@ map_so_ii = function( lwd = 1 } else { selection = geau::so_ii_hydro[["degre"]] <= detail - geometry = geau::so_ii_hydro[["geometry"]][] + 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) + plot(geometry, col = color, lwd = lwd, add = TRUE) + + theme_legend = list( + title = sprintf("R\u00e9seau hydrographique"), + legend = ifelse(detail == "canal", "canal", "cours d'eau"), + x = "topright", + cex = .8, + bg = "white", + inset = 0.01, + col = color, + lwd = 2 + ) } - plot(dataset[["geometry"]], add = TRUE, ...) + if (!missing(dataset)) plot(dataset[["geometry"]], add = TRUE, ...) plot(geau::so_ii_limit, lwd = 2, add = TRUE) @@ -124,5 +220,17 @@ map_so_ii = function( 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)) } diff --git a/geau/data-raw/so_ii_catnat.R b/geau/data-raw/so_ii_catnat.R new file mode 100644 index 0000000000000000000000000000000000000000..eaf53df10efb1f22c0491cb6c946086be53f372e --- /dev/null +++ b/geau/data-raw/so_ii_catnat.R @@ -0,0 +1,29 @@ +# code to prepare `so_ii_catnat` dataset goes here + +so_ii_catnat = read.csv2( + geau::current_version("data-common/so-ii/gaspar", "catnat-") +) + +alea_scope = c("inondation", "nappe", "submersion") +so_ii_catnat = so_ii_catnat[ so_ii_catnat[["alea"]] %in% alea_scope, ] + +so_ii_catnat[["commune"]] = factor( + so_ii_catnat[["commune"]], + levels = so_ii_scope +) +so_ii_catnat[["alea"]] = factor( + so_ii_catnat[["alea"]], + levels = alea_scope +) + +so_ii_catnat = estimate_catnat_freq( + so_ii_catnat[["commune"]], + so_ii_catnat[["date.start"]], + so_ii_catnat[["alea"]] +) + +# updating datasets + +actual = setwd("geau") +usethis::use_data(so_ii_catnat, internal = FALSE, overwrite = TRUE) +setwd(actual) \ No newline at end of file diff --git a/geau/data-raw/so_ii_population.R b/geau/data-raw/so_ii_population.R new file mode 100644 index 0000000000000000000000000000000000000000..a771c06304b70495be2fb2a1afd1e8d74fb31555 --- /dev/null +++ b/geau/data-raw/so_ii_population.R @@ -0,0 +1,32 @@ +# code to prepare `so_ii_population` dataset goes here + +so_ii_population = readxl::read_xlsx( + geau::current_version( + "data-common/data/INSEE/Population/Historique", + "base-pop-historique" + ), + sheet = 1, + skip = 5, +) +class(so_ii_population) = "data.frame" +rownames(so_ii_population) = so_ii_population[["CODGEO"]] +selection = grep( + "PMUN|PSCDC|PTOT", + colnames(so_ii_population), + value = TRUE +) +so_ii_population = as.matrix( + so_ii_population[geau::so_ii_scope, selection] +) +year = gsub("PMUN", "20", selection) +year = gsub("PTOT", "19", year) +year = gsub("1919", "19", year) +year = gsub("1918", "18", year) +dimnames(so_ii_population)[[2]] = year + +# updating datasets + +# actual = setwd(file.path(system.file(package = "geau"), "..")) +actual = setwd("geau") +usethis::use_data(so_ii_population, internal = FALSE, overwrite = TRUE) +setwd(actual) diff --git a/geau/data-raw/so_ii_scope.R b/geau/data-raw/so_ii_scope.R index 7fe7810642921ee083db74ccd4e05f138535aad2..c69a3905d4c0de33c6a14c4f4cc948e612bfa742 100644 --- a/geau/data-raw/so_ii_scope.R +++ b/geau/data-raw/so_ii_scope.R @@ -24,26 +24,40 @@ so_ii_limit = sf::st_union(so_ii_commune) so_ii_clc = readRDS("data-common/data/so-ii/so-ii_clc.rds") so_ii_clc = so_ii_clc["code_18"] names(so_ii_clc) = c("clc_2018", "geometry") -color = scales::alpha(c("red3", "darkolivegreen3", "darkgreen", "#4C90B4", "lightblue"), .2) +clc_color = data.frame( + color = scales::alpha( + c( + "red3", + "darkolivegreen3", + "darkgreen", + "#4C90B4", + "lightblue" + ), + .2 + ), + label_fr = c( + "Zone urbaine", + "Zone agricole", + "Forêt, zone naturelle", + "Zone humide", + "Surface d'eau" + ), + label_uk = c( + "Urban area", + "Agricultural area", + "Forest, natural area", + "Humid area", + "Water surface" + ) +) so_ii_clc[["color"]] = as.character( cut( as.integer(substr(so_ii_clc[["clc_2018"]], 1, 1)), breaks = 5, - labels = color + labels = clc_color[["color"]] ) ) -# code to prepare `so_ii_gaspar` dataset goes here - -so_ii_gaspar = read.csv2( - current_version("data-common/so-ii/gaspar", "catnat_year_n"), - header = TRUE, - row.names = 1 -) -so_ii_gaspar = as.matrix(so_ii_gaspar) -colnames(so_ii_gaspar) = gsub("^X", "", colnames(so_ii_gaspar)) -so_ii_gaspar = so_ii_gaspar[so_ii_scope, ] - # updating datasets # actual = setwd(file.path(system.file(package = "geau"), "..")) @@ -52,5 +66,5 @@ 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_gaspar, internal = FALSE, overwrite = TRUE) +usethis::use_data(clc_color, internal = FALSE, overwrite = TRUE) setwd(actual) diff --git a/geau/data/clc_color.rda b/geau/data/clc_color.rda new file mode 100644 index 0000000000000000000000000000000000000000..468f6fb9fd841f01298b3298699aa43ff82fe708 Binary files /dev/null and b/geau/data/clc_color.rda differ diff --git a/geau/data/so_ii_catnat.rda b/geau/data/so_ii_catnat.rda new file mode 100644 index 0000000000000000000000000000000000000000..4083200d81d8518fd6c2633a328c1d012148d4de Binary files /dev/null and b/geau/data/so_ii_catnat.rda differ diff --git a/geau/data/so_ii_gaspar.rda b/geau/data/so_ii_gaspar.rda deleted file mode 100644 index b043d07338c1978285be83914c7af4282819f5b2..0000000000000000000000000000000000000000 Binary files a/geau/data/so_ii_gaspar.rda and /dev/null differ diff --git a/geau/data/so_ii_population.rda b/geau/data/so_ii_population.rda new file mode 100644 index 0000000000000000000000000000000000000000..bc3a1b17f4b91879f41c30609c3c58215fe403f4 Binary files /dev/null and b/geau/data/so_ii_population.rda differ diff --git a/geau/man/clc_color.Rd b/geau/man/clc_color.Rd new file mode 100644 index 0000000000000000000000000000000000000000..35203a561be96dfe331bc7cb00806d253dd04386 --- /dev/null +++ b/geau/man/clc_color.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/data.r +\docType{data} +\name{clc_color} +\alias{clc_color} +\title{Color and label for CLC} +\format{ +data.frame 5 rows, 3 variables +} +\usage{ +clc_color +} +\description{ +A dataset proposing default colors and labels for plotting CLC +} +\keyword{datasets} diff --git a/geau/man/estimate_catnat_freq.Rd b/geau/man/estimate_catnat_freq.Rd new file mode 100644 index 0000000000000000000000000000000000000000..79ac25384bed6b13c4b2d4b015ac8af8174c61dc --- /dev/null +++ b/geau/man/estimate_catnat_freq.Rd @@ -0,0 +1,36 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/estimate_catnat_freq.R +\encoding{UTF-8} +\name{estimate_catnat_freq} +\alias{estimate_catnat_freq} +\title{Estimate frequency of Cat Nat events} +\usage{ +estimate_catnat_freq(commune, period, hazard, period_format = "\%Y") +} +\arguments{ +\item{commune}{factor, commune} + +\item{period}{POSIXct, a date for the event} + +\item{hazard}{factor, type of hazard} + +\item{period_format}{character, format to extract information from period} +} +\value{ +array fivving frequency of Cat Nat events with 3 dimensions +(commune, period, hazard) +} +\description{ +Estimate frequency of Cat Nat events +} +\examples{ + +\dontrun{ +# To be added (soon) +} +} +\author{ +Frédéric Grelot + +David Nortes Martinez +} diff --git a/geau/man/map_so_ii.Rd b/geau/man/map_so_ii.Rd index be4ec5f6d5b5e1fe3de12c5c299187e75fdf1f31..e2c1ac696702834840d863d455056d39fe9d1fbb 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", "hydro"), + theme = c("none", "clc", "catnat", "hydro"), bar = TRUE, path = NULL, - gaspar_year, + legend_theme = FALSE, + year, detail, ... ) @@ -23,11 +24,13 @@ map_so_ii( \item{theme}{character, choice for the theme (if any)} -\item{bar}{logical, should a bar be plotted} +\item{bar}{logical, should a bar be plotted for the dataset} \item{path}{character, the name of the file to save the plot} -\item{gaspar_year}{character, the year chosen for gaspar theme} +\item{legend_theme}{logical, should a legend be plotted for the theme} + +\item{year}{character, the year chosen for some themes (catnat, population)} \item{detail}{character, detail for theme, depends on theme} @@ -40,7 +43,9 @@ Nothing useful. Plot a thematic map of so-ii } \details{ -For theme "hydro" detail takes values "1", "2", "3" or "canal" +For theme "catnat", detail must be chosen in c("inondation", "submersion", +"nappe"). +For theme "hydro" detail must be chosen in "0", "1", "2", "3" or "canal". } \examples{ diff --git a/geau/man/so_ii_catnat.Rd b/geau/man/so_ii_catnat.Rd new file mode 100644 index 0000000000000000000000000000000000000000..50b2aab612ad4afa953986d39234eed25cf48de1 --- /dev/null +++ b/geau/man/so_ii_catnat.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/data.r +\docType{data} +\name{so_ii_catnat} +\alias{so_ii_catnat} +\title{Number of Cat Nat events for the municipalities of so-ii} +\format{ +array with 3 dimensions +\describe{ +\item{first}{commune as in so_ii_scope} +\item{second}{year of Cat Nat events} +\item{third}{type of hazard} +} +} +\source{ +\url{https://www.georisques.gouv.fr/donnees/bases-de-donnees/base-gaspar} # nolint +} +\usage{ +so_ii_catnat +} +\description{ +A dataset containing the number of Cat Nat events (linked to flood) by year +and so-ii municipality according to the GASPAR database. +} +\keyword{datasets} diff --git a/geau/man/so_ii_gaspar.Rd b/geau/man/so_ii_gaspar.Rd deleted file mode 100644 index dcf936d10f9d2ae5f621b8c24e8f4abfb2b66904..0000000000000000000000000000000000000000 --- a/geau/man/so_ii_gaspar.Rd +++ /dev/null @@ -1,17 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/data.r -\docType{data} -\name{so_ii_gaspar} -\alias{so_ii_gaspar} -\title{Flood frequency for the municipalities of so-ii} -\format{ -matrix 78 rows, 41 variables -} -\usage{ -so_ii_gaspar -} -\description{ -A dataset containing the flood frequency by year and so-ii municipality -according to the GASPAR database. -} -\keyword{datasets} diff --git a/geau/man/so_ii_population.Rd b/geau/man/so_ii_population.Rd new file mode 100644 index 0000000000000000000000000000000000000000..e2fd7371abdf02717f458323fab18ebc9d262bdc --- /dev/null +++ b/geau/man/so_ii_population.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/data.r +\docType{data} +\name{so_ii_population} +\alias{so_ii_population} +\title{Population for so-ii} +\format{ +numeric matrix +\describe{ +\item{row}{commune as in so_ii_scope} +\item{column}{year} +} +} +\source{ +\url{https://www.insee.fr/fr/statistiques/2522602} +} +\usage{ +so_ii_population +} +\description{ +A dataset containing the population of commune in so-ii according to INSEE. +} +\keyword{datasets} diff --git a/map/map-2020-07-20.rmd b/map/map-2020-07-20.rmd new file mode 100644 index 0000000000000000000000000000000000000000..d3a977f0bf35a84030f259fe216168947289c743 --- /dev/null +++ b/map/map-2020-07-20.rmd @@ -0,0 +1,96 @@ +```{r data-recup} +# Récupération des données (à faire une fois) + +## Récupération du périmètre (déjà pré-traité) +soii = readRDS("data-common/data/so-ii/so-ii_perim.rds") + +## Récupération du périmètre dans France (déjà prétraité) +soii_france = readRDS("data-common/data/so-ii/so-ii_france.rds") + +## Récupération de CLC (déjà pré-traité) +soii_clc = readRDS("data-common/data/so-ii/so-ii_clc.rds") + +## Recupération des données du fond de carte +# soii_osm = maptiles::get_tiles(soii, provider = "OpenStreetMap.MapnikBW", crop = TRUE, zoom = 11) +# terra::writeRaster(soii_osm, "data-common/data/so-ii/so-ii_osm-bw.tif", overwrite = TRUE) +soii_osm = terra::rast("data-common/data/so-ii/so-ii_osm-bw.tif") +# credit = sprintf("Background from %s", maptiles::get_credit("OpenStreetMap")) +``` + +```{r rex-pauline} +# Production d'une carte + +## Définition du nom du fichier de sauvegarde +file_path = file.path("data-common/figure/so-ii/pdf/2021-07-20/rex-pauline.pdf") + +## Récupération des données propre à la carte en cours +rex_agri = rio::import("data-common/table/so-ii/rex-agri-2014.ods", which = 1) +## Transformation des données d'enquête en points géoréférencés +rex_agri = sf::st_as_sf(rex_agri, coords = c("longitude", "latitude"), crs = "WGS84") + +# Génération de la carte + +## Ouverture du fichier de sauvegarde +# png(file_path, height = 800, width = 800) +pdf(file_path) + +## Initialisation de la carte avec le périmètre de so-ii +par(mai = c(.65, .60, .50, .15)) +plot(soii, axes = TRUE) +# terra::plotRGB(soii_osm, add = TRUE) +plot(soii, lwd = 2, add = TRUE) + +## Ajout du fond CLC avec le niveau 1 du code_18 +color_clc = scales::alpha(c("red3", "darkolivegreen3", "darkgreen", "#4C90B4", "lightblue"), .2) +color = as.character(cut( + as.integer(substr(soii_clc[["code_18"]], 1, 1)), + breaks = 5, + labels = color_clc)) +plot(soii_clc$geometry, border = NA, col = color, add = TRUE) + +## Ajout des points d'enquête +# plot(rex_agri$geometry, col = "red", bg = "red", pch = 21, cex = 1, add = TRUE) +plot(rex_agri$geometry[rex_agri[["REX 2015"]],], + col = "black", bg = "black", cex = 1.4, + pch = 21, add = TRUE) +plot(rex_agri$geometry[rex_agri[["REX 2019"]],], + col = "black", bg = "green", cex = 1.4, + pch = 21, add = TRUE) +plot(rex_agri$geometry[rex_agri[["REX 2020"]],], + col = "black", bg = "orange", cex = 1.4, + pch = 21, add = TRUE) + +## Ajout de l'échelle +# raster::scalebar(10, type = "bar", divs = 4, below = "km") +terra::sbar(10, c(3.55, 43.47), type = "bar", below = "km", label = c(0, 5, 10), cex = .8) + +## Ajout des crédits +# text(3.55, 43.435, credit, adj = 0, cex = .8, font = 3) + +## Légende CLC +legend("topright", cex = .8, bg = "white", inset = 0.01, + title = "Land Use (from CLC)", + legend = c( + "Urban area", + "Agricultural area", + "Forest, natural area", + "Humid area", + "Water surface"), + fill = color_clc) + +## Légende Carte en cours +legend("bottomright", cex = .8, bg = "white", inset = 0.01, + title = "Farms surveyed in", + legend = c("2015", "2015 & 2019", "2015 & 2020"), + pch = 21, + col = "black", + pt.bg = c("black", "green", "orange"), + pt.cex = 1.4) + +## Ajout de l'encart +# geau::add.inset(soii_france, col = c("white", "red"), border = c("lightgray", "red"), lwd = 2) + +## Fermeture du fichier de sauvegarde +dev.off() +``` + diff --git a/map/map-2021-07-20.rmd b/map/map-2021-07-20.rmd new file mode 100644 index 0000000000000000000000000000000000000000..ac737ce7687ee45cb977359a1978e33ce015c6ea --- /dev/null +++ b/map/map-2021-07-20.rmd @@ -0,0 +1,1016 @@ + +```{r data-recup} +# Récupération des données (à faire une fois) + +## Récupération du périmètre (déjà pré-traité) +soii = readRDS("data-common/data/so-ii/so-ii_perim.rds") + +## Récupération du périmètre dans France (déjà prétraité) +soii_france = readRDS("data-common/data/so-ii/so-ii_france.rds") + +## Récupération de CLC (déjà pré-traité) +soii_clc = readRDS("data-common/data/so-ii/so-ii_clc.rds") + +## Recupération des données du fond de carte +# soii_osm = maptiles::get_tiles(soii, provider = "OpenStreetMap.MapnikBW", crop = TRUE, zoom = 11) +# terra::writeRaster(soii_osm, "data-common/data/so-ii/so-ii_osm-bw.tif", overwrite = TRUE) +# soii_osm = terra::rast("data-common/data/so-ii/so-ii_osm-bw.tif") +# credit = sprintf("Background from %s", maptiles::get_credit("OpenStreetMap")) +``` + +```{r rex_2020} +# Production d'une carte + +## Définition du nom du fichier de sauvegarde +file_path = file.path("data-common/figure/so-ii/pdf/2021-07-20/rex_2020.pdf") + +## Récupération des données propre à la carte en cours +rex_2020 = rio::import("data-common/table/so-ii/rex-2020.ods", which = 1) +## Transformation des données d'enquête en points géoréférencés +rex_2020 = sf::st_as_sf(rex_2020, coords = c("longitude", "latitude"), crs = "WGS84") + +# Génération de la carte + +## Ouverture du fichier de sauvegarde +# png(file_path, height = 800, width = 800) +pdf(file_path) + +## Initialisation de la carte avec le périmètre de so-ii +par(mai = c(.65, .60, .50, .15)) +plot(soii, axes = TRUE) +# terra::plotRGB(soii_osm, add = TRUE) +plot(soii, lwd = 2, add = TRUE) + +## Ajout du fond CLC avec le niveau 1 du code_18 +color_clc = scales::alpha(c("red3", "darkolivegreen3", "darkgreen", "#4C90B4", "lightblue"), .2) +color = as.character(cut( + as.integer(substr(soii_clc[["code_18"]], 1, 1)), + breaks = 5, + labels = color_clc)) +plot(soii_clc$geometry, border = NA, col = color, add = TRUE) + +## Ajout des points d'enquête +# plot(rex_2020$geometry, col = "red", bg = "red", pch = 21, cex = 1, add = TRUE) +plot(rex_2020$geometry[rex[["viticulture"]],], + col = "black", bg = "deeppink4", cex = 1.4, + pch = 21, add = TRUE) +plot(rex_2020$geometry[rex[["habitant"]],], + col = "black", bg = "cornflowerblue", cex = 1.4, + pch = 21, add = TRUE) +# plot(rex_2020$geometry[rex[["maraichage"]],], + # col = "black", bg = "green", cex = 1.4, + # pch = 21, add = TRUE) + +## Ajout de l'échelle +# raster::scalebar(10, type = "bar", divs = 4, below = "km") +terra::sbar(10, c(3.55, 43.47), type = "bar", below = "km", label = c(0, 5, 10), cex = .8) + +## Ajout des crédits +# text(3.55, 43.435, credit, adj = 0, cex = .8, font = 3) + +## Légende + +# legend("topright", cex = .8, bg = "white", inset = 0.01, + # title = "Land Use (from CLC)", + # legend = c( + # "Urban area", + # "Agricultural area", + # "Forest, natural area", + # "Humid area", + # "Water surface"), + # fill = color_clc) + +legend("bottomright", cex = .8, bg = "white", inset = 0.01, + title = "Enquêtes du REX 19 septembre 2020 :", + legend = c("Agriculteurs", "Habitants membre ROI"), + pch = 21, + col = "black", + pt.bg = c("deeppink4", "cornflowerblue"), + pt.cex = 1.4) + +## Ajout de l'encart +# geau::add.inset(soii_france, col = c("white", "red"), border = c("lightgray", "red"), lwd = 2) + +## Fermeture du fichier de sauvegarde +dev.off() +``` + +```{r roi_agri} +# Production d'une carte + +## Définition du nom du fichier de sauvegarde +file_path = file.path("data-common/figure/so-ii/pdf/2021-07-20/roi_agri.pdf") + +## Récupération des données propre à la carte en cours +roi_agri = rio::import("data-common/table/so-ii/roi-agri.ods", which = 1) +## Transformation des données d'enquête en points géoréférencés +roi_agri = sf::st_as_sf(rex_2020, coords = c("longitude", "latitude"), crs = "WGS84") + +# Génération de la carte + +## Ouverture du fichier de sauvegarde +# png(file_path, height = 800, width = 800) +pdf(file_path) + +## Initialisation de la carte avec le périmètre de so-ii +par(mai = c(.65, .60, .50, .15)) +plot(soii, axes = TRUE) +# terra::plotRGB(soii_osm, add = TRUE) +plot(soii, lwd = 2, add = TRUE) + +## Ajout du fond CLC avec le niveau 1 du code_18 +color_clc = scales::alpha(c("red3", "darkolivegreen3", "darkgreen", "#4C90B4", "lightblue"), .2) +color = as.character(cut( + as.integer(substr(soii_clc[["code_18"]], 1, 1)), + breaks = 5, + labels = color_clc)) +plot(soii_clc$geometry, border = NA, col = color, add = TRUE) + +## Ajout des points d'enquête +# plot(roi_agri$geometry, col = "red", bg = "red", pch = 21, cex = 1, add = TRUE) +plot(roi_agri$geometry[roi_agri[["activite"]] == "viticulture"], + col = "black", bg = "gray", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_agri$geometry[roi_agri[["activite"]] == "maraichage"], + col = "black", bg = "green", cex = 1.4, + pch = 21, add = TRUE) +## Ajout de l'échelle +# raster::scalebar(10, type = "bar", divs = 4, below = "km") +terra::sbar(10, c(3.55, 43.47), type = "bar", below = "km", label = c(0, 5, 10), cex = .8) + +## Ajout des crédits +# text(3.55, 43.435, credit, adj = 0, cex = .8, font = 3) + +## Légende + +# legend("topright", cex = .8, bg = "white", inset = 0.01, + # title = "Land Use (from CLC)", + # legend = c( + # "Urban area", + # "Agricultural area", + # "Forest, natural area", + # "Humid area", + # "Water surface"), + # fill = color_clc) + +legend("bottomright", cex = .8, bg = "white", inset = 0.01, + title = "Agriculteurs contactées/à contacter:", + legend = c("Agriculteurs"), + pch = 21, + col = "black", + pt.bg = c("gray"), + pt.cex = 1.4) + +## Ajout de l'encart +# geau::add.inset(soii_france, col = c("white", "red"), border = c("lightgray", "red"), lwd = 2) + +## Fermeture du fichier de sauvegarde +dev.off() +``` + +```{r presence_candidats} +# Production d'une carte + +## Définition du nom du fichier de sauvegarde +file_path = file.path("data-common/figure/so-ii/pdf/2021-07-20/roi_candidat_presence.pdf") + +## Récupération des données propre à la carte en cours +roi_habitant = rio::import("data-common/table/so-ii/roi-habitant-2021-07-20.ods", which = 1) +roi_habitant = roi_habitant[!is.na(roi_habitant$latitude), ] + +## Transformation des données d'enquête en points géoréférencés +roi_habitant = sf::st_as_sf(roi_habitant, coords = c("longitude", "latitude"), crs = "WGS84") + +# Génération de la carte + +## Ouverture du fichier de sauvegarde +# png(file_path, height = 800, width = 800) +pdf(file_path) + +## Initialisation de la carte avec le périmètre de so-ii +par(mai = c(.65, .60, .50, .15)) +plot(soii, axes = TRUE) +# terra::plotRGB(soii_osm, add = TRUE) +plot(soii, lwd = 2, add = TRUE) + +## Ajout du fond CLC avec le niveau 1 du code_18 +color_clc = scales::alpha(c("red3", "darkolivegreen3", "darkgreen", "#4C90B4", "lightblue"), .2) +color = as.character(cut( + as.integer(substr(soii_clc[["code_18"]], 1, 1)), + breaks = 5, + labels = color_clc)) +plot(soii_clc$geometry, border = NA, col = color, add = TRUE) + +## Ajout des points d'enquête +# plot(candidats$geometry, col = "red", bg = "red", pch = 21, cex = 1, add = TRUE) +plot(roi_habitant$geometry[roi_habitant[["statut_personne"]] == "abandon"], + col = "black", bg = "gray55", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[roi_habitant[["statut_personne"]] == "non"], + col = "black", bg = "gray55", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[ + roi_habitant[["statut_personne"]] == "candidat" & + roi_habitant[["presence_atelier"]] == "non" + ], + col = "black", bg = "lightskyblue", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[ + roi_habitant[["statut_personne"]] == "candidat" & + roi_habitant[["presence_atelier"]] == "oui" + ], + col = "black", bg = "limegreen", cex = 1.4, + pch = 21, add = TRUE) + +## Ajout de l'échelle +# raster::scalebar(10, type = "bar", divs = 4, below = "km") +terra::sbar(10, c(3.55, 43.47), type = "bar", below = "km", label = c(0, 5, 10), cex = .8) + +## Ajout des crédits +# text(3.55, 43.435, credit, adj = 0, cex = .8, font = 3) + +## Légende + +# legend("topright", cex = .8, bg = "white", inset = 0.01, + # title = "Land Use (from CLC)", + # "Urban area", + # "Agricul +```{r rex_2020} +# Production d'une carte + +## Définition du nom du fichier de sauvegarde +file_path = file.path("data-common/figure/so-ii/pdf/2021-07-20/rex_2020.pdf") + +## Récupération des données propre à la carte en cours +rex_2020 = rio::import("data-common/table/so-ii/rex-2020.ods", which = 1) +## Transformation des données d'enquête en points géoréférencés +rex_2020 = sf::st_as_sf(rex_2020, coords = c("longitude", "latitude"), crs = "WGS84") + +# Génération de la carte + +## Ouverture du fichier de sauvegarde +# png(file_path, height = 800, width = 800) +pdf(file_path) + +## Initialisation de la carte avec le périmètre de so-ii +par(mai = c(.65, .60, .50, .15)) +plot(soii, axes = TRUE) +# terra::plotRGB(soii_osm, add = TRUE) +plot(soii, lwd = 2, add = TRUE) + +## Ajout du fond CLC avec le niveau 1 du code_18 +color_clc = scales::alpha(c("red3", "darkolivegreen3", "darkgreen", "#4C90B4", "lightblue"), .2) +color = as.character(cut( + as.integer(substr(soii_clc[["code_18"]], 1, 1)), + breaks = 5, + labels = color_clc)) +plot(soii_clc$geometry, border = NA, col = color, add = TRUE) + +## Ajout des points d'enquête +# plot(rex_2020$geometry, col = "red", bg = "red", pch = 21, cex = 1, add = TRUE) +plot(rex_2020$geometry[rex[["viticulture"]],], + col = "black", bg = "deeppink4", cex = 1.4, + pch = 21, add = TRUE) +plot(rex_2020$geometry[rex[["habitant"]],], + col = "black", bg = "cornflowerblue", cex = 1.4, + pch = 21, add = TRUE) +# plot(rex_2020$geometry[rex[["maraichage"]],], + # col = "black", bg = "green", cex = 1.4, + # pch = 21, add = TRUE) +deeppink4 +## Ajout de l'échelle +# raster::scalebar(10, type = "bar", divs = 4, below = "km") +terra::sbar(10, c(3.55, 43.47), type = "bar", below = "km", label = c(0, 5, 10), cex = .8) + +## Ajout des crédits +# text(3.55, 43.435, credit, adj = 0, cex = .8, font = 3) + +## Légende + +# legend("topright", cex = .8, bg = "white", inset = 0.01, + # title = "Land Use (from CLC)", + # legend = c( + # "Urban area", + # "Agricultural area", + # "Forest, natural area", + # "Humid area", + # "Water surface"), + # fill = color_clc) + +legend("bottomright", cex = .8, bg = "white", inset = 0.01, + title = "Enquêtes du REX 19 septembre 2020 :", + legend = c("Agriculteurs", "Habitants membre ROI"), + pch = 21, + col = "black", + pt.bg = c("deeppink4", "cornflowerblue"), + pt.cex = 1.4) + +## Ajout de l'encart +# geau::add.inset(soii_france, col = c("white", "red"), border = c("lightgray", "red"), lwd = 2) + +## Fermeture du fichier de sauvegarde +dev.off() +``` + + +```{r presence_candidats} +# Production d'une carte + +## Définition du nom du fichier de sauvegarde +file_path = file.path("data-common/figure/so-ii/pdf/2021-07-20/roi_candidat_presence.pdf") + +## Récupération des données propre à la carte en cours +roi_habitant = rio::import("data-common/table/so-ii/roi-habitant-2021-07-20.ods", which = 1) +roi_habitant = roi_habitant[!is.na(roi_habitant$latitude), ] + +## Transformation des données d'enquête en points géoréférencés +roi_habitant = sf::st_as_sf(roi_habitant, coords = c("longitude", "latitude"), crs = "WGS84") + +# Génération de la carte + +## Ouverture du fichier de sauvegarde +# png(file_path, height = 800, width = 800) +pdf(file_path) + +## Initialisation de la carte avec le périmètre de so-ii +par(mai = c(.65, .60, .50, .15)) +plot(soii, axes = TRUE) +# terra::plotRGB(soii_osm, add = TRUE) +plot(soii, lwd = 2, add = TRUE) + +## Ajout du fond CLC avec le niveau 1 du code_18 +color_clc = scales::alpha(c("red3", "darkolivegreen3", "darkgreen", "#4C90B4", "lightblue"), .2) +color = as.character(cut( + as.integer(substr(soii_clc[["code_18"]], 1, 1)), + breaks = 5, + labels = color_clc)) +plot(soii_clc$geometry, border = NA, col = color, add = TRUE) + +## Ajout des points d'enquête +# plot(candidats$geometry, col = "red", bg = "red", pch = 21, cex = 1, add = TRUE) +plot(roi_habitant$geometry[roi_habitant[["statut_personne"]] == "abandon"], + col = "black", bg = "gray55", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[roi_habitant[["statut_personne"]] == "non"], + col = "black", bg = "gray55", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[ + roi_habitant[["statut_personne"]] == "candidat" & + roi_habitant[["presence_atelier"]] == "non" + ], + col = "black", bg = "lightskyblue", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[ + roi_habitant[["statut_personne"]] == "candidat" & + roi_habitant[["presence_atelier"]] == "oui" + ], + col = "black", bg = "limegreen", cex = 1.4, + pch = 21, add = TRUE) + +## Ajout de l'échelle +# raster::scalebar(10, type = "bar", divs = 4, below = "km") +terra::sbar(10, c(3.55, 43.47), type = "bar", below = "km", label = c(0, 5, 10), cex = .8) + +## Ajout des crédits +# text(3.55, 43.435, credit, adj = 0, cex = .8, font = 3) + +## Légende + +# legend("topright", cex = .8, bg = "white", inset = 0.01, + # title = "Land Use (from CLC)", + # "Urban area", + # "Agricultural area", + # "Forest, natural area", + # "Humid area", + # "Water surface"), + # fill = color_clc) + +legend("bottomright", cex = .8, bg = "white", inset = 0.01, + title = "Candidats du ROI Habitant :", + legend = c("abandon / non retenu", "candidat non présent", "candidat présent"), + pch = 21, + col = "black", + pt.bg = c("gray55", "lightskyblue", "limegreen"), + pt.cex = 1.4) + +## Ajout de l'encart +# geau::add.inset(soii_france, col = c("white", "red"), border = c("lightgray", "red"), lwd = 2) + +## Fermeture du fichier de sauvegarde +dev.off() +``` + +```{r type_inondation} +# Production d'une carte + +## Définition du nom du fichier de sauvegarde +file_path = file.path("data-common/figure/so-ii/pdf/2021-07-20/type_inondation.pdf") + +## Récupération des données propre à la carte en cours +roi_habitant = rio::import("data-common/table/so-ii/roi-habitant-2021-07-20.ods", which = 1) +roi_habitant = roi_habitant[!is.na(roi_habitant$latitude), ] + +## Transformation des données d'enquête en points géoréférencés +roi_habitant = sf::st_as_sf(roi_habitant, coords = c("longitude", "latitude"), crs = "WGS84") + +# Génération de la carte + +## Ouverture du fichier de sauvegarde +# png(file_path, height = 800, width = 800) +pdf(file_path) + +## Initialisation de la carte avec le périmètre de so-ii +par(mai = c(.65, .60, .50, .15)) +plot(soii, axes = TRUE) +# terra::plotRGB(soii_osm, add = TRUE) +plot(soii, lwd = 2, add = TRUE) + +## Ajout du fond CLC avec le niveau 1 du code_18 +color_clc = scales::alpha(c("red3", "darkolivegreen3", "darkgreen", "#4C90B4", "lightblue"), .2) +color = as.character(cut( + as.integer(substr(soii_clc[["code_18"]], 1, 1)), + breaks = 5, + labels = color_clc)) +plot(soii_clc$geometry, border = NA, col = color, add = TRUE) + +## Ajout des points d'enquête +# plot(roi_habitant$geometry, col = "red", bg = "red", pch = 21, cex = 1, add = TRUE) +plot(roi_habitant$geometry[ + roi_habitant[["type_alea"]] == "debordement-cours-eau"] & + roi_habitant[["statut_personne"]] == "candidat" + ], + col = "black", bg = "blue", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[roi_habitant[["type_alea"]] == "debordement-cours-eau_ruissellement" & + roi_habitant[["statut_personne"]] == "candidat" + ], + col = "black", bg = "lightblue", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[roi_habitant[["type_alea"]] == "debordement-etang" & + roi_habitant[["statut_personne"]] == "candidat" + ], + col = "black", bg = "hotpink1", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[roi_habitant[["type_alea"]] == "remontee-nappe" & + roi_habitant[["statut_personne"]] == "candidat" + ], + col = "black", bg = "green", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[roi_habitant[["type_alea"]] == "ruissellement" & + roi_habitant[["statut_personne"]] == "candidat" + ], + col = "black", bg = "brown", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[roi_habitant[["type_alea"]] == "rupture-digue"], + col = "black", bg = "orange", cex = 1.4, + pch = 21, add = TRUE) + +## Ajout de l'échelle +# raster::scalebar(10, type = "bar", divs = 4, below = "km") +terra::sbar(10, c(3.55, 43.47), type = "bar", below = "km", label = c(0, 5, 10), cex = .8) + +## Ajout des crédits +# text(3.55, 43.435, credit, adj = 0, cex = .8, font = 3) + +## Légende +# legend("topright", cex = .8, bg = "white", inset = 0.01, + # title = "Land Use (from CLC)", + # legend = c( + # "Urban area", + # "Agricultural area", + # "Forest, natural area", + # "Humid area", + # "Water surface"), + # fill = color_clc) + +legend("bottomright", cex = .8, bg = "white", inset = 0.01, + title = "Exposition principale des candidats :", + legend = c("débordement de cours d'eau", "débordement et ruissellement", "débordement d'étang", "remontée de nappe", "ruissellement", "rupture de digue"), + pch = 21, + col = "black", + pt.bg = c("blue", "lightblue", "hotpink1", "green", "brown", "orange"), + pt.cex = 1.4) + +## Ajout de l'encart +# geau::add.inset(soii_france, col = c("white", "red"), border = c("lightgray", "red"), lwd = 2) + +## Fermeture du fichier de sauvegarde +dev.off() +``` + + +```{r origine} +# Production d'une carte + +## Définition du nom du fichier de sauvegarde +file_path = file.path("data-common/figure/so-ii/pdf/2021-07-20/origine.pdf") + +## Récupération des données propre à la carte en cours +roi_habitant = rio::import("data-common/table/so-ii/roi-habitant-2021-07-20.ods", which = 1) +roi_habitant = roi_habitant[!is.na(roi_habitant$latitude), ] + +## Transformation des données d'enquête en points géoréférencés +roi_habitant = sf::st_as_sf(roi_habitant, coords = c("longitude", "latitude"), crs = "WGS84") + +# Génération de la carte + +## Ouverture du fichier de sauvegarde +# png(file_path, height = 800, width = 800) +pdf(file_path) + +## Initialisation de la carte avec le périmètre de so-ii +par(mai = c(.65, .60, .50, .15)) +plot(soii, axes = TRUE) +# terra::plotRGB(soii_osm, add = TRUE) +plot(soii, lwd = 2, add = TRUE) + +## Ajout du fond CLC avec le niveau 1 du code_18 +color_clc = scales::alpha(c("red3", "darkolivegreen3", "darkgreen", "#4C90B4", "lightblue"), .2) +color = as.character(cut( + as.integer(substr(soii_clc[["code_18"]], 1, 1)), + breaks = 5, + labels = color_clc)) +plot(soii_clc$geometry, border = NA, col = color, add = TRUE) + +## Ajout des points d'enquête +# plot(roi_habitant$geometry, col = "red", bg = "red", pch = 21, cex = 1, add = TRUE) +plot(roi_habitant$geometry[ + roi_habitant[["Origine"]] == "REX-2021" & + roi_habitant[["statut_personne"]] == "candidat" + ], + col = "black", bg = "royalblue3", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[ + roi_habitant[["Origine"]] == "PI-M2-ES-2020" & + roi_habitant[["statut_personne"]] == "candidat" + ], + col = "black", bg = "khaki3", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[ + roi_habitant[["Origine"]] == "Stage-M2-ES-2020" & + roi_habitant[["statut_personne"]] == "candidat" + ], + col = "black", bg = "palegreen2", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[roi_habitant[["Origine"]] == "PI-M2-ES-2019"], + col = "black", bg = "khaki1", cex = 1.4, + pch = 21, add = TRUE) + +## Ajout de l'échelle +# raster::scalebar(10, type = "bar", divs = 4, below = "km") +terra::sbar(10, c(3.55, 43.47), type = "bar", below = "km", label = c(0, 5, 10), cex = .8) + +## Ajout des crédits +# text(3.55, 43.435, credit, adj = 0, cex = .8, font = 3) + +## Légende +# legend("topright", cex = .8, bg = "white", inset = 0.01, + # title = "Land Use (from CLC)", + # legend = c( + # "Urban area", + # "Agricultural area", + # "Forest, natural area", + # "Humid area", + # "Water surface"), + # fill = color_clc) + +legend("bottomright", cex = .8, bg = "white", inset = 0.01, + title = "Origine des candidats :", + legend = c("REX 2021", "PI Master 2 ES 2020", "Stage Master 2 ES 2020", "PI Master 2 ES 2019"), + pch = 21, + col = "black", + pt.bg = c("royalblue3", "khaki3", "palegreen2", "khaki1"), + pt.cex = 1.4) + +## Ajout de l'encart +# geau::add.inset(soii_france, col = c("white", "red"), border = c("lightgray", "red"), lwd = 2) + +## Fermeture du fichier de sauvegarde +dev.off() +``` + + +```{r type_inondation} +# Production d'une carte + +## Définition du nom du fichier de sauvegarde +file_path = file.path("data-common/figure/so-ii/pdf/2021-07-20/type_inondation.pdf") + +## Récupération des données propre à la carte en cours +roi_habitant = rio::import("data-common/table/so-ii/roi-habitant-2021-07-20.ods", which = 1) +roi_habitant = roi_habitant[!is.na(roi_habitant$latitude), ] + +## Transformation des données d'enquête en points géoréférencés +roi_habitant = sf::st_as_sf(roi_habitant, coords = c("longitude", "latitude"), crs = "WGS84") + +# Génération de la carte + +## Ouverture du fichier de sauvegarde +# png(file_path, height = 800, width = 800) +pdf(file_path) + +## Initialisation de la carte avec le périmètre de so-ii +par(mai = c(.65, .60, .50, .15)) +plot(soii, axes = TRUE) +# terra::plotRGB(soii_osm, add = TRUE) +plot(soii, lwd = 2, add = TRUE) + +## Ajout du fond CLC avec le niveau 1 du code_18 +color_clc = scales::alpha(c("red3", "darkolivegreen3", "darkgreen", "#4C90B4", "lightblue"), .2) +color = as.character(cut( + as.integer(substr(soii_clc[["code_18"]], 1, 1)), + breaks = 5, + labels = color_clc)) +plot(soii_clc$geometry, border = NA, col = color, add = TRUE) + +## Ajout des points d'enquête +# plot(roi_habitant$geometry, col = "red", bg = "red", pch = 21, cex = 1, add = TRUE) +plot(roi_habitant$geometry[ + roi_habitant[["type_alea"]] == "debordement-cours-eau" & + roi_habitant[["statut_personne"]] == "candidat" + ], + col = "black", bg = "blue", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[ + roi_habitant[["type_alea"]] == "debordement-cours-eau_ruissellement" & + roi_habitant[["statut_personne"]] == "candidat" + ], + col = "black", bg = "lightblue", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[ + roi_habitant[["type_alea"]] == "debordement-etang" & + roi_habitant[["statut_personne"]] == "candidat" + ], + col = "black", bg = "hotpink1", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[ + roi_habitant[["type_alea"]] == "remontee-nappe" & + roi_habitant[["statut_personne"]] == "candidat" + ], + col = "black", bg = "green", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[ + roi_habitant[["type_alea"]] == "ruissellement" & + roi_habitant[["statut_personne"]] == "candidat" + ], + col = "black", bg = "brown", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[ + roi_habitant[["type_alea"]] == "rupture-digue" & + roi_habitant[["statut_personne"]] == "candidat" + ], + col = "black", bg = "orange", cex = 1.4, + pch = 21, add = TRUE) + +## Ajout de l'échelle +# raster::scalebar(10, type = "bar", divs = 4, below = "km") +terra::sbar(10, c(3.55, 43.47), type = "bar", below = "km", label = c(0, 5, 10), cex = .8) + +## Ajout des crédits +# text(3.55, 43.435, credit, adj = 0, cex = .8, font = 3) + +## Légende +# legend("topright", cex = .8, bg = "white", inset = 0.01, + # title = "Land Use (from CLC)", + # legend = c( + # "Urban area", + # "Agricultural area", + # "Forest, natural area", + # "Humid area", + # "Water surface"), + # fill = color_clc) + +legend("bottomright", cex = .8, bg = "white", inset = 0.01, + title = "Exposition principale des candidats :", + legend = c("débordement de cours d'eau", "débordement et ruissellement", "débordement d'étang", "remontée de nappe", "ruissellement", "rupture de digue"), + pch = 21, + col = "black", + pt.bg = c("blue", "lightblue", "hotpink1", "green", "brown", "orange"), + pt.cex = 1.4) + +## Ajout de l'encart +# geau::add.inset(soii_france, col = c("white", "red"), border = c("lightgray", "red"), lwd = 2) + +## Fermeture du fichier de sauvegarde +dev.off() +``` + + +```{r annee_emmenagement} +# Production d'une carte + +## Définition du nom du fichier de sauvegarde +file_path = file.path("data-common/figure/so-ii/pdf/2021-07-20/annee_emmenagement.pdf") + +## Récupération des données propre à la carte en cours +roi_habitant = rio::import("data-common/table/so-ii/roi-habitant-2021-07-20.ods", which = 1) +roi_habitant = roi_habitant[!is.na(roi_habitant$latitude), ] + +## Transformation des données d'enquête en points géoréférencés +roi_habitant = sf::st_as_sf(roi_habitant, coords = c("longitude", "latitude"), crs = "WGS84") + +# Génération de la carte + +## Ouverture du fichier de sauvegarde +# png(file_path, height = 800, width = 800) +pdf(file_path) + +## Initialisation de la carte avec le périmètre de so-ii +par(mai = c(.65, .60, .50, .15)) +plot(soii, axes = TRUE) +# terra::plotRGB(soii_osm, add = TRUE) +plot(soii, lwd = 2, add = TRUE) + +## Ajout du fond CLC avec le niveau 1 du code_18 +color_clc = scales::alpha(c("red3", "darkolivegreen3", "darkgreen", "#4C90B4", "lightblue"), .2) +color = as.character(cut( + as.integer(substr(soii_clc[["code_18"]], 1, 1)), + breaks = 5, + labels = color_clc)) +plot(soii_clc$geometry, border = NA, col = color, add = TRUE) + +## Ajout des points d'enquête +# plot(roi_habitant$geometry, col = "red", bg = "red", pch = 21, cex = 1, add = TRUE) +plot(roi_habitant$geometry[ + roi_habitant[["annee_emmenagement"]] >= 2000 & + roi_habitant[["statut_personne"]] == "candidat" + ], + col = "black", bg = "white", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[ + roi_habitant[["annee_emmenagement"]] < 2000 & + roi_habitant[["annee_emmenagement"]] >= 1987 & + roi_habitant[["statut_personne"]] == "candidat" + ], + col = "black", bg = "lightcoral", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[ & + roi_habitant[["annee_emmenagement"]] == 1970 & + roi_habitant[["statut_personne"]] == "candidat" + ], + col = "black", bg = "brown", cex = 1.4, + pch = 21, add = TRUE) + +## Ajout des crédits +# text(3.55, 43.435, credit, adj = 0, cex = .8, font = 3) + +## Légende +# legend("topright", cex = .8, bg = "white", inset = 0.01, + # title = "Land Use (from CLC)", + # legend = c( + # "Urban area", + # "Agricultural area", + # "Forest, natural area", + # "Humid area", + # "Water surface"), + # fill = color_clc) + +legend("bottomright", cex = .8, bg = "white", inset = 0.01, + title = "Année d'emménagement des candidats :", + legend = c("2000-2021", "1987-2000", "1970-1987", "Avant 1970"), + pch = 21, + col = "black", + pt.bg = c("white", "lightcoral", "red", "brown"), + pt.cex = 1.4) + +## Ajout de l'encart +# geau::add.inset(soii_france, col = c("white", "red"), border = c("lightgray", "red"), lwd = 2) + +## Fermeture du fichier de sauvegarde +dev.off() +``` + +```{r age_candidats} +# Production d'une carte + +## Définition du nom du fichier de sauvegarde +file_path = file.path("data-common/figure/so-ii/pdf/2021-07-20/age_candidats.pdf") + +## Récupération des données propre à la carte en cours +roi_habitant = rio::import("data-common/table/so-ii/roi-habitant-2021-07-20.ods", which = 1) +roi_habitant = roi_habitant[!is.na(roi_habitant$latitude), ] + +## Transformation des données d'enquête en points géoréférencés +roi_habitant = sf::st_as_sf(roi_habitant, coords = c("longitude", "latitude"), crs = "WGS84") + +# Génération de la carte + +## Ouverture du fichier de sauvegarde +# png(file_path, height = 800, width = 800) +pdf(file_path) + +## Initialisation de la carte avec le périmètre de so-ii +par(mai = c(.65, .60, .50, .15)) +plot(soii, axes = TRUE) +# terra::plotRGB(soii_osm, add = TRUE) +plot(soii, lwd = 2, add = TRUE) + +## Ajout du fond CLC avec le niveau 1 du code_18 +color_clc = scales::alpha(c("red3", "darkolivegreen3", "darkgreen", "#4C90B4", "lightblue"), .2) +color = as.character(cut( + as.integer(substr(soii_clc[["code_18"]], 1, 1)), + breaks = 5, + labels = color_clc)) +plot(soii_clc$geometry, border = NA, col = color, add = TRUE) + +## Ajout des points d'enquête +# plot(roi_habitant$geometry, col = "red", bg = "red", pch = 21, cex = 1, add = TRUE) +plot(roi_habitant$geometry[roi_habitant[["tranche_age"]] == "+71 ans" & + roi_habitant[["statut_personne"]] == "candidat" + ], + col = "black", bg = "coral4", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[roi_habitant[["tranche_age"]] == "51-70" & + roi_habitant[["statut_personne"]] == "candidat" + ], + col = "black", bg = "brown2", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[roi_habitant[["tranche_age"]] == "31-50" & + roi_habitant[["statut_personne"]] == "candidat" + ], + col = "black", bg = "orange", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[roi_habitant[["tranche_age"]] == "18-30" & + roi_habitant[["statut_personne"]] == "candidat" + ], + col = "black", bg = "gold", cex = 1.4, + pch = 21, add = TRUE) + +## Ajout de l'échelle +# raster::scalebar(10, type = "bar", divs = 4, below = "km") +terra::sbar(10, c(3.55, 43.47), type = "bar", below = "km", label = c(0, 5, 10), cex = .8) + +## Ajout des crédits +# text(3.55, 43.435, credit, adj = 0, cex = .8, font = 3) + +## Légende +# legend("topright", cex = .8, bg = "white", inset = 0.01, + # title = "Land Use (from CLC)", + # legend = c( + # "Urban area", + # "Agricultural area", + # "Forest, natural area", + # "Humid area", + # "Water surface"), + # fill = color_clc) + +legend("bottomright", cex = .8, bg = "white", inset = 0.01, + title = "Tranches d'âge des candidats :", + legend = c("18-30", "31-50", "51-70", "+71 ans"), + pch = 21, + col = "black", + pt.bg = c("gold", "orange", "brown2", "coral4"), + pt.cex = 1.4) + +## Ajout de l'encart +# geau::add.inset(soii_france, col = c("white", "red"), border = c("lightgray", "red"), lwd = 2) + +## Fermeture du fichier de sauvegarde +dev.off() +``` + + +```{r ROI_agri} +# Production d'une carte + +## Définition du nom du fichier de sauvegarde +file_path = file.path("data-common/figure/so-ii/pdf/2021-07-20/roi_agri.pdf") + +## Récupération des données propre à la carte en cours +roi_habitant = rio::import("data-common/table/so-ii/roi-habitant-2021-07-20.ods", which = 1) +roi_habitant = roi_habitant[!is.na(roi_habitant$latitude), ] + +## Transformation des données d'enquête en points géoréférencés +roi_habitant = sf::st_as_sf(roi_habitant, coords = c("longitude", "latitude"), crs = "WGS84") + +# Génération de la carte + +## Ouverture du fichier de sauvegarde +# png(file_path, height = 800, width = 800) +pdf(file_path) + +## Initialisation de la carte avec le périmètre de so-ii +par(mai = c(.65, .60, .50, .15)) +plot(soii, axes = TRUE) +# terra::plotRGB(soii_osm, add = TRUE) +plot(soii, lwd = 2, add = TRUE) + +## Ajout du fond CLC avec le niveau 1 du code_18 +color_clc = scales::alpha(c("red3", "darkolivegreen3", "darkgreen", "#4C90B4", "lightblue"), .2) +color = as.character(cut( + as.integer(substr(soii_clc[["code_18"]], 1, 1)), + breaks = 5, + labels = color_clc)) +plot(soii_clc$geometry, border = NA, col = color, add = TRUE) + +## Ajout des points d'enquête +# plot(roi_habitant$geometry, col = "red", bg = "red", pch = 21, cex = 1, add = TRUE) +plot(roi_habitant$geometry[roi_habitant[["tranche_age"]] == "+71 ans"], + col = "black", bg = "brown", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[roi_habitant[["tranche_age"]] == "51-70"], + col = "black", bg = "red", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[roi_habitant[["tranche_age"]] == "31-50"], + col = "black", bg = "orange", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[roi_habitant[["tranche_age"]] == "18-30"], + col = "black", bg = "lightyellow", cex = 1.4, + pch = 21, add = TRUE) + +## Ajout de l'échelle +# raster::scalebar(10, type = "bar", divs = 4, below = "km") +terra::sbar(10, c(3.55, 43.47), type = "bar", below = "km", label = c(0, 5, 10), cex = .8) + +## Ajout des crédits +# text(3.55, 43.435, credit, adj = 0, cex = .8, font = 3) + +## Légende +# legend("topright", cex = .8, bg = "white", inset = 0.01, + # title = "Land Use (from CLC)", + # legend = c( + # "Urban area", + # "Agricultural area", + # "Forest, natural area", + # "Humid area", + # "Water surface"), + # fill = color_clc) + +legend("bottomright", cex = .8, bg = "white", inset = 0.01, + title = "Tranches d'âge des candidats :", + legend = c("18-30", "31-50", "51-70", "+71 ans"), + pch = 21, + col = "black", + pt.bg = c("lightyellow", "orange", "red", "brown"), + pt.cex = 1.4) + +## Ajout de l'encart +# geau::add.inset(soii_france, col = c("white", "red"), border = c("lightgray", "red"), lwd = 2) + +## Fermeture du fichier de sauvegarde +dev.off() +``` + + + +```{r experts_assurance} +# Production d'une carte + +## Définition du nom du fichier de sauvegarde +file_path = file.path("data-common/figure/so-ii/pdf/2021-07-20/experts_assurance.pdf") + +## Récupération des données propre à la carte en cours +experts_assurance = rio::import("data-common/table/so-ii/experts-assurance-2021.ods", which = 1) +experts_assurance = experts_assurance[!is.na(experts_assurance$latitude), ] + +## Transformation des données d'enquête en points géoréférencés +experts_assurance = sf::st_as_sf(experts_assurance, coords = c("longitude", "latitude"), crs = "WGS84") + +# Génération de la carte + +## Ouverture du fichier de sauvegarde +# png(file_path, height = 800, width = 800) +pdf(file_path) + +## Initialisation de la carte avec le périmètre de la France +par(mai = c(.65, .60, .50, .15)) +plot(soii_france, axes = TRUE) +# terra::plotRGB(soii_osm, add = TRUE) +plot(soii_france, lwd = 2, add = TRUE) + +## Ajout des points des bureaux d'expertise + +# plot(experts_assurance$geometry, col = "red", bg = "red", pch = 21, cex = 1, add = TRUE) +plot(experts_assurance$geometry[experts_assurance[["statut"]] == "Rencontré"], + col = "black", bg = "green", cex = 1.4, + pch = 21, add = TRUE) +plot(experts_assurance$geometry[experts_assurance[["statut"]] == "Contacté"], + col = "black", bg = "yellow", cex = 1.4, + pch = 21, add = TRUE) +plot(experts_assurance$geometry[experts_assurance[["statut"]] == "Prévu"], + col = "black", bg = "white", cex = 1.4, + pch = 21, add = TRUE) + +## Ajout de l'échelle +# raster::scalebar(10, type = "bar", divs = 4, below = "km") +terra::sbar(10, c(3.55, 43.47), type = "bar", below = "km", label = c(0, 5, 10), cex = .8) + +## Ajout des crédits +# text(3.55, 43.435, credit, adj = 0, cex = .8, font = 3) + +## Légende + +legend("bottomright", cex = .8, bg = "white", inset = 0.01, + title = "Rencontre avec les experts d'assurance :", + legend = c("Rencontré", "Contacté", "Prévu"), + pch = 21, + col = "black", + pt.bg = c("green", "yellow", "white"), + pt.cex = 1.4) + +## Ajout de l'encart +# geau::add.inset(soii_france, col = c("white", "red"), border = c("lightgray", "red"), lwd = 2) + +## Fermeture du fichier de sauvegarde +dev.off() +``` diff --git a/map/map-2021-08-31.rmd b/map/map-2021-08-31.rmd new file mode 100644 index 0000000000000000000000000000000000000000..498291a8cfae8e7be906798b94dc65371c02965f --- /dev/null +++ b/map/map-2021-08-31.rmd @@ -0,0 +1,675 @@ + +```{r data-recup} +# Récupération des données (à faire une fois) + +## Récupération du périmètre (déjà pré-traité) +soii = readRDS("data-common/data/so-ii/so-ii_perim.rds") + +## Récupération du périmètre dans France (déjà prétraité) +soii_france = readRDS("data-common/data/so-ii/so-ii_france.rds") + +## Récupération de CLC (déjà pré-traité) +soii_clc = readRDS("data-common/data/so-ii/so-ii_clc.rds") + +## Recupération des données du fond de carte +# soii_osm = maptiles::get_tiles(soii, provider = "OpenStreetMap.MapnikBW", crop = TRUE, zoom = 11) +# terra::writeRaster(soii_osm, "data-common/data/so-ii/so-ii_osm-bw.tif", overwrite = TRUE) +# soii_osm = terra::rast("data-common/data/so-ii/so-ii_osm-bw.tif") +# credit = sprintf("Background from %s", maptiles::get_credit("OpenStreetMap")) + +# Récupération des données habitant + +## Récupération des données propre à la carte en cours +roi_habitant = rio::import("data-common/table/so-ii/roi-habitant-2021-08-31.ods", which = 1) +roi_habitant = roi_habitant[!is.na(roi_habitant$latitude), ] +roi_habitant = roi_habitant[roi_habitant[["statut_personne"]] == "membre", ] + +## Transformation des données d'enquête en points géoréférencés +roi_habitant = sf::st_as_sf(roi_habitant, coords = c("longitude", "latitude"), crs = "WGS84") +``` + +```{r rex_2020} +# OK Production d'une carte + +## Définition du nom du fichier de sauvegarde +file_path = file.path("data-common/figure/so-ii/pdf/2021-08-31/rex_2020.pdf") + +## Récupération des données propre à la carte en cours +rex_2020 = rio::import("data-common/table/so-ii/rex-2020.ods", which = 1) +rex_2020 = rex_2020[!is.na(rex_2020$latitude), ] + +## Transformation des données d'enquête en points géoréférencés +rex_2020 = sf::st_as_sf(rex_2020, coords = c("longitude", "latitude"), crs = "WGS84") + +# Génération de la carte + +## Ouverture du fichier de sauvegarde +# png(file_path, height = 800, width = 800) +pdf(file_path) + +## Initialisation de la carte avec le périmètre de so-ii +par(mai = c(.65, .60, .50, .15)) +plot(soii, axes = TRUE) +# terra::plotRGB(soii_osm, add = TRUE) +plot(soii, lwd = 2, add = TRUE) + +## Ajout du fond CLC avec le niveau 1 du code_18 +color_clc = scales::alpha(c("red3", "darkolivegreen3", "darkgreen", "#4C90B4", "lightblue"), .2) +color = as.character(cut( + as.integer(substr(soii_clc[["code_18"]], 1, 1)), + breaks = 5, + labels = color_clc)) +plot(soii_clc$geometry, border = NA, col = color, add = TRUE) + +## Ajout des points d'enquête +# plot(rex_2020$geometry, col = "red", bg = "red", pch = 21, cex = 1, add = TRUE) +plot(rex_2020$geometry[rex_2020[["viticulture"]],], + col = "black", bg = "deeppink4", cex = 1.4, + pch = 21, add = TRUE) +plot(rex_2020$geometry[rex_2020[["habitant"]],], + col = "black", bg = "cornflowerblue", cex = 1.4, + pch = 21, add = TRUE) +# plot(rex_2020$geometry[rex_2020[["maraichage"]],], + # col = "black", bg = "green", cex = 1.4, + # pch = 21, add = TRUE) + +## Ajout de l'échelle +# raster::scalebar(10, type = "bar", divs = 4, below = "km") +terra::sbar(10, c(3.55, 43.47), type = "bar", below = "km", label = c(0, 5, 10), cex = .8) + +## Ajout des crédits +# text(3.55, 43.435, credit, adj = 0, cex = .8, font = 3) + +## Légende + +# legend("topright", cex = .8, bg = "white", inset = 0.01, + # title = "Land Use (from CLC)", + # legend = c( + # "Urban area", + # "Agricultural area", + # "Forest, natural area", + # "Humid area", + # "Water surface"), + # fill = color_clc) + +legend("bottomright", cex = .8, bg = "white", inset = 0.01, + title = "Enquêtes du REX 19 septembre 2020 :", + legend = c("Agriculteurs", "Habitants membre ROI"), + pch = 21, + col = "black", + pt.bg = c("deeppink4", "cornflowerblue"), + pt.cex = 1.4) + +## Ajout de l'encart +# geau::add.inset(soii_france, col = c("white", "red"), border = c("lightgray", "red"), lwd = 2) + +## Fermeture du fichier de sauvegarde +dev.off() +``` + +```{r roi_agri} +# Production d'une carte + +## Définition du nom du fichier de sauvegarde +file_path = file.path("data-common/figure/so-ii/pdf/2021-08-31/roi_agri.pdf") + +## Récupération des données propre à la carte en cours +roi_agri = rio::import("data-common/table/so-ii/roi-agri.ods", which = 1) +roi_agri = roi_agri[!is.na(roi_agri$latitude), ] + +## Transformation des données d'enquête en points géoréférencés +roi_agri = sf::st_as_sf(roi_agri, coords = c("longitude", "latitude"), crs = "WGS84") + +# Génération de la carte + +## Ouverture du fichier de sauvegarde +# png(file_path, height = 800, width = 800) +pdf(file_path) + +## Initialisation de la carte avec le périmètre de so-ii +par(mai = c(.65, .60, .50, .15)) +plot(soii, axes = TRUE) +# terra::plotRGB(soii_osm, add = TRUE) +plot(soii, lwd = 2, add = TRUE) + +## Ajout du fond CLC avec le niveau 1 du code_18 +color_clc = scales::alpha(c("red3", "darkolivegreen3", "darkgreen", "#4C90B4", "lightblue"), .2) +color = as.character(cut( + as.integer(substr(soii_clc[["code_18"]], 1, 1)), + breaks = 5, + labels = color_clc)) +plot(soii_clc$geometry, border = NA, col = color, add = TRUE) + +## Ajout des points d'enquête +# plot(roi_agri$geometry, col = "red", bg = "red", pch = 21, cex = 1, add = TRUE) +plot(roi_agri$geometry[roi_agri[["activite"]] == "loisirs"], + col = "black", bg = "gray", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_agri$geometry[roi_agri[["activite"]] == "arboriculture"], + col = "black", bg = "lightblue", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_agri$geometry[roi_agri[["activite"]] == "cereales"], + col = "black", bg = "yellow", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_agri$geometry[roi_agri[["activite"]] == "horticulture"], + col = "black", bg = "lightpink", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_agri$geometry[roi_agri[["activite"]] == "elevage"], + col = "black", bg = "orangered4", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_agri$geometry[roi_agri[["activite"]] == "maraichage"], + col = "black", bg = "springgreen2", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_agri$geometry[roi_agri[["activite"]] == "viticulture"], + col = "black", bg = "magenta4", cex = 1.4, + pch = 21, add = TRUE) + +## Ajout de l'échelle +# raster::scalebar(10, type = "bar", divs = 4, below = "km") +terra::sbar(10, c(3.55, 43.47), type = "bar", below = "km", label = c(0, 5, 10), cex = .8) + +## Ajout des crédits +# text(3.55, 43.435, credit, adj = 0, cex = .8, font = 3) + +## Légende + +# legend("topright", cex = .8, bg = "white", inset = 0.01, + # title = "Land Use (from CLC)", + # legend = c( + # "Urban area", + # "Agricultural area", + # "Forest, natural area", + # "Humid area", + # "Water surface"), + # fill = color_clc) + +legend("bottomright", cex = .8, bg = "white", inset = 0.01, + title = "Contacts pris :", + legend = c("loisirs", "arboriculture", "cereales", "horticulture", "elevage", "maraichage","viticulture"), + pch = 21, + col = "black", + pt.bg = c("gray", "lightblue", "yellow", "lightpink", "orangered4", "springgreen2", "magenta4"), + pt.cex = 1.4) + +## Ajout de l'encart +# geau::add.inset(soii_france, col = c("white", "red"), border = c("lightgray", "red"), lwd = 2) + +## Fermeture du fichier de sauvegarde +dev.off() +``` + +```{r roi-presence} +# Production d'une carte + +## Définition du nom du fichier de sauvegarde +file_path = file.path("data-common/figure/so-ii/pdf/2021-08-31/roi_presence.pdf") + +# Génération de la carte + +## Ouverture du fichier de sauvegarde +# png(file_path, height = 800, width = 800) +pdf(file_path) + +## Initialisation de la carte avec le périmètre de so-ii +par(mai = c(.65, .60, .50, .15)) +plot(soii, axes = TRUE) +# terra::plotRGB(soii_osm, add = TRUE) +plot(soii, lwd = 2, add = TRUE) + +## Ajout du fond CLC avec le niveau 1 du code_18 +color_clc = scales::alpha(c("red3", "darkolivegreen3", "darkgreen", "#4C90B4", "lightblue"), .2) +color = as.character(cut( + as.integer(substr(soii_clc[["code_18"]], 1, 1)), + breaks = 5, + labels = color_clc)) +plot(soii_clc$geometry, border = NA, col = color, add = TRUE) + +## Ajout des points d'enquête +# plot(roi_habitant$geometry, col = "red", bg = "red", pch = 21, cex = 1, add = TRUE) +plot(roi_habitant$geometry[roi_habitant[["presence_atelier"]] == "non"], + col = "black", bg = "black", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[roi_habitant[["presence_atelier"]] == "2021-07-20"], + col = "black", bg = "lightgray", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[roi_habitant[["presence_atelier"]] == "2021-08-31"], + col = "black", bg = "white", cex = 1.4, + pch = 21, add = TRUE) + +## Ajout de l'échelle +# raster::scalebar(10, type = "bar", divs = 4, below = "km") +terra::sbar(10, c(3.55, 43.47), type = "bar", below = "km", label = c(0, 5, 10), cex = .8) + +## Ajout des crédits +# text(3.55, 43.435, credit, adj = 0, cex = .8, font = 3) + +## Légende + +# legend("topright", cex = .8, bg = "white", inset = 0.01, + # title = "Land Use (from CLC)", + # legend = c( + # "Urban area", + # "Agricultural area", + # "Forest, natural area", + # "Humid area", + # "Water surface"), + # fill = color_clc) + +legend("bottomright", cex = .8, bg = "white", inset = 0.01, + title = "Membres", + legend = c( + sprintf("Présents (%s)", sum(roi_habitant[["presence_atelier"]] == "2021-08-31")), + sprintf("Présents en juillet (%s)", sum(roi_habitant[["presence_atelier"]] == "2021-07-20")), + sprintf("Non présents (%s)", sum(roi_habitant[["presence_atelier"]] == "non"))), + pch = 21, + col = "black", + pt.bg = c("white", "lightgray", "black"), + pt.cex = 1.4) + +## Ajout de l'encart +# geau::add.inset(soii_france, col = c("white", "red"), border = c("lightgray", "red"), lwd = 2) + +## Fermeture du fichier de sauvegarde +dev.off() +``` + +```{r roi-inondation} +# Production d'une carte + +## Définition du nom du fichier de sauvegarde +file_path = file.path("data-common/figure/so-ii/pdf/2021-08-31/roi_inondation.pdf") + +# Génération de la carte + +## Ouverture du fichier de sauvegarde +# png(file_path, height = 800, width = 800) +pdf(file_path) + +## Initialisation de la carte avec le périmètre de so-ii +par(mai = c(.65, .60, .50, .15)) +plot(soii, axes = TRUE) +# terra::plotRGB(soii_osm, add = TRUE) +plot(soii, lwd = 2, add = TRUE) + +## Ajout du fond CLC avec le niveau 1 du code_18 +color_clc = scales::alpha(c("red3", "darkolivegreen3", "darkgreen", "#4C90B4", "lightblue"), .2) +color = as.character(cut( + as.integer(substr(soii_clc[["code_18"]], 1, 1)), + breaks = 5, + labels = color_clc)) +plot(soii_clc$geometry, border = NA, col = color, add = TRUE) + +## Ajout des points d'enquête +# plot(roi_habitant$geometry, col = "red", bg = "red", pch = 21, cex = 1, add = TRUE) +plot(roi_habitant$geometry[roi_habitant[["type_alea"]] == "debordement-cours-eau"], + col = "black", bg = "dodgerblue", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[roi_habitant[["type_alea"]] == "ruissellement"], + col = "black", bg = "red", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[roi_habitant[["type_alea"]] == "debordement-etang"], + col = "black", bg = "lightseagreen", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[roi_habitant[["type_alea"]] == "remontee-nappe"], + col = "black", bg = "sandybrown", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[roi_habitant[["type_alea"]] == "rupture-digue"], + col = "black", bg = "gray53", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[roi_habitant[["type_alea"]] == "non-inonde"], + col = "black", bg = "floralwhite", cex = 1.4, + pch = 21, add = TRUE) + +## Ajout de l'échelle +# raster::scalebar(10, type = "bar", divs = 4, below = "km") +terra::sbar(10, c(3.55, 43.47), type = "bar", below = "km", label = c(0, 5, 10), cex = .8) + +## Ajout des crédits +# text(3.55, 43.435, credit, adj = 0, cex = .8, font = 3) + +## Légende"white", +# legend("topright", cex = .8, bg = "white", inset = 0.01, + # title = "Land Use (from CLC)", + # legend = c( + # "Urban area", + # "Agricultural area", + # "Forest, natural area", + # "Humid area", + # "Water surface"), + # fill = color_clc) + +legend("bottomright", cex = .8, bg = "white", inset = 0.01, + title = "Types d'aléas :", + legend = c( + sprintf("débordement de cours d'eau (%s)", sum(roi_habitant[["type_alea"]] == "debordement-cours-eau")), + sprintf("ruissellement (%s)", sum(roi_habitant[["type_alea"]] == "ruissellement")), + sprintf("débordement d'étang (%s)", sum(roi_habitant[["type_alea"]] == "debordement-etang")), + sprintf("remontée de nappe (%s)", sum(roi_habitant[["type_alea"]] == "remontee-nappe")), + sprintf("rupture digue (%s)", sum(roi_habitant[["type_alea"]] == "rupture-digue")), + sprintf("non inondé (%s)", sum(roi_habitant[["type_alea"]] == "non-inonde"))), + pch = c(21, 21, 21, 21, 21, 21), + col = "black", + pt.bg = c("dodgerblue", "red", "lightseagreen", "sandybrown", "gray53", "floralwhite"), + pt.cex = 1.4) + +## Ajout de l'encart +# geau::add.inset(soii_france, col = c("white", "red"), border = c("lightgray", "red"), lwd = 2), +## Fermeture du fichier de sauvegarde +dev.off() +``` + + +```{r roi-origine} +# Production d'une carte + +## Définition du nom du fichier de sauvegarde +file_path = file.path("data-common/figure/so-ii/pdf/2021-08-31/roi_origine.pdf") + +# Génération de la carte + +## Ouverture du fichier de sauvegarde +# png(file_path, height = 800, width = 800) +pdf(file_path) + +## Initialisation de la carte avec le périmètre de so-ii +par(mai = c(.65, .60, .50, .15)) +plot(soii, axes = TRUE) +# terra::plotRGB(soii_osm, add = TRUE) +plot(soii, lwd = 2, add = TRUE) + +## Ajout du fond CLC avec le niveau 1 du code_18 +color_clc = scales::alpha(c("red3", "darkolivegreen3", "darkgreen", "#4C90B4", "lightblue"), .2) +color = as.character(cut( + as.integer(substr(soii_clc[["code_18"]], 1, 1)), + breaks = 5, + labels = color_clc)) +plot(soii_clc$geometry, border = NA, col = color, add = TRUE) + +## Ajout des points d'enquête +# plot(roi_habitant$geometry, col = "red", bg = "red", pch = 21, cex = 1, add = TRUE) +plot(roi_habitant$geometry[roi_habitant[["Origine"]] == "REX-2021"], + col = "black", bg = "bisque", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[roi_habitant[["Origine"]] == "PI-M2-ES-2020"], + col = "black", bg = "gold", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[roi_habitant[["Origine"]] == "Stage-M2-ES-2020"], + col = "black", bg = "darkgoldenrod3", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[roi_habitant[["Origine"]] == "PI-M2-ES-2019"], + col = "black", bg = "sienna4", cex = 1.4, + pch = 21, add = TRUE) + +## Ajout de l'échelle +# raster::scalebar(10, type = "bar", divs = 4, below = "km") +terra::sbar(10, c(3.55, 43.47), type = "bar", below = "km", label = c(0, 5, 10), cex = .8) + +## Ajout des crédits +# text(3.55, 43.435, credit, adj = 0, cex = .8, font = 3) + +## Légende +# legend("topright", cex = .8, bg = "white", inset = 0.01, + # title = "Land Use (from CLC)", + # legend = c( + # "Urban area", + # "Agricultural area", + # "Forest, natural area", + # "Humid area", + # "Water surface"), + # fill = color_clc) + +legend("bottomright", cex = .8, bg = "white", inset = 0.01, + title = "Origine des membres :", + legend = c( + sprintf("2019 PI Master ES (%s)", sum(roi_habitant[["Origine"]] == "PI-M2-ES-2019")), + sprintf("2020 Stage Master ES (%s)", sum(roi_habitant[["Origine"]] == "Stage-M2-ES-2020")), + sprintf("2020 PI Master ES (%s)", sum(roi_habitant[["Origine"]] == "PI-M2-ES-2020")), + sprintf("2021 REX (%s)", sum(roi_habitant[["Origine"]] == "REX-2021")) + ), + pch = 21, + col = "black", + pt.bg = c("sienna4", "darkgoldenrod3", "gold", "bisque"), + pt.cex = 1.4) + +## Ajout de l'encart +# geau::add.inset(soii_france, col = c("white", "red"), border = c("lightgray", "red"), lwd = 2) + +## Fermeture du fichier de sauvegarde +dev.off() +``` + +```{r roi-emmenagement} +# Production d'une carte + +## Définition du nom du fichier de sauvegarde +file_path = file.path("data-common/figure/so-ii/pdf/2021-08-31/roi_emmenagement.pdf") + +# Génération de la carte + +## Ouverture du fichier de sauvegarde +# png(file_path, height = 800, width = 800) +pdf(file_path) + +## Initialisation de la carte avec le périmètre de so-ii +par(mai = c(.65, .60, .50, .15)) +plot(soii, axes = TRUE) +# terra::plotRGB(soii_osm, add = TRUE) +plot(soii, lwd = 2, add = TRUE) + +## Ajout du fond CLC avec le niveau 1 du code_18 +color_clc = scales::alpha(c("red3", "darkolivegreen3", "darkgreen", "#4C90B4", "lightblue"), .2) +color = as.character(cut( + as.integer(substr(soii_clc[["code_18"]], 1, 1)), + breaks = 5, + labels = color_clc)) +plot(soii_clc$geometry, border = NA, col = color, add = TRUE) + +## Ajout des points d'enquête +# plot(roi_habitant$geometry, col = "red", bg = "red", pch = 21, cex = 1, add = TRUE) +plot(roi_habitant$geometry[ + roi_habitant[["annee_emmenagement"]] >= 1970 & roi_habitant[["annee_emmenagement"]] <= 1987 + ], + col = "black", bg = "mediumorchid4", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[ + roi_habitant[["annee_emmenagement"]] >= 1988 & roi_habitant[["annee_emmenagement"]] <= 2000 + ], + col = "black", bg = "mediumorchid1", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[roi_habitant[["annee_emmenagement"]] >= 2001], + col = "black", bg = "lightpink1", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[roi_habitant[["annee_emmenagement"]] < 1970], + col = "black", bg = "navyblue", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[is.na(roi_habitant[["annee_emmenagement"]])], + col = "black", bg = "floralwhite", cex = 1.4, + pch = 21, add = TRUE) + +## Ajout des crédits +# text(3.55, 43.435, credit, adj = 0, cex = .8, font = 3) + +## Légende +# legend("topright", cex = .8, bg = "white", inset = 0.01, + # title = "Land Use (from CLC)", + # legend = c( + # "Urban area", + # "Agricultural area", + # "Forest, natural area", + # "Humid area", + # "Water surface"), + # fill = color_clc) + +legend("bottomright", cex = .8, bg = "white", inset = 0.01, + title = "Année d'emménagement des membres :", + legend = c( + sprintf("2001-2021 (%s)", sum(na.rm = TRUE, + roi_habitant[["annee_emmenagement"]] >= 2001 + )), + sprintf("1988-2000 (%s)", sum(na.rm = TRUE, + roi_habitant[["annee_emmenagement"]] >= 1988 & roi_habitant[["annee_emmenagement"]] <= 2000 + )), + sprintf("1970-1987 (%s)", sum(na.rm = TRUE, + roi_habitant[["annee_emmenagement"]] >= 1970 & roi_habitant[["annee_emmenagement"]] <= 1987 + )), + sprintf("Avant 1970 (%s)", sum(na.rm = TRUE, + roi_habitant[["annee_emmenagement"]] < 1970 + )), + sprintf("Date inconnue (%s)", sum(is.na(roi_habitant[["annee_emmenagement"]]))) + ), + pch = 21, + col = "black", + pt.bg = c("lightpink1", "mediumorchid1", "mediumorchid4", "navyblue", "floralwhite"), + pt.cex = 1.4) + +## Ajout de l'encart +# geau::add.inset(soii_france, col = c("white", "red"), border = c("lightgray", "red"), lwd = 2) + +## Fermeture du fichier de sauvegarde +dev.off() +``` + +```{r roi-age} +# Production d'une carte + +## Définition du nom du fichier de sauvegarde +file_path = file.path("data-common/figure/so-ii/pdf/2021-08-31/roi_age.pdf") + +# Génération de la carte + +## Ouverture du fichier de sauvegarde +# png(file_path, height = 800, width = 800) +pdf(file_path) + +## Initialisation de la carte avec le périmètre de so-ii +par(mai = c(.65, .60, .50, .15)) +plot(soii, axes = TRUE) +# terra::plotRGB(soii_osm, add = TRUE) +plot(soii, lwd = 2, add = TRUE) + +## Ajout du fond CLC avec le niveau 1 du code_18 +color_clc = scales::alpha(c("red3", "darkolivegreen3", "darkgreen", "#4C90B4", "lightblue"), .2) +color = as.character(cut( + as.integer(substr(soii_clc[["code_18"]], 1, 1)), + breaks = 5, + labels = color_clc)) +plot(soii_clc$geometry, border = NA, col = color, add = TRUE) + +## Ajout des points d'enquête +# plot(roi_habitant$geometry, col = "red", bg = "red", pch = 21, cex = 1, add = TRUE) +plot(roi_habitant$geometry[roi_habitant[["tranche_age"]] == "51-70"], + col = "black", bg = "brown2", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[roi_habitant[["tranche_age"]] == "18-30"], + col = "black", bg = "white", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[roi_habitant[["tranche_age"]] == "31-50"], + col = "black", bg = "gold", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[roi_habitant[["tranche_age"]] == "+71 ans"], + col = "black", bg = "coral4", cex = 1.4, + pch = 21, add = TRUE) +plot(roi_habitant$geometry[is.na(roi_habitant[["tranche_age"]])], + col = "black", bg = "lightblue", cex = 1.4, + pch = 21, add = TRUE) + +## Ajout de l'échelle +# raster::scalebar(10, type = "bar", divs = 4, below = "km") +terra::sbar(10, c(3.55, 43.47), type = "bar", below = "km", label = c(0, 5, 10), cex = .8) + +## Ajout des crédits +# text(3.55, 43.435, credit, adj = 0, cex = .8, font = 3) + +## Légende +# legend("topright", cex = .8, bg = "white", inset = 0.01, + # title = "Land Use (from CLC)", + # legend = c( + # "Urban area", + # "Agricultural area", + # "Forest, natural area", + # "Humid area", + # "Water surface"), + # fill = color_clc) + +legend("bottomright", cex = .8, bg = "white", inset = 0.01, + title = "Tranches d'âge des membres :", + legend = c( + sprintf("18-30 (%s)", sum(roi_habitant[["tranche_age"]] == "18-30", na.rm = TRUE)), + sprintf("31-50 (%s)", sum(roi_habitant[["tranche_age"]] == "31-50", na.rm = TRUE)), + sprintf("51-70 (%s)", sum(roi_habitant[["tranche_age"]] == "51-70", na.rm = TRUE)), + sprintf("+71 ans (%s)", sum(roi_habitant[["tranche_age"]] == "+71 ans", na.rm = TRUE)), + sprintf("inconnu (%s)", sum(is.na(roi_habitant[["tranche_age"]]))) + ), + pch = 21, + col = "black", + pt.bg = c("white", "gold", "brown2", "coral4", "lightblue"), + pt.cex = 1.4) + +## Ajout de l'encart +# geau::add.inset(soii_france, col = c("white", "red"), border = c("lightgray", "red"), lwd = 2) + +## Fermeture du fichier de sauvegarde +dev.off() +``` + +```{r experts_assurance} +# Production d'une carte + +## Définition du nom du fichier de sauvegarde +file_path = file.path("data-common/figure/so-ii/pdf/2021-08-31/experts_assurance.pdf") + +## Récupération des données propre à la carte en cours +experts_assurance = rio::import("data-common/table/so-ii/experts-assurance-2021.ods", which = 1) +experts_assurance = experts_assurance[!is.na(experts_assurance$latitude), ] + +## Transformation des données d'enquête en points géoréférencés +experts_assurance = sf::st_as_sf(experts_assurance, coords = c("longitude", "latitude"), crs = "WGS84") + +# Génération de la carte + +## Ouverture du fichier de sauvegarde +# png(file_path, height = 800, width = 800) +pdf(file_path) + +## Initialisation de la carte avec le périmètre de la France +par(mai = c(.65, .60, .50, .15)) +plot(soii_france, axes = TRUE) +# terra::plotRGB(soii_osm, add = TRUE) +plot(soii_france, lwd = 2, add = TRUE) + +## Ajout des points des bureaux d'expertise + +# plot(experts_assurance$geometry, col = "red", bg = "red", pch = 21, cex = 1, add = TRUE) +plot(experts_assurance$geometry[experts_assurance[["statut"]] == "Rencontré"], + col = "black", bg = "green", cex = 1.4, + pch = 21, add = TRUE) +plot(experts_assurance$geometry[experts_assurance[["statut"]] == "Contacté"], + col = "black", bg = "yellow", cex = 1.4, + pch = 21, add = TRUE) +plot(experts_assurance$geometry[experts_assurance[["statut"]] == "Prévu"], + col = "black", bg = "white", cex = 1.4, + pch = 21, add = TRUE) + +## Ajout de l'échelle +# raster::scalebar(10, type = "bar", divs = 4, below = "km") +terra::sbar(10, c(3.55, 43.47), type = "bar", below = "km", label = c(0, 5, 10), cex = .8) + +## Ajout des crédits +# text(3.55, 43.435, credit, adj = 0, cex = .8, font = 3) + +## Légende + +legend("bottomright", cex = .8, bg = "white", inset = 0.01, + title = "Rencontre avec les experts d'assurance :", + legend = c("Rencontré", "Contacté", "Prévu"), + pch = 21, + col = "black", + pt.bg = c("green", "yellow", "white"), + pt.cex = 1.4) + +## Ajout de l'encart +# geau::add.inset(soii_france, col = c("white", "red"), border = c("lightgray", "red"), lwd = 2) + +## Fermeture du fichier de sauvegarde +dev.off() +``` diff --git a/map/map-logo.rmd b/map/map-logo.rmd new file mode 100644 index 0000000000000000000000000000000000000000..64df1f5351f0ba6cdbc4cb63d2bf703dbf592f5e --- /dev/null +++ b/map/map-logo.rmd @@ -0,0 +1,63 @@ + +```{r data-recup} +library(sf) +# Récupération des données (à faire une fois) + +## Récupération du périmètre (déjà pré-traité) +so_ii = readRDS("data-common/data/so-ii/so-ii_perim.rds") + +## Récupération de CLC (déjà pré-traité) +so_ii_clc = readRDS("data-common/data/so-ii/so-ii_clc.rds") + +## Récupération des cours d'eau +river = sf::read_sf("data-common/data/so-ii/topage-2021-09/cours-eau-so-ii.shp") +river = sf::st_transform(river, crs = sf::st_crs(so_ii)) + +selection = c( + "le Salaison", + "la Lironde", + "la Mosson", + "le Terrieu", + "le Lez", + "le Bérange", + "le Lirou", + "la Cadoule", + "Ruisseau du Coulazou" +) +river = river[river[["TopoOH"]] %in% selection, ] +``` + +```{r logo} +## Définition du nom du fichier de sauvegarde +file_path = file.path("data-common/figure/so-ii/pdf/so_ii.pdf") + +# Génération de la carte + +## Ouverture du fichier de sauvegarde +# png(file_path, height = 800, width = 800) +pdf(file_path) + +## Initialisation de la carte avec le périmètre de so-ii +par(mai = c(.65, .60, .50, .15)) +# so_ii_epure = sf::st_simplify(so_ii, dTolerance = 333) +# plot(so_ii_epure, lwd = 4, col = scales::alpha("orange", .333)) + +so_ii_epure = rmapshaper::ms_simplify(so_ii, keep = 0.04) +plot(so_ii_epure, lwd = 6, col = scales::alpha("#e95d0fff", .5), border = "#004494ff") + +# ## Ajout du fond CLC avec le niveau 1 du code_18 +# color_clc = scales::alpha( +# c("#FF2A2A", "#008400", "#008400", "#008400", "#002fa7ff"), +# c(.5, .25, .35, .15, 1) +# ) +# # color_clc = scales::alpha(c("black", "darkolivegreen3", "darkolivegreen3", "lightblue", "lightblue"), .5) +# color = as.character(cut( +# as.integer(substr(so_ii_clc[["code_18"]], 1, 1)), +# breaks = 5, +# labels = color_clc)) +# plot(so_ii_clc$geometry, border = NA, col = color, add = TRUE) + +# plot(river$geometry, lwd = 3, col = "#002fa7ff", add = TRUE) + +dev.off() +``` diff --git a/map/map_so_ii.R b/map/map_so_ii.R new file mode 100644 index 0000000000000000000000000000000000000000..2283457c9f1b9ec607f97f6eb6fa28f3d2bff000 --- /dev/null +++ b/map/map_so_ii.R @@ -0,0 +1,76 @@ +# Data to be included in library +so_ii = readRDS("data-common/data/so-ii/so-ii_perim.rds") +so_ii_clc = readRDS("data-common/data/so-ii/so-ii_clc.rds") + +# Map + +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" = pdf(path), + "png" = png(path), + error(sprintf("%s not recognized", tolower(tools::file_ext(path)))) + ) + } + + ## Init map + par(mai = c(.65, .60, .50, .15)) + plot(so_ii, axes = TRUE) + plot(so_ii, lwd = 2, add = TRUE) + + if ("clc" %in% theme) { + color_clc = scales::alpha(c("red3", "darkolivegreen3", "darkgreen", "#4C90B4", "lightblue"), .2) + color = as.character(cut( + as.integer(substr(so_ii_clc[["code_18"]], 1, 1)), + breaks = 5, + labels = color_clc)) + plot(so_ii_clc$geometry, border = NA, col = 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(legend, dataset_legend) + } + + if (!is.null(path)) invisible(dev.off()) +} + + +# Data to be plot +dataset = rio::import("data-common/table/so-ii/rex-2020.ods", which = 1) +dataset = dataset[!is.na(dataset$latitude), ] +dataset = sf::st_as_sf(dataset, coords = c("longitude", "latitude"), crs = "WGS84") + +# Color +bg = rep(NA, nrow(dataset)) +bg[dataset[["viticulture"]]] = "deeppink4" +bg[dataset[["habitant"]]] = "cornflowerblue" +col = "black" +cex = 1.4 +pch = 21 + +# Legend +dataset_legend = list( + title = "Enquêtes du REX 19 septembre 2020", + legend = c("Agriculteurs", "Habitants membre ROI"), + pch = 21, + pt.bg = c("deeppink4", "cornflowerblue"), + pt.cex = 1.4 +) + +map_so_ii(dataset, dataset_legend, path = "toto.pdf", bg = bg, cex = cex, col = col, pch = pch) +map_so_ii(dataset, dataset_legend, path = "toto.png", bg = bg, cex = cex, col = col, pch = pch) +map_so_ii(dataset, dataset_legend, path = "toto.pdf", bg = bg, pch = 22) \ No newline at end of file diff --git a/map_so_ii.rmd b/map_so_ii.rmd index 870f96a2a8424433d1c6d9f691ed32ae47ae398e..b77ea05555b2049509db4395312065b02bf9a597 100644 --- a/map_so_ii.rmd +++ b/map_so_ii.rmd @@ -12,17 +12,23 @@ bg[dataset[["habitant"]]] = "cornflowerblue" col = "black" cex = 1.4 pch = 21 +pch[dataset[["viticulture"]]] = 21 +pch[dataset[["habitant"]]] = 22 # Legend definition dataset_legend = list( title = "Enquêtes du REX 19 septembre 2020", - legend = c("Agriculteurs", "Habitants membre ROI"), - pch = 21, + legend = c("Agriculteur", "Habitant"), + pch = c(21, 22), pt.bg = c("deeppink4", "cornflowerblue"), - pt.cex = 1.4 + pt.cex = cex ) -map_so_ii(dataset, dataset_legend, path = "toto.pdf", bg = bg, cex = cex, col = col, pch = pch) -map_so_ii(dataset, dataset_legend, path = "toto.png", bg = bg, cex = cex, col = col, pch = pch) -map_so_ii(dataset, dataset_legend, path = "toto.pdf", bg = bg, pch = 22) -map_so_ii(dataset, dataset_legend, path = "toto.pdf", bg = bg, pch = 22, theme = "gaspar") \ No newline at end of file +map_so_ii(dataset, dataset_legend, bg = bg, pch = pch, theme = "clc", legend_theme = TRUE) +map_so_ii(dataset, dataset_legend, bg = bg, pch = pch, theme = "catnat", year = 2020, legend_theme = TRUE) +map_so_ii(dataset, dataset_legend, bg = bg, pch = pch, theme = "catnat", year = 2020, hazard = "nappe", legend_theme = TRUE) +map_so_ii(dataset, dataset_legend, bg = bg, pch = pch, theme = "population", legend_theme = TRUE) + +map_so_ii(dataset, dataset_legend, path = "rex-clc.pdf", bg = bg, pch = pch, theme = "clc", year = 2020, legend_theme = TRUE) +map_so_ii(dataset, dataset_legend, path = "rex-catnat.pdf", bg = bg, pch = pch, theme = "catnat", year = 2020, legend_theme = TRUE) +map_so_ii(dataset, dataset_legend, path = "rex-population.pdf", bg = bg, pch = pch, theme = "population", legend_theme = TRUE) \ No newline at end of file diff --git a/script/gaspar.R b/script/gaspar.R new file mode 100644 index 0000000000000000000000000000000000000000..07c31a5e01a90a0a3a695a5644ea25ce3456ea72 --- /dev/null +++ b/script/gaspar.R @@ -0,0 +1,89 @@ +# Functions + +plot_chronicle = function(catnat, file_path = "catnat-chronicle.pdf") { + year.month = format(catnat[["date.start"]], "%Y-%m") + n.ym = table(year.month) + d.ym = as.Date(paste(names(n.ym), "01", sep = "-")) + + pdf(file_path, width = 20, height = 10) + plot(d.ym, as.integer(n.ym), type = "h", xaxt = "n", xlab = "", ylab = "n", col = "royalblue3") + axis.Date(1, format = "%Y-%m", las = 2, at = d.ym) + axis.Date(1, format = "%Y-%m", las = 2, label = FALSE, + at = seq(range(d.ym)[1], range(d.ym)[2], by = "month")) + dev.off() +} + +plot_month = function(catnat, file_path = "catnat-month.pdf") { + month = format(seq(as.Date("2020-01-01"), length.out = 12, by = "month"), "%m") + month = table(factor(format(catnat[["date.start"]], "%m"), levels = month)) + + pdf(file_path, width = 20, height = 10) + barplot(height = month, ylab = "n", xlab = "month", col = "royalblue3") + dev.off() +} + +# Data + +## Preparing files & version (today) + +today = as.character(Sys.Date()) +dir.create("data-common/data/gaspar/archive", showWarnings = FALSE) +archive = sprintf("data-common/data/gaspar/archive/gaspar-%s", today) + +## Download uptodate data + +utils::download.file( + url = "https://files.georisques.fr/GASPAR/gaspar.zip", + destfile = file.path(sprintf("%s.zip", archive)), + method = "wget") + +utils::unzip(sprintf("%s.zip", archive), exdir = archive) +unlink(archive, recursive = TRUE) +catnat = rio::import(file.path(archive, "catnat_gaspar.csv"))[-c(1, 10)] + +## Formating data + scope + +names(catnat) = c( + "commune", + "commune_name", + "alea_code", + "alea_jo", + "date.start", + "date.end", + "date.arrete", + "date.jo" +) +# write.csv2(unique(catnat[c("alea_code", "alea")]), "lib_risque_jo.csv", row.names = FALSE) +# catnat = catnat[ grep("nondation", catnat[["alea"]]), ] + +so_ii_scope = geau::so_ii_scope +catnat_so_ii = merge( + catnat[ catnat[["commune"]] %in% so_ii_scope, ], + read.csv2("data-common/so-ii/gaspar/catnat_alea_jo.csv") +) +write.csv2( + catnat_so_ii, + sprintf("data-common/so-ii/gaspar/catnat-%s.csv", today), + row.names = FALSE +) + +alea_scope = c("inondation", "nappe", "submersion") +catnat_so_ii = catnat_so_ii[ catnat_so_ii[["alea"]] %in% alea_scope, ] +catnat_so_ii[["commune"]] = factor( + catnat_so_ii[["commune"]], + levels = so_ii_scope +) +catnat_so_ii[["alea"]] = factor( + catnat_so_ii[["alea"]], + levels = alea_scope +) +# Treatments + +plot_chronicle(catnat, "figure/catnat-france-chronicle.pdf") +plot_month(catnat, "figure/catnat-france-month.pdf") + +plot_chronicle(catnat_so_ii, "catnat-so-ii-chronicle.pdf") +plot_month(catnat_so_ii, "catnat-so-ii-month.pdf") + +write.csv2(catnat_year, sprintf("data-common/so-ii/gaspar/catnat_year_n-%s.csv", today)) +write.csv2(catnat_month, sprintf("data-common/so-ii/gaspar/catnat_month_n-%s.csv", today)) \ No newline at end of file