-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
administrative-maps.R
75 lines (73 loc) · 2.67 KB
/
administrative-maps.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#' Mapa de Chile a nivel provincial
#' @description Este mapa es calculado a partir
#' del mapa comunal para no recargar el volumen de datos del paquete.
#' @param mapa mapa a agregar, por defecto es todo el mapa nacional
#' @import sf
#' @importFrom rmapshaper ms_dissolve
#' @importFrom sf st_as_sf
#' @importFrom dplyr as_tibble inner_join select distinct
#' @importFrom magrittr %>%
#' @importFrom rlang sym
#' @return Un objeto de clase sf y data.frame.
#' @examples
#' generar_provincias()
#' @export
generar_provincias <- function(mapa = chilemapas::mapa_comunas) {
ms_dissolve(st_as_sf(mapa), field = "codigo_provincia") %>%
as_tibble() %>%
inner_join(
chilemapas::codigos_territoriales %>%
select(!!sym("codigo_provincia"), !!sym("codigo_region")) %>%
distinct(),
by = "codigo_provincia"
) %>%
select(!!sym("codigo_provincia"), !!sym("codigo_region"), !!sym("geometry"))
}
#' Mapa de Chile a nivel regional
#' @description Este mapa es calculado a partir
#' del mapa comunal para no recargar el volumen de datos del paquete.
#' @param mapa mapa a agregar, por defecto es todo el mapa nacional
#' @importFrom rmapshaper ms_dissolve
#' @importFrom sf st_as_sf
#' @return Un objeto de clase sf y data.frame.
#' @examples
#' generar_regiones()
#' @export
generar_regiones <- function(mapa = chilemapas::mapa_comunas) {
ms_dissolve(st_as_sf(mapa), field = "codigo_region")
}
#' Mapa de Chile a nivel de servicios de salud
#' @description Este mapa es calculado a partir
#' del mapa comunal para no recargar el volumen de datos del paquete.
#' @param mapa mapa a agregar, por defecto es todo el mapa nacional
#' @importFrom dplyr as_tibble inner_join
#' @importFrom rmapshaper ms_dissolve
#' @importFrom sf st_as_sf
#' @return Un objeto de clase sf y data.frame.
#' @examples
#' generar_servicios_salud()
#' @export
generar_servicios_salud <- function(mapa = chilemapas::mapa_comunas) {
mapa %>%
merge(
chilemapas::divisiones_salud %>%
select(!!sym("codigo_servicio_salud"), !!sym("codigo_comuna")),
by = "codigo_comuna"
) %>%
st_as_sf() %>%
ms_dissolve(field = "codigo_servicio_salud") %>%
as_tibble() %>%
inner_join(
chilemapas::divisiones_salud %>%
select(!!sym("codigo_servicio_salud"), !!sym("codigo_comuna")) %>%
distinct() %>%
inner_join(
chilemapas::codigos_territoriales %>%
select(!!sym("codigo_comuna"), !!sym("codigo_region"))
) %>%
select(!!sym("codigo_servicio_salud"), !!sym("codigo_region")) %>%
distinct(),
by = "codigo_servicio_salud"
) %>%
select(!!sym("codigo_servicio_salud"), !!sym("codigo_region"), !!sym("geometry"))
}