From 898879c0171ebba0354caa919efed9e8c0a911c2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Grelot?= <frederic.grelot@irstea.fr>
Date: Fri, 21 Jan 2022 17:12:48 +0100
Subject: [PATCH] =?UTF-8?q?script/admin=5Fexpress.R=20=09-=20cr=C3=A9ation?=
 =?UTF-8?q?=20des=20donn=C3=A9es=20epci=20et=20commune=20dans=20data-commo?=
 =?UTF-8?q?n/so-ii?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Refs #5
---
 script/admin_express.R | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
 create mode 100644 script/admin_express.R

diff --git a/script/admin_express.R b/script/admin_express.R
new file mode 100644
index 0000000..626120f
--- /dev/null
+++ b/script/admin_express.R
@@ -0,0 +1,33 @@
+# 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
-- 
GitLab