so_ii_collectivity.R 1.46 KB
Newer Older
Grelot Frederic's avatar
Grelot Frederic committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# 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)