diff --git a/functions/combineRedundantEdges.R b/functions/combineRedundantEdges.R index f6abb36..63b37b2 100644 --- a/functions/combineRedundantEdges.R +++ b/functions/combineRedundantEdges.R @@ -113,12 +113,16 @@ combineRedundantEdges <- function(nodes_current,edges_current,outputCrs){ # Adding the undirected and directed edges, and setting any edges with zero - # lanes to one. + # lanes to one (if one-way) or two (if two) edges_all <- bind_rows( edges_undirected_merged, edges_directed_opposite_merged%>%filter(is_oneway==1) ) %>% - mutate(permlanes=ifelse(permlanes==0,1,permlanes)) + mutate(permlanes = case_when( + permlanes == 0 & is_oneway == 1 ~ 1, + permlanes == 0 & is_oneway == 0 ~ 2, + TRUE ~ permlanes + )) # Finding the geometry edges_geom <- edges_current %>% diff --git a/functions/combineUndirectedAndDirectedEdges.R b/functions/combineUndirectedAndDirectedEdges.R index 17748e9..2234f8c 100644 --- a/functions/combineUndirectedAndDirectedEdges.R +++ b/functions/combineUndirectedAndDirectedEdges.R @@ -64,10 +64,14 @@ combineUndirectedAndDirectedEdges <- function(nodes_current,edges_current,output # directed edges need the from id and to id in the correct order mutate(from_id=ifelse(from_id_directed==-1,from_id,from_id_directed)) %>% mutate(to_id=ifelse(to_id_directed==-1,to_id,to_id_directed)) %>% - # Setting any edges with zero lanes to one. - mutate(permlanes=ifelse(permlanes==0,1,permlanes)) %>% # Only road edges can be one way mutate(is_oneway=ifelse(is_car==0,0,is_oneway)) %>% + # Setting any edges with zero lanes to one (if one-way) or two (if two-way) + mutate(permlanes = case_when( + permlanes == 0 & is_oneway == 1 ~ 1, + permlanes == 0 & is_oneway == 0 ~ 2, + TRUE ~ permlanes + )) %>% dplyr::select(-current_group,-from_id_directed,-to_id_directed) # geometry of shortest edges diff --git a/functions/makeEdgesOneway.R b/functions/makeEdgesOneway.R index d8e6897..4f7fc92 100644 --- a/functions/makeEdgesOneway.R +++ b/functions/makeEdgesOneway.R @@ -10,9 +10,10 @@ makeEdgesOneway <- function(nodes_current, edges_current) { names.to.change <- c("fromX", "fromY", "toX", "toY") edges_current <- rename_with(edges_current, tolower, any_of(names.to.change)) - # for two-way, divide permlanes by 2, rounded up (as they will be split into 2 * one-way) + # for two-way, divide permlanes and capacity by 2, rounded up (as they will be split into 2 * one-way) edges_current <- edges_current %>% - mutate(permlanes = ifelse(is_oneway == 0, ceiling(permlanes / 2), permlanes)) + mutate(permlanes = ifelse(is_oneway == 0, ceiling(permlanes / 2), permlanes), + capacity = ifelse(is_oneway == 0, ceiling(capacity / 2), capacity)) # select only two-way edges edges_twoway <- edges_current %>% diff --git a/functions/processOsmTags.R b/functions/processOsmTags.R index 8179306..e1554a1 100644 --- a/functions/processOsmTags.R +++ b/functions/processOsmTags.R @@ -86,6 +86,10 @@ processOsmTags <- function(osm_df,this_defaults_df){ newLanes = ifelse(df$is_oneway[1] == 0, df$permlanes[1] * 2, df$permlanes[1]) df$permlanes[1] = newLanes } + } else { + # if no tags, then lanes is default number, multiplied by 2 if two-way + newLanes = ifelse(df$is_oneway[1] == 0, df$permlanes[1] * 2, df$permlanes[1]) + df$permlanes[1] = newLanes } return(df) } diff --git a/functions/restructureData.R b/functions/restructureData.R index ce96214..efb35cf 100644 --- a/functions/restructureData.R +++ b/functions/restructureData.R @@ -19,7 +19,7 @@ restructureData <- function(networkList, highway_lookup, mutate(freespeed=defaults_df$freespeed[16]) %>% mutate(laneCapacity=defaults_df$laneCapacity[16]) %>% mutate(is_car=0) %>% - mutate(permlanes=1) %>% # bikepaths are assumed sinlge lane + mutate(permlanes=2) %>% # bikepaths are assumed one lane in each direction mutate(is_oneway=0) %>% # bikepaths are assumed bi-directional dplyr::select(-uid) # merging changed bikepaths back with rest of the links