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

Merge → add ppr theme to gaspar

Merge branch '11-maintain-gaspar' into 'master'

Resolve "maintain gaspar"

Closes #11

See merge request !12
Showing with 186 additions and 17 deletions
+186 -17
Package: floodam.data
Title: An easy way to recover and prepare some useful data linked to CBA
applied to flood
Version: 0.9.22.0
Version: 0.9.23.0
Authors@R: c(
person(given = "Frédéric",
family = "Grelot",
......
......@@ -11,6 +11,8 @@ export(alert_gaspar)
export(alert_mattermost)
export(analyse_catnat)
export(analyse_intersection)
export(analyse_ppr)
export(analyse_ppr_state)
export(apply_scheme)
export(complete.pattern)
export(create.date)
......
......@@ -108,6 +108,16 @@ adapt_gaspar = function(
hazard = names(floodam.data::pprn_classification)[-(1:2)]
result = merge(result, floodam.data::pprn_classification)
result = result[apply(result[hazard], 1, any),]
result["state"] = analyse_ppr_state(
result[c(
"date_prescription",
"date_deprescription",
"date_cancellation",
"date_repeal",
"date_approval"
)]
)
}
# Saving
......
#' @title Analyse gaspar to give some elementary results
#' @title Analyse catnat theme from gaspar to give some elementary results
#'
#' @details
#'
......@@ -26,7 +26,7 @@ analyse_catnat = function(catnat) {
year = table(factor(format(event[["date_start"]], "%Y"), levels = 1982:as.integer(format(Sys.Date(), "%Y"))))
month = table(factor(format(event[["date_start"]], "%m"), levels = sprintf("%02d", 1:12)))
type = table(event$catnat)
type = table(event[["catnat"]])
return (
list(
......@@ -42,3 +42,94 @@ analyse_catnat = function(catnat) {
# plot(month, lwd = 10, col = "grey50", lend = 1) ; grid()
}
#' @title Analyse ppr theme from gaspar to give state of documents
#'
#' @details
#'
#' To be added.
#'
#' @param ppr data.frame, data to be analysed
#'
#' @return A factor of state.
#'
#' @export
#'
#' @encoding UTF-8
#' @author Frédéric Grelot
analyse_ppr_state = function(ppr) {
classification = data.frame(
in_use =
!is.na(ppr[["date_approval"]]) &
is.na(ppr[["date_deprescription"]]) &
is.na(ppr[["date_cancellation"]]) &
is.na(ppr[["date_repeal"]]),
in_progress =
!is.na(ppr[["date_prescription"]]) &
is.na(ppr[["date_deprescription"]]) &
is.na(ppr[["date_cancellation"]]) &
is.na(ppr[["date_repeal"]]) &
is.na(ppr[["date_approval"]]),
cancelled =
!is.na(ppr[["date_deprescription"]]) |
!is.na(ppr[["date_cancellation"]]) |
!is.na(ppr[["date_repeal"]]),
unknown =
is.na(ppr[["date_prescription"]]) &
is.na(ppr[["date_deprescription"]]) &
is.na(ppr[["date_cancellation"]]) &
is.na(ppr[["date_repeal"]]) &
is.na(ppr[["date_approval"]])
)
if (any(unique(apply(classification, 1, sum)) != 1)) {
warning("Classification of pprn has duplicated types.")
}
result = rep(NA_character_, nrow(classification))
result[classification[["unknown"]]] = "unknown"
result[classification[["cancelled"]]] = "cancelled"
result[classification[["in_progress"]]] = "progress"
result[classification[["in_use"]]] = "use"
return(factor(result, levels = c("use", "progress", "cancelled", "unknown")))
}
#' @title Analyse ppr theme from gaspar to give some elementary results
#'
#' @details
#'
#' The following treatments are performed:
#' - In the element detail, a matrix gives for each commune (rows), the count
#' of all procedures depening on their state (columns). The column <NA> is
#' alwas given even if, normally, it should stay at 0 for each commune.
#' - In the element summary, from the information in element detail, a state at
#' the commune is given. It is performed this way: if one document is in state
#' "use", the commune is in state "use", otherwise if one document is in state
#' "progress", the commune is in state "progress", otherwise if one document
#' is in state "cancelled", the commune is in state "cancelled", otherwise if
#' one document is in state "unknown", the commune is in state "unknown",
#' otherwise the commune's state is NA.
#'
#' @param ppr data.frame, data to be analysed
#'
#' @return A list of analysis (detail, summary)
#'
#' @export
#'
#' @encoding UTF-8
#' @author Frédéric Grelot
analyse_ppr = function(ppr) {
result = stats::aggregate(ppr["state"], ppr["commune"], table, useNA = "always")
detail = result[["state"]]
rownames(detail) = as.character(result[["commune"]])
summary = structure(rep(NA_character_, nrow(detail)), names = rownames(detail))
summary[detail[, "unknown"] > 0] = "unknown"
summary[detail[, "cancelled"] > 0] = "cancelled"
summary[detail[, "progress"] > 0] = "progress"
summary[detail[, "use"] > 0] = "use"
list(
detail = detail,
summary = factor(summary, c("use", "progress", "cancelled", "unknown"))
)
}
\ No newline at end of file
No preview for this file type
floodam.data Version: 0.9.21.0
floodam.data Version: 0.9.23.0
0 errors ✔ | 0 warnings ✔ | 0 notes ✔
**Note de version**
* ajout de analyse_intersection, analyse_eaip
* ajout du theme pprn dans adapt_gaspar
* ajout de analyse_ppr, analyse_ppr_state
**Détails**
- nouvelle fonction
- analyse_intersection (provides analysis from st_intersects and st_intersection)
- analyse_eaip (wrapper of analyse_intersection for eaip DB)
- analyse_ppr (gives an analysis of ppr at commune level)
- analyse_ppr_state (analyse some dates in ppr procedure to decide their state)
# git tag -a v0.9.21.0 -F dev/tag-message
# git tag -a v0.9.23.0 -F dev/tag-message
# git push --tags
name;name_origin;order;keep;type;label_fr;source;length_source;type_source;comment
id;cod_nat_pprn;1;TRUE;character;ID du PPRN;georisques;;text;
pprn_label_fr;lib_pprn;2;TRUE;factor;libellé du PPRN;georisques;;text;
catchment_label_fr;lib_bassin_risques;3;FALSE;factor;libellé du bassin de risque;georisques;;text;
catchment_label_fr;lib_bassin_risques;3;TRUE;factor;libellé du bassin de risque;georisques;;text;
hazard;num_risque;4;TRUE;factor;code du risque;georisques;;integer;
hazard_label_fr;lib_risque;5;TRUE;factor;libellé du risque;georisques;;text;
pprn_revised;list_codenat_ppr_revise;6;TRUE;list;code du PPRN révisé;georisques;;text;
......@@ -14,8 +14,8 @@ type_label_fr;cod_ppr;10;TRUE;factor;code du PPRN;georisques;;text;
;dat_montage_deb;13;FALSE;date;date de début de réflexion de l'élaboration;georisques;;text;
;dat_montage_fin;14;FALSE;date;date de fin de réflexion de l'élaboration;georisques;;text;
date_prescription;dat_prescription;15;TRUE;date;date de l'arrêté préfectoral portant prescription;georisques;;text;
;dat_appli_ant;16;FALSE;date;date de l'arrêté préfectoral portant application anticipée;georisques;;text;
;dat_deprescription;17;FALSE;date;date de l'arrêté préfectoral portant déprescription;georisques;;text;
date_anticipated;dat_appli_ant;16;TRUE;date;date de l'arrêté préfectoral portant application anticipée;georisques;;text;
date_deprescription;dat_deprescription;17;TRUE;date;date de l'arrêté préfectoral portant déprescription;georisques;;text;
;dat_etu_hydro_deb;18;FALSE;date;date de début de réalisation des études hydrologiques et hydrauliques;georisques;;text;
;dat_etu_hydro_fin;19;FALSE;date;date de fin de réalisation des études hydrologiques et hydrauliques;georisques;;text;
;dat_etu_alea_deb;20;FALSE;date;date de début de l'élaboration des cartes d’aléas;georisques;;text;
......@@ -36,9 +36,9 @@ date_mise_a_enquete_deb;dat_mise_a_enquete_deb;34;TRUE;date;date d’ouverture d
date_mise_a_enquete_fin;dat_mise_a_enquete_fin;35;TRUE;date;date de fermeture de l’enquête publique;georisques;;text;
date_approval;dat_approbation;36;TRUE;date;date de l'arrêté préfectoral portant approbation;georisques;;text;
date_amendment;dat_modification;37;TRUE;date;date de l'arrêté préfectoral prescrivant une modification;georisques;;text;
date_cancellation;dat_annulation;38;FALSE;date;date de la décision d'annulation du Tribunal Administratif;georisques;;text;
date_plu;dat_annexion_plu;39;FALSE;date;date de l'arrêté municipal annexant le PPR au PLU;georisques;;text;
date_extension;dat_proroga;40;FALSE;date;date de l'arrêté préfectoral prorogeant de 18 mois la date de prescription;georisques;;text;
date_repeal;dat_abrog;41;FALSE;date;date de l'arrêté préfectoral portant abrogation;georisques;;text;
date_cancellation;dat_annulation;38;TRUE;date;date de la décision d'annulation du Tribunal Administratif;georisques;;text;
date_plu;dat_annexion_plu;39;TRUE;date;date de l'arrêté municipal annexant le PPR au PLU;georisques;;text;
date_extension;dat_proroga;40;TRUE;date;date de l'arrêté préfectoral prorogeant de 18 mois la date de prescription;georisques;;text;
date_repeal;dat_abrog;41;TRUE;date;date de l'arrêté préfectoral portant abrogation;georisques;;text;
revision;etat_revision;42;TRUE;logical;Indique si le PPR a été révisé ou non;georisques;;text;
date_update;dat_maj;43;TRUE;date;date de mise à jour de la fiche gaspar;georisques;;text;
......@@ -3,7 +3,7 @@
\encoding{UTF-8}
\name{analyse_catnat}
\alias{analyse_catnat}
\title{Analyse gaspar to give some elementary results}
\title{Analyse catnat theme from gaspar to give some elementary results}
\usage{
analyse_catnat(catnat)
}
......@@ -14,7 +14,7 @@ analyse_catnat(catnat)
A list of analysis (catnat, event, year, month, and type)
}
\description{
Analyse gaspar to give some elementary results
Analyse catnat theme from gaspar to give some elementary results
}
\details{
The following treatments are performed:
......
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/analyse_gaspar.R
\encoding{UTF-8}
\name{analyse_ppr}
\alias{analyse_ppr}
\title{Analyse ppr theme from gaspar to give some elementary results}
\usage{
analyse_ppr(ppr)
}
\arguments{
\item{ppr}{data.frame, data to be analysed}
}
\value{
A list of analysis (detail, summary)
}
\description{
Analyse ppr theme from gaspar to give some elementary results
}
\details{
The following treatments are performed:
- In the element detail, a matrix gives for each commune (rows), the count
of all procedures depening on their state (columns). The column <NA> is
alwas given even if, normally, it should stay at 0 for each commune.
- In the element summary, from the information in element detail, a state at
the commune is given. It is performed this way: if one document is in state
"use", the commune is in state "use", otherwise if one document is in state
"progress", the commune is in state "progress", otherwise if one document
is in state "cancelled", the commune is in state "cancelled", otherwise if
one document is in state "unknown", the commune is in state "unknown",
otherwise the commune's state is NA.
}
\author{
Frédéric Grelot
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/analyse_gaspar.R
\encoding{UTF-8}
\name{analyse_ppr_state}
\alias{analyse_ppr_state}
\title{Analyse ppr theme from gaspar to give state of documents}
\usage{
analyse_ppr_state(ppr)
}
\arguments{
\item{ppr}{data.frame, data to be analysed}
}
\value{
A factor of state.
}
\description{
Analyse ppr theme from gaspar to give state of documents
}
\details{
To be added.
}
\author{
Frédéric Grelot
}
......@@ -11,3 +11,10 @@ adapted = "data-local/floodam-data/adapted/gaspar"
floodam.data::download_gaspar(original)
floodam.data::adapt_gaspar(original, adapted, scope = list("so_ii" = so.ii::so_ii_scope))
floodam.data::alert_gaspar(adapted, scope = "so_ii")
ppri = adapt_gaspar(
original, adapted,
theme = "pprn",
scope = list("so_ii" = so.ii::so_ii_scope),
retrieve = TRUE, keep = TRUE)
ppri_commune = analyse_ppr(ppri)
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment