-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path03_central_zone_not_applicable.R
51 lines (40 loc) · 1.44 KB
/
03_central_zone_not_applicable.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
# determine central zone
library(sf)
library(tidyverse)
library(tidytransit)
library(tmap)
cells <- st_read("./data/project_rodalies.gpkg", layer = "celles_mobilitat")
# fuse by municipality
cells_g <- cells %>%
mutate("NOMBRE_CEL" = gsub(" \\(.*", "", NOMBRE_CEL)) %>%
mutate("NOMBRE_CEL" = gsub("_", "'", NOMBRE_CEL)) %>%
group_by(NOMBRE_CEL) %>%
summarise("POB_GRUPO" = sum(POB_GRUPO))
# central zone is determined as those municipalities w/ >10
# tmb or tram stops (+ Sant Cugat)
get_stops <- function(x){
gtfs <- x %>% read_gtfs() %>% gtfs_as_sf()
stops <- gtfs$stops
stops <- select(stops, stop_id, geometry)
}
stops <- tibble(agency = c("./data/gtfs_tmb.zip", "./data/gtfs_trambaix.zip",
"./data/gtfs_trambesos.zip")) %>%
mutate("stops" = map(agency, get_stops)) %>%
unnest(cols = c(stops))
stops_per_cell <- stops %>%
st_as_sf() %>%
st_transform(st_crs(cells_g)) %>%
st_join(cells_g) %>%
as_tibble() %>%
select(-geometry) %>%
group_by(NOMBRE_CEL) %>%
summarise("stations" = n()) %>%
filter(stations > 2)
cells_g_2 <- cells_g %>%
left_join(stops_per_cell, by = "NOMBRE_CEL") %>%
mutate("NOMBRE_CEL" = case_when(!(is.na(stations)) ~ "Zona central",
TRUE ~ NOMBRE_CEL)) %>%
select(-stations) %>%
group_by(NOMBRE_CEL) %>%
summarise("POB_GRUPO" = sum(POB_GRUPO))
st_write(cells_g_2, "./data/project_rodalies.gpkg", layer = "celles_mobilitat_agrupades")