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

geau version 1.0.4.0

- so_ii_collectivity ajouté
	- remplace so_ii_commune
	- ajoute info sur syndicats, epci
- map_so_ii intègre theme collectivity

Refs #5
Showing with 176 additions and 72 deletions
+176 -72
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.4.0
Authors@R: Authors@R:
c( c(
person(given = "Frédéric", person(given = "Frédéric",
......
...@@ -3,31 +3,39 @@ ...@@ -3,31 +3,39 @@
#' A dataset containing the INSEE code of all local collectivities #' A dataset containing the INSEE code of all local collectivities
#' (communes) included in so-ii #' (communes) included in so-ii
#' #'
#' @format a vector of 69 INSEE code #' @format a vector of 78 INSEE code
"so_ii_scope" "so_ii_scope"
#' List of all collectivities included in so-ii #' Spatial definition of collectivities included in so-ii
#' #'
#' A dataset containing the INSEE code of all local collectivities #' A dataset containing the spatial definition of all collectivities
#' included in so-ii. #' included in so-ii and some administrative informations.
#' #'
#' @details
#' Basically this dataset is obtained as a selection from the layer #' Basically this dataset is obtained as a selection from the layer
#' COMMUNE in ADMIN EXPRESS, more a renaming of variables. #' 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 sf data.frame 69 rows, 7 variables #' @format sf data.frame 78 rows, 11 variables
#' \describe{ #' \describe{
#' \item{id}{id, from IGN ADMIN EXPRESS} #' \item{commune_name}{character, INSEE code of the collectivity}
#' \item{commune}{character, official name of the commune} #' \item{syble}{logical, membership in SYBLE}
#' \item{commune_majuscule}{character, official capitalized name of the #' \item{symbo}{logical, membership in SYMBO}
#' commune} #' \item{commune_name}{character, official name of the collectivity}
#' \item{code}{character, INSEE code of the commune} #' \item{commune_name_cap}{character, official capitalized name of the
#' \item{statut}{character, statut of the commune} #' collectivity}
#' \item{pop_yyy}{integer, official population of year yyyy in the commune} #' \item{departement}{character, INSEE code of the departement of the
#' \item{epci}{character, INSEE ID of the EPCI of the commune} #' 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.data.gouv.fr/fr/datasets/admin-express/} #' @source \url{https://www.data.gouv.fr/fr/datasets/admin-express/}
"so_ii_commune" "so_ii_collectivity"
#' Spatial perimeter of so-ii #' Spatial perimeter of so-ii
#' #'
......
#' @title Plot a thematic map of so-ii #' @title Plot a thematic map of so-ii
#' #'
#' @details #' @details
#' For theme "collectivity" detail must be chosen in c("none", "syble", "symbo",
#' "epci", "syndicate").
#' For theme "catnat", detail must be chosen in c("inondation", "submersion", #' For theme "catnat", detail must be chosen in c("inondation", "submersion",
#' "nappe"). #' "nappe").
#' For theme "hydro" detail must be chosen in "0", "1", "2", "3" or "canal". #' For theme "hydro" detail must be chosen in "0", "1", "2", "3" or "canal".
#' #'
#' @param dataset sf objectf, data to be plotted #' @param dataset sf objectf, data to be plotted
...@@ -31,7 +33,7 @@ ...@@ -31,7 +33,7 @@
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", "clc", "catnat", "hydro", "population"),
bar = TRUE, bar = TRUE,
path = NULL, path = NULL,
legend_theme = FALSE, legend_theme = FALSE,
...@@ -55,6 +57,62 @@ map_so_ii = function( ...@@ -55,6 +57,62 @@ map_so_ii = function(
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)
if ("collectivity" %in% theme) {
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"]]
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 ("clc" %in% theme) { if ("clc" %in% theme) {
plot( plot(
geau::so_ii_clc[["geometry"]], geau::so_ii_clc[["geometry"]],
...@@ -89,7 +147,7 @@ map_so_ii = function( ...@@ -89,7 +147,7 @@ map_so_ii = function(
) )
border = "grey80" 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
...@@ -155,7 +213,7 @@ map_so_ii = function( ...@@ -155,7 +213,7 @@ map_so_ii = function(
} }
plot( plot(
geau::so_ii_commune[["geometry"]], geau::so_ii_collectivity[["geometry"]],
border = border, border = border,
col = color, col = color,
add = TRUE add = TRUE
......
# 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)
...@@ -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 deleted
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
map_so_ii( map_so_ii(
dataset, dataset,
dataset_legend = NULL, dataset_legend = NULL,
theme = c("none", "clc", "catnat", "hydro"), theme = c("none", "collectivity", "clc", "catnat", "hydro", "population"),
bar = TRUE, bar = TRUE,
path = NULL, path = NULL,
legend_theme = FALSE, legend_theme = FALSE,
...@@ -43,6 +43,8 @@ Nothing useful. ...@@ -43,6 +43,8 @@ Nothing useful.
Plot a thematic map of so-ii Plot a thematic map of so-ii
} }
\details{ \details{
For theme "collectivity" detail must be chosen in c("none", "syble", "symbo",
"epci", "syndicate").
For theme "catnat", detail must be chosen in c("inondation", "submersion", For theme "catnat", detail must be chosen in c("inondation", "submersion",
"nappe"). "nappe").
For theme "hydro" detail must be chosen in "0", "1", "2", "3" or "canal". For theme "hydro" detail must be chosen in "0", "1", "2", "3" or "canal".
......
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/data.r
\docType{data}
\name{so_ii_collectivity}
\alias{so_ii_collectivity}
\title{Spatial definition of collectivities included in so-ii}
\format{
sf data.frame 78 rows, 11 variables
\describe{
\item{commune_name}{character, INSEE code of the collectivity}
\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.data.gouv.fr/fr/datasets/admin-express/}
}
\usage{
so_ii_collectivity
}
\description{
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.
}
\keyword{datasets}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/data.r
\docType{data}
\name{so_ii_commune}
\alias{so_ii_commune}
\title{List of all collectivities included in so-ii}
\format{
sf data.frame 69 rows, 7 variables
\describe{
\item{id}{id, from IGN ADMIN EXPRESS}
\item{commune}{character, official name of the commune}
\item{commune_majuscule}{character, official capitalized name of the
commune}
\item{code}{character, INSEE code of the commune}
\item{statut}{character, statut of the commune}
\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/}
}
\usage{
so_ii_commune
}
\description{
A dataset containing the INSEE code of all local collectivities
included in so-ii.
}
\details{
Basically this dataset is obtained as a selection from the layer
COMMUNE in ADMIN EXPRESS, more a renaming of variables.
}
\keyword{datasets}
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
\alias{so_ii_scope} \alias{so_ii_scope}
\title{Local collectivities included in so-ii} \title{Local collectivities included in so-ii}
\format{ \format{
a vector of 69 INSEE code a vector of 78 INSEE code
} }
\usage{ \usage{
so_ii_scope so_ii_scope
......
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