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

Commit

Permalink
Implement a simple solution
Browse files Browse the repository at this point in the history
  • Loading branch information
droogmic committed May 29, 2022
1 parent 29c4547 commit 1148512
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 11 deletions.
49 changes: 46 additions & 3 deletions data/spec-lanes.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@
},
"access": {
"type": "object",
"description": "Access to the lane. Freeform tags matching OSM way access",
"additionalProperties": {
"type": "string"
"description": "Access by mode.",
"properties": {
"bicycle": {
"$ref": "/schemas/access"
}
}
},
"markings": {
Expand Down Expand Up @@ -159,6 +161,47 @@
"const": "osm2lanes"
}
]
},
"access": {
"$id": "/schemas/access",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"description": "Legal access for a lane. Only populated if different than default",
"required": [
"access"
],
"properties": {
"access": {
"type": "string",
"description": "The access value.",
"anyOf": [
{
"const": "yes"
},
{
"const": "no"
},
{
"const": "designated"
}
]
},
"direction": {
"type": "string",
"description": "The direction of the access, if applicable.",
"anyOf": [
{
"const": "forward"
},
{
"const": "backward"
},
{
"const": "both"
}
]
}
}
}
}
}
4 changes: 2 additions & 2 deletions osm2lanes/src/road/lane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl Printable for Direction {
// 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")]
#[serde(rename_all = "snake_case")]
pub struct AccessByType {
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) foot: Option<AccessAndDirection>,
Expand All @@ -191,7 +191,7 @@ pub struct AccessByType {

/// Access for a given user
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
#[serde(rename_all = "snake_case")]
pub struct AccessAndDirection {
pub(crate) access: AccessTagValue,
/// Direction, if different from designated direction
Expand Down
35 changes: 30 additions & 5 deletions osm2lanes/src/transform/lanes_to_tags/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#![allow(clippy::module_name_repetitions)] // TODO: fix upstream

use celes::Country;
use osm_tags::Access;

pub use self::error::LanesToTagsMsg;
use super::{tags_to_lanes, TagsToLanesConfig};
use crate::locale::Locale;
use crate::locale::{DrivingSide, Locale};
use crate::metric::Speed;
use crate::road::{Color, Designated, Direction, Lane, Marking, Road};
use crate::road::{AccessByType, Color, Designated, Direction, Lane, Marking, Road};
use crate::tag::Tags;

#[non_exhaustive]
Expand All @@ -33,6 +34,13 @@ impl Lane {
fn is_shoulder(&self) -> bool {
matches!(self, Lane::Shoulder { .. })
}

fn access(&self) -> Option<&AccessByType> {
match self {
Self::Travel { access, .. } => access.as_ref(),
_ => None,
}
}
}

mod error {
Expand Down Expand Up @@ -159,7 +167,7 @@ pub fn lanes_to_tags(
set_shoulder(lanes, &mut tags)?;
set_pedestrian(lanes, &mut tags)?;
set_parking(lanes, &mut tags)?;
set_cycleway(lanes, &mut tags, oneway)?;
set_cycleway(lanes, &mut tags, oneway, locale)?;
set_busway(lanes, &mut tags, oneway)?;

let max_speed = get_max_speed(lanes, &mut tags)?;
Expand Down Expand Up @@ -326,7 +334,12 @@ fn set_parking(lanes: &[Lane], tags: &mut Tags) -> Result<(), LanesToTagsMsg> {
Ok(())
}

fn set_cycleway(lanes: &[Lane], tags: &mut Tags, oneway: bool) -> Result<(), LanesToTagsMsg> {
fn set_cycleway(
lanes: &[Lane],
tags: &mut Tags,
oneway: bool,
locale: &Locale,
) -> Result<(), LanesToTagsMsg> {
let left_cycle_lane: Option<&Lane> = lanes
.iter()
.take_while(|lane| !lane.is_motor())
Expand Down Expand Up @@ -396,7 +409,19 @@ fn set_cycleway(lanes: &[Lane], tags: &mut Tags, oneway: bool) -> Result<(), Lan
}

// Handle shared lanes
if lanes.forward_inside() // TODO: this needs to exist...
//if lanes.forward_inside() // TODO: this needs to exist...
if lanes.len() == 1 {
let lane = match locale.driving_side {
DrivingSide::Right => lanes.last(),
DrivingSide::Left => lanes.first(),
};
if let Some(bicycle) = lane.and_then(Lane::access).and_then(|a| a.bicycle.as_ref()) {
if oneway && bicycle.access == Access::Yes && bicycle.direction == Some(Direction::Both)
{
tags.checked_insert("cycleway", "opposite")?;
}
}
}

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion osm2lanes/src/transform/tags_to_lanes/modes/bicycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ pub(in crate::transform::tags_to_lanes) fn bicycle(
.bicycle = Infer::Direct(AccessAndDirection {
access: Access::Yes,
direction: Some(Direction::Both),
})
});
},
},
Location::Both { forward, backward } => {
Expand Down

0 comments on commit 1148512

Please sign in to comment.