Skip to content

Commit ec78318

Browse files
Merge pull request #68 from U-Shift/67-consider-parking-existence
#67 considering parking lanes when characterizing infrastructure
2 parents 800d551 + a6fa58e commit ec78318

3 files changed

Lines changed: 29 additions & 5 deletions

File tree

R/prioritize_lanes.R

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@
2323
#' \item \code{hour}, the hour for which the frequency applies (24 hour format).
2424
#' \item \code{frequency}, the number of services for the route that depart from the first stop for the corresponding 60 minutes period.
2525
#' \item \code{is_bus_lane}, whether the way has a bus lane.
26+
#' \item \code{n_lanes_parking}, the number of parking lanes.
27+
#' \item \code{n_lanes_circulation}, the number of circulation lanes.
2628
#' \item \code{n_lanes}, the total number of lanes.
2729
#' \item \code{n_directions}, the number of travel directions.
28-
#' \item \code{n_lanes_direction}, the number of lanes per direction.
30+
#' \item \code{n_lanes_circulation_direction}, the number of circulation lanes per direction.
31+
#' \item \code{n_lanes_direction}, the number of total lanes per direction.
2932
#' \item \code{routes}, the list of route_ids that use the way, separated by semicolon.
3033
#' \item \code{geometry}, the route shape.
3134
#' \item (if \code{keep_osm_attributes = TRUE}) all OSM way attributes.
@@ -74,7 +77,20 @@ prioritize_lanes <- function(
7477
left_join(bus_lanes |> sf::st_drop_geometry() |> select(osm_id) |> mutate(is_bus_lane = TRUE), by = c("way_osm_id" = "osm_id")) |>
7578
mutate(
7679
is_bus_lane = ifelse(is.na(is_bus_lane), FALSE, is_bus_lane),
77-
n_lanes = coalesce(
80+
n_lanes_parking = dplyr::case_when(
81+
# Any 'parking:both' or 'parking:lane:both' column present with value different from 'no'
82+
if_any(starts_with("parking:both"), ~ !is.na(.) & . != "no") ~ 2L,
83+
# Otherwise, count left and right sides separately based on specific tags
84+
TRUE ~ (
85+
as.integer(
86+
if_any(starts_with("parking:left"),~ !is.na(.) & . != "no")
87+
) +
88+
as.integer(
89+
if_any(starts_with("parking:right"), ~ !is.na(.) & . != "no")
90+
)
91+
)
92+
),
93+
n_lanes_circulation = coalesce(
7894
# Global count
7995
parse_lanes(lanes),
8096
# Directional count
@@ -85,11 +101,17 @@ prioritize_lanes <- function(
85101
2 # NA_integer_
86102
),
87103
n_directions = case_when(
88-
n_lanes == 1 ~ 1, # When only one lane, assume one direction
104+
n_lanes_circulation == 1 ~ 1, # When only one lane, assume one direction
89105
oneway %in% c("yes", "1", "-1", "true") ~ 1,
90106
oneway %in% c("no", "0", "false") ~ 2,
91107
TRUE ~ 2
92108
),
109+
n_lanes_circulation_direction = case_when(
110+
n_lanes_circulation / n_directions < 1 ~ 1,
111+
!is.na(n_lanes_circulation) & !is.na(n_directions) ~ n_lanes_circulation / n_directions,
112+
TRUE ~ NA_real_
113+
),
114+
n_lanes = n_lanes_circulation + n_lanes_parking,
93115
n_lanes_direction = case_when(
94116
n_lanes / n_directions < 1 ~ 1,
95117
!is.na(n_lanes) & !is.na(n_directions) ~ n_lanes / n_directions,
@@ -99,7 +121,7 @@ prioritize_lanes <- function(
99121

100122
if (!keep_osm_attributes) {
101123
lanes = lanes |>
102-
select(way_osm_id, hour, frequency, is_bus_lane, n_lanes, n_directions, n_lanes_direction, routes, geometry)
124+
select(way_osm_id, hour, frequency, is_bus_lane, n_lanes_parking, n_lanes_circulation, n_lanes, n_directions, n_lanes_circulation_direction, n_lanes_direction, routes, geometry)
103125
}
104126

105127
return(lanes)

R/query_osm_shapes_to_routes.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#' @import callr
4040
#'
4141
#' @export
42-
osm_shapes_to_routes <- function(gtfs, q, ways = FALSE, ways_tags = c("lanes", "psv", "bus", "way")) {
42+
osm_shapes_to_routes <- function(gtfs, q, ways = FALSE, ways_tags = c("lanes", "psv", "bus", "way", "parking")) {
4343

4444
total_steps = ifelse(ways, 3, 2)
4545

dev/test_prioritize_lanes.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ mapview::mapview(way_frequency)
4242
mapview::mapview(lanes, zcol="is_bus_lane")
4343
mapview::mapview(lanes, zcol="n_directions")
4444
mapview::mapview(lanes, zcol="n_lanes_direction")
45+
mapview::mapview(lanes, zcol="n_lanes_circulation_direction")
46+
mapview::mapview(lanes |> mutate(n_lanes_parking = as.character(n_lanes_parking)), zcol="n_lanes_parking")
4547

4648
# Prioritization
4749
# Color pallete from https://colorhunt.co/palette/f63049d027528a244b111f35

0 commit comments

Comments
 (0)