-
Notifications
You must be signed in to change notification settings - Fork 1
/
02-comunas.R
46 lines (37 loc) · 1.34 KB
/
02-comunas.R
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
45
46
source("00-paquetes.r")
finp <- list.files("cartografias-originales", recursive = T, full.names = T, pattern = "COMUNA.*shp$")
# 15 regiones ----
finp_15r <- grep("/r08/|/r16/", finp, value = T, invert = T)
comunas_15r <- map_df(
finp_15r,
function(f) {
d <- read_sf(f, as_tibble = T) %>%
clean_names() %>%
mutate(
comuna = as.character(comuna),
region = str_pad(region, 2, "left", "0"),
provincia = str_pad(provincia , 3, "left", "0"),
comuna = str_pad(comuna , 5, "left", "0")
)
}
)
# 16 regiones ----
finp_16r <- grep("/r08-15r/", finp, value = T, invert = T)
comunas_16r <- map_df(
finp_16r,
function(f) {
d <- read_sf(f, as_tibble = T) %>%
clean_names() %>%
mutate(
comuna = as.character(comuna),
region = str_pad(region, 2, "left", "0"),
provincia = str_pad(provincia , 3, "left", "0"),
comuna = str_pad(comuna , 5, "left", "0")
)
}
)
# exportar ----
# las opciones evitan el warning
# GDAL Message 1: One or several characters couldn't be converted correctly from UTF-8 to ISO-8859-1. This warning will not be emitted anymore.
write_sf(comunas_15r, "cartografias-fusionadas/comunas_15r.shp", layer_options = "ENCODING=UTF-8")
write_sf(comunas_16r, "cartografias-fusionadas/comunas_16r.shp", layer_options = "ENCODING=UTF-8")