Skip to content
This repository has been archived by the owner on Mar 9, 2023. It is now read-only.

Add Direction To Access #193

Merged
merged 1 commit into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions osm2lanes/src/road/lane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize};
use crate::locale::Locale;
use crate::metric::{Metre, Speed};
use crate::road::separator::{Markings, Semantic};
use crate::tag::{Access as AccessValue, HighwayType};
use crate::tag::{Access as AccessTagValue, HighwayType};

/// A single lane
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
Expand All @@ -19,7 +19,7 @@ pub enum Lane {
#[serde(skip_serializing_if = "Option::is_none")]
max_speed: Option<Speed>,
#[serde(skip_serializing_if = "Option::is_none")]
access: Option<Access>,
access: Option<AccessByType>,
},
Parking {
direction: Direction,
Expand Down Expand Up @@ -170,19 +170,31 @@ impl Printable for Direction {
}

/// Access by vehicle type
///
/// Types as defined in <https://wiki.openstreetmap.org/wiki/Key:access#Land-based_transportation>
// TODO: how to handle the motor_vehicle vs motorcar discussion in https://wiki.openstreetmap.org/wiki/Key:motorcar#Controversy
// TODO: separating weight class by usage?
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub struct Access {
pub struct AccessByType {
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) foot: Option<AccessValue>,
pub(crate) foot: Option<AccessAndDirection>,
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) bicycle: Option<AccessValue>,
pub(crate) bicycle: Option<AccessAndDirection>,
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) taxi: Option<AccessValue>,
pub(crate) taxi: Option<AccessAndDirection>,
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) bus: Option<AccessValue>,
pub(crate) bus: Option<AccessAndDirection>,
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) motor: Option<AccessValue>,
pub(crate) motor: Option<AccessAndDirection>,
}

/// Access for a given user
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub struct AccessAndDirection {
pub(crate) access: AccessTagValue,
/// Direction, if different from designated direction
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) direction: Option<Direction>,
}
2 changes: 1 addition & 1 deletion osm2lanes/src/road/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::metric::Metre;
use crate::tag::Highway;

mod lane;
pub use lane::{Access, Designated, Direction, Lane, Printable};
pub use lane::{AccessAndDirection, AccessByType, Designated, Direction, Lane, Printable};

mod separator;
pub use separator::{Color, Marking, Markings, Semantic, Style};
Expand Down
27 changes: 19 additions & 8 deletions osm2lanes/src/transform/tags_to_lanes/road.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ use super::separator::{
use super::TagsToLanesMsg;
use crate::locale::{DrivingSide, Locale};
use crate::metric::{Metre, Speed};
use crate::road::{Access as LaneAccess, Designated, Direction, Lane};
use crate::road::{
AccessAndDirection as LaneAccessAndDirection, AccessByType as LaneAccessByType, Designated,
Direction, Lane,
};
use crate::tag::{Access as AccessValue, Highway, TagKey, Tags, HIGHWAY, LIFECYCLE};
use crate::transform::error::{RoadError, RoadWarnings};
use crate::transform::tags_to_lanes::counts::{CentreTurnLaneScheme, Counts};
Expand Down Expand Up @@ -56,8 +59,16 @@ pub struct Access {
pub motor: Infer<AccessValue>,
}

impl From<Access> for Option<LaneAccess> {
impl From<Access> for Option<LaneAccessByType> {
fn from(inferred: Access) -> Self {
impl LaneAccessAndDirection {
fn from(v: Infer<AccessValue>) -> Option<Self> {
v.some().map(|v| Self {
access: v,
direction: None,
})
}
}
if inferred.foot.is_none()
&& inferred.bicycle.is_none()
&& inferred.taxi.is_none()
Expand All @@ -66,12 +77,12 @@ impl From<Access> for Option<LaneAccess> {
{
return None;
}
Some(LaneAccess {
foot: inferred.foot.some(),
bicycle: inferred.bicycle.some(),
taxi: inferred.taxi.some(),
bus: inferred.bus.some(),
motor: inferred.motor.some(),
Some(LaneAccessByType {
foot: LaneAccessAndDirection::from(inferred.foot),
bicycle: LaneAccessAndDirection::from(inferred.bicycle),
taxi: LaneAccessAndDirection::from(inferred.taxi),
bus: LaneAccessAndDirection::from(inferred.bus),
motor: LaneAccessAndDirection::from(inferred.motor),
})
}
}
Expand Down