Issue #45: support parsing from tags.

This commit is contained in:
Sergey Vartanov 2021-06-01 02:46:02 +03:00
parent acfeee97eb
commit 62f10ab647
2 changed files with 10 additions and 4 deletions

View file

@ -202,9 +202,12 @@ class Road(Figure):
self.matcher: RoadMatcher = matcher self.matcher: RoadMatcher = matcher
self.width: Optional[float] = None self.width: Optional[float] = None
self.lanes: int = 1
if "lanes" in tags: if "lanes" in tags:
try: try:
self.width = float(tags["lanes"]) * 3.7 self.width = float(tags["lanes"]) * 3.7
self.lanes = float(tags["lanes"])
except ValueError: except ValueError:
pass pass
if "width" in tags: if "width" in tags:

View file

@ -2,12 +2,13 @@
Road shape drawing. Road shape drawing.
""" """
from dataclasses import dataclass from dataclasses import dataclass
from typing import List from typing import List, Any, Dict
import numpy as np import numpy as np
import svgwrite import svgwrite
from shapely.geometry import LineString, Point from shapely.geometry import LineString, Point
from roentgen.constructor import Road
from roentgen.flinger import Flinger, angle, turn_by_angle, norm from roentgen.flinger import Flinger, angle, turn_by_angle, norm
from roentgen.osm_reader import OSMNode from roentgen.osm_reader import OSMNode
@ -64,13 +65,15 @@ class RoadPart:
node_1: OSMNode, node_1: OSMNode,
node_2: OSMNode, node_2: OSMNode,
flinger: Flinger, flinger: Flinger,
left_offset: float, road: Road,
right_offset: float,
lanes: List[Lane],
) -> "RoadPart": ) -> "RoadPart":
""" """
Construct road part from OSM nodes. Construct road part from OSM nodes.
""" """
left_offset: float = road.width / 2
right_offset: float = road.width / 2
lanes = [Lane(road.width / road.lanes)] * road.lanes
return cls( return cls(
flinger.fling(node_1.coordinates), flinger.fling(node_1.coordinates),
flinger.fling(node_2.coordinates), flinger.fling(node_2.coordinates),