Source

Target

Commits (10)
Showing with 344 additions and 112 deletions
+344 -112
Package: geau
Title: Utilities very useful to share within geau-inondation team
Version: 1.0.3.0
Version: 1.0.5.0
Authors@R:
c(
person(given = "Frédéric",
......
......@@ -3,31 +3,39 @@
#' A dataset containing the INSEE code of all local collectivities
#' (communes) included in so-ii
#'
#' @format a vector of 69 INSEE code
#' @format a vector of 78 INSEE code
"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
#' included in so-ii.
#' 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.
#' 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{
#' \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}
#' \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/}
"so_ii_commune"
"so_ii_collectivity"
#' Spatial perimeter of so-ii
#'
......@@ -100,9 +108,12 @@
#' @format sf data.frame 125 rows, 4 variables
#' \describe{
#' \item{id}{id, from BD TOPAGE (corresponding to CdOh)}
#' \item{name}{character, name of the river or part of the river in BD
#' TOPAGE}
#' \item{degre}{character, level of detail to plot the hydrographic network}
#' \item{name}{character, name of the hydrographic elements in the BD TOPAGE}
#' \item{degre}{factor, level of importance of the hydrographic element
#' used to plot the hydrographic network with different levels of
#' detail ("1", "2", "3").}
#' \item{type}{factor, type of hydrographic element ("canal", "river",
#' "waterbody")}
#' }
#'
#' @source \url{http://bdtopage.eaufrance.fr/page/objectifs}
......
#' @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".
#' @details
#' \subsection{detail specification}{
#' For the specification of detail, it depends on the theme chosen.
#' \itemize{
#' \item{\strong{catnat}: detail must be chosen in "inondation",
#' "submersion", or "nappe". If missing all type will be chosen and
#' aggregated before plotting.}
#' \item{\strong{collectivity}: detail must be chosen in "none", "syble",
#' "symbo", "epci" or "syndicate". If missing, "none" will be chosen,
#' and only the boundaries of collectivities are plotted.}
#' \item{\strong{hydro}: detail must be chosen in "none", "1", "2", "3" for
#' levels of detail or "canal", "river", "waterbody" for types of
#' hydrographic elements. If missing, "none" will be chosen, and
#' everything is plotted.}
#' }
#' }
#' \subsection{year specification}{
#' For the specification of year, it depends on the theme chosen.
#' \itemize{
#' \item{\strong{catnat}: year corresponds to the year of data. If missing,
#' nothing is plotted.}
#' \item{\strong{population}: year corresponds to the year of data. If
#' missing, last available year is plotted.}
#' }
#' }
#'
#' @param dataset sf objectf, data to be plotted
#' @param dataset_legend list of parameters to be passed to legend
......@@ -12,7 +33,7 @@
#' @param path character, the name of the file to save the plot
#' @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 detail character, detail for theme, depends on theme. See details.
#' @param ... some parameters that will be used by plot (from sf)
#'
#' @return Nothing useful.
......@@ -21,6 +42,7 @@
#'
#' @encoding UTF-8
#' @author Frédéric Grelot
#' @author David Nortes Martinez
#'
#' @examples
#'
......@@ -31,7 +53,7 @@
map_so_ii = function(
dataset,
dataset_legend = NULL,
theme = c("none", "clc", "catnat", "hydro", "population"),
theme = c("none", "collectivity", "clc", "catnat", "hydro", "population"),
bar = TRUE,
path = NULL,
legend_theme = FALSE,
......@@ -55,6 +77,63 @@ map_so_ii = function(
graphics::par(mai = c(.65, .60, .50, .15))
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"]]
plot(geometry, border = border, col = color, add = TRUE)
if (detail %in% c("syble", "syndicate")) {
color_legend = scales::alpha("orange", .3)
color = ifelse(
geau::so_ii_collectivity[["syble"]],
color_legend,
NA
)
plot(geometry, border = border, col = color, add = TRUE)
theme_legend[["legend"]] = c(theme_legend[["legend"]], "SYBLE")
theme_legend[["fill"]] = c(theme_legend[["fill"]], color_legend)
}
if (detail %in% c("symbo", "syndicate")) {
color_legend = scales::alpha("green", .3)
color = ifelse(
geau::so_ii_collectivity[["symbo"]],
color_legend,
NA
)
plot(geometry, border = border, col = color, add = TRUE)
theme_legend[["legend"]] = c(theme_legend[["legend"]], "SYMBO")
theme_legend[["fill"]] = c(theme_legend[["fill"]], color_legend)
}
if (detail == "epci") {
epci = as.factor(geau::so_ii_collectivity[["epci_name"]])
color_legend = grDevices::hcl.colors(nlevels(epci), "Lisbon", alpha = .3)
color = color_legend[epci]
plot(geometry, border = border, col = color, add = TRUE)
theme_legend[["legend"]] = levels(epci)
theme_legend[["fill"]] = color_legend
}
}
if ("clc" %in% theme) {
plot(
geau::so_ii_clc[["geometry"]],
......@@ -89,7 +168,7 @@ map_so_ii = function(
)
border = "grey80"
plot(
geau::so_ii_commune[["geometry"]],
geau::so_ii_collectivity[["geometry"]],
border = border,
col = color[ , year],
add = TRUE
......@@ -155,7 +234,7 @@ map_so_ii = function(
}
plot(
geau::so_ii_commune[["geometry"]],
geau::so_ii_collectivity[["geometry"]],
border = border,
col = color,
add = TRUE
......@@ -164,36 +243,41 @@ map_so_ii = function(
if ("hydro" %in% theme) {
if (missing(detail)) {
detail = "0"
detail = "none"
}
detail = match.arg(
as.character(detail),
choices = c("0", "1", "2", "3", "canal")
choices = c(
"none",
levels(geau::so_ii_hydro[["degre"]]),
levels(geau::so_ii_hydro[["type"]])
)
)
if (detail == "canal") {
selection = geau::so_ii_hydro[["degre"]] == detail
geometry = geau::so_ii_hydro[["geometry"]][selection]
color = scales::alpha("red", .3)
lwd = 1
} else {
selection = geau::so_ii_hydro[["degre"]] <= detail
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)
color = scales::alpha("blue", .3)
bg = scales::alpha("blue", .3)
border = NA
selection = seq(nrow(geau::so_ii_hydro))
theme_legend = list(
title = sprintf("R\u00e9seau hydrographique"),
legend = ifelse(detail == "canal", "canal", "cours d'eau"),
legend = "\u00e9l\u00e9ment du r\u00e9seau",
x = "topright",
cex = .8,
bg = "white",
inset = 0.01,
col = color,
lwd = 2
lwd = 1
)
if (detail %in% levels(geau::so_ii_hydro[["type"]])) {
selection = as.character(geau::so_ii_hydro[["type"]]) == detail
theme_legend[["legend"]] = detail
}
if (detail %in% levels(geau::so_ii_hydro[["degre"]])) {
selection = as.character(geau::so_ii_hydro[["degre"]]) <= detail
}
geometry = geau::so_ii_hydro[["geometry"]][selection]
lwd = 4 - as.numeric(geau::so_ii_hydro[["degre"]][selection])
plot(geometry, col = color, lwd = lwd, border = border, add = TRUE)
}
if (!missing(dataset)) plot(dataset[["geometry"]], 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)
# code to prepare `so_ii_hydro` dataset goes here
selection = c("CdOH", "TopoOH")
file_dir = current_version(
file_dir = geau::current_version(
"data-common/so-ii/topage",
pattern = "^[0-9-]+$"
)
so_ii_hydro = sf::st_read(file.path(file_dir, "cours-eau-so-ii.shp"))
so_ii_hydro = sf::st_transform(
so_ii_hydro[selection],
river = sf::st_read(file.path(file_dir, "cours_eau.shp"))
river = sf::st_transform(
river[selection],
sf::st_crs(geau::so_ii_limit)
)
names(so_ii_hydro) = c("id", "name", "geometry")
names(river) = c("id", "name", "geometry")
classification = read.csv2(
current_version("data-common/so-ii/topage", pattern = "courseau"),
geau::current_version("data-common/so-ii/topage", pattern = "cours_eau"),
colClasses = "character",
row.names = 1
)
river = merge(river, classification)
waterbody = sf::st_read(file.path(file_dir, "plan_eau.shp"))
waterbody[["name"]] = gsub("C[?]ur", "Cœur", waterbody[["name"]])
classification = read.csv2(
geau::current_version("data-common/so-ii/topage", pattern = "plan_eau"),
colClasses = "character"
)[c("id", "name", "degre")]
)
waterbody = merge(waterbody, classification)
so_ii_hydro = rbind(river, waterbody)
so_ii_hydro = merge(so_ii_hydro, classification)
so_ii_hydro[["degre"]] = factor(so_ii_hydro[["degre"]])
so_ii_hydro[["type"]] = factor(so_ii_hydro[["type"]])
Encoding(waterbody[["name"]]) = "UTF-8"
# updating datasets
# actual = setwd(file.path(system.file(package = "geau"), ".."))
actual = setwd("geau")
usethis::use_data(so_ii_hydro, internal = FALSE, overwrite = TRUE)
setwd(actual)
......@@ -6,19 +6,6 @@ so_ii_scope = read.csv2(
)[["code"]]
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
so_ii_clc = readRDS("data-common/data/so-ii/so-ii_clc.rds")
......@@ -63,8 +50,6 @@ so_ii_clc[["color"]] = as.character(
# actual = setwd(file.path(system.file(package = "geau"), ".."))
actual = setwd("geau")
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(clc_color, internal = FALSE, overwrite = TRUE)
setwd(actual)
File added
File deleted
No preview for this file type
......@@ -8,7 +8,7 @@
map_so_ii(
dataset,
dataset_legend = NULL,
theme = c("none", "clc", "catnat", "hydro"),
theme = c("none", "collectivity", "clc", "catnat", "hydro", "population"),
bar = TRUE,
path = NULL,
legend_theme = FALSE,
......@@ -32,7 +32,7 @@ map_so_ii(
\item{year}{character, the year chosen for some themes (catnat, population)}
\item{detail}{character, detail for theme, depends on theme}
\item{detail}{character, detail for theme, depends on theme. See details.}
\item{...}{some parameters that will be used by plot (from sf)}
}
......@@ -43,9 +43,30 @@ Nothing useful.
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".
\subsection{detail specification}{
For the specification of detail, it depends on the theme chosen.
\itemize{
\item{\strong{catnat}: detail must be chosen in "inondation",
"submersion", or "nappe". If missing all type will be chosen and
aggregated before plotting.}
\item{\strong{collectivity}: detail must be chosen in "none", "syble",
"symbo", "epci" or "syndicate". If missing, "none" will be chosen,
and only the boundaries of collectivities are plotted.}
\item{\strong{hydro}: detail must be chosen in "none", "1", "2", "3" for
levels of detail or "canal", "river", "waterbody" for types of
hydrographic elements. If missing, "none" will be chosen, and
everything is plotted.}
}
}
\subsection{year specification}{
For the specification of year, it depends on the theme chosen.
\itemize{
\item{\strong{catnat}: year corresponds to the year of data. If missing,
nothing is plotted.}
\item{\strong{population}: year corresponds to the year of data. If
missing, last available year is plotted.}
}
}
}
\examples{
......@@ -55,4 +76,6 @@ For theme "hydro" detail must be chosen in "0", "1", "2", "3" or "canal".
}
\author{
Frédéric Grelot
David Nortes Martinez
}
% 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}
......@@ -8,9 +8,12 @@
sf data.frame 125 rows, 4 variables
\describe{
\item{id}{id, from BD TOPAGE (corresponding to CdOh)}
\item{name}{character, name of the river or part of the river in BD
TOPAGE}
\item{degre}{character, level of detail to plot the hydrographic network}
\item{name}{character, name of the hydrographic elements in the BD TOPAGE}
\item{degre}{factor, level of importance of the hydrographic element
used to plot the hydrographic network with different levels of
detail ("1", "2", "3").}
\item{type}{factor, type of hydrographic element ("canal", "river",
"waterbody")}
}
}
\source{
......
......@@ -5,7 +5,7 @@
\alias{so_ii_scope}
\title{Local collectivities included in so-ii}
\format{
a vector of 69 INSEE code
a vector of 78 INSEE code
}
\usage{
so_ii_scope
......
library(sf)
map_so_ii()
map_so_ii(theme = "collectivity")
map_so_ii(theme = "collectivity", detail = "syble")
map_so_ii(theme = "collectivity", detail = "symbo")
map_so_ii(theme = "clc")
map_so_ii(theme = "population")
map_so_ii(theme = "catnat", year = 2019)
map_so_ii(theme = "hydro", detail = 3)
# Can only work if data-common is a symbolic link
# Data to be plotted
......
# Functions
# Data
input_dir = geau::current_version("data-common/data/IGN/ADMIN-EXPRESS/version")
commune = sf::st_read(file.path(input_dir, "COMMUNE.shp"))
commune = sf::st_drop_geometry(commune)
commune = commune[c("NOM", "NOM_M", "INSEE_COM", "INSEE_DEP", "INSEE_REG", "SIREN_EPCI")]
names(commune) = c("commune_name", "commune_nam_cap", "commune", "departement", "region", "epci")
rownames(commune) = commune[["commune"]]
commune = commune[geau::so_ii_scope, ]
commune_so_ii = read.csv2(geau::current_version("data-common/so-ii/commune"))
commune_so_ii = merge(commune_so_ii[c("commune", "syble", "symbo")], commune)
epci = sf::st_read(file.path(input_dir, "EPCI.shp"))
epci = sf::st_drop_geometry(epci)
names(epci) = c("id", "epci", "epci_name", "epci_nature")
rownames(epci) = epci[["epci"]]
epci = epci[unique(commune[["epci"]]), c("epci", "epci_name", "epci_nature")]
# Save
today = Sys.Date()
write.csv2(
commune_so_ii,
sprintf("data-common/so-ii/commune/commune-%s.csv", today),
row.names = FALSE
)
write.csv2(
epci,
sprintf("data-common/so-ii/epci/epci-%s.csv", today),
row.names = FALSE
)
\ No newline at end of file
# Functions
# Data
library(geau)
library(sf)
waterbody = sf::st_read(geau::current_version("data-common/data/topage/plan_eau", "shp"))
waterbody = sf::st_transform(waterbody, crs = st_crs(geau::so_ii_limit))
waterbody = waterbody[
lengths(sf::st_intersects(waterbody, geau::so_ii_limit)) > 0,
c("CdOH", "TopoOH")
]
names(waterbody) = c("id", "name", "geometry")
waterbody = sf::st_intersection(waterbody, geau::so_ii_limit)
# Save
sf::st_write(waterbody, "data-common/so-ii/topage/2021-09/plan_eau.shp", append = FALSE)