Support bridges for roads.

This commit is contained in:
Sergey Vartanov 2021-09-13 06:31:12 +03:00
parent b99a2ae87e
commit 30dacffddf
4 changed files with 38 additions and 32 deletions

View file

@ -291,10 +291,7 @@ class Constructor:
priority: int
icon_set: IconSet
icon_set, priority = self.scheme.get_icon(
self.extractor,
line.tags,
processed,
self.configuration,
self.extractor, line.tags, processed, self.configuration
)
if icon_set is not None:
labels: list[Label] = self.scheme.construct_text(

View file

@ -245,6 +245,35 @@ class Road(Figure):
except ValueError:
pass
def draw(
self,
svg: Drawing,
flinger: Flinger,
color: Color,
extra_width: float = 0,
) -> None:
"""Draw road as simple SVG path."""
flinger.get_scale()
width: float
if self.width is not None:
width = self.width
else:
width = self.matcher.default_width
if extra_width and self.tags.get("bridge") == "yes":
color = Color("#666666")
scale: float = flinger.get_scale(self.outers[0][0].coordinates)
path_commands: str = self.get_path(flinger)
path: Path = Path(d=path_commands)
style: dict[str, Any] = {
"fill": "none",
"stroke": color.hex,
"stroke-linecap": "round",
"stroke-linejoin": "round",
"stroke-width": scale * width + extra_width,
}
path.update(style)
svg.add(path)
class Crater(Tagged):
"""

View file

@ -23321,9 +23321,12 @@
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc" />
<path
style="opacity:1;fill:none;fill-opacity:1;stroke:#333333;stroke-width:0.1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
style="opacity:1;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
d="M 257.5 403 C 257.223 403 257 403.20653 257 403.46289 L 257 403.53711 C 257 403.79347 257.223 404 257.5 404 L 258 404 L 258 413 L 257.5 413 C 257.223 413 257 413.20653 257 413.46289 L 257 413.53711 C 257 413.79347 257.223 414 257.5 414 L 269.5 414 C 269.777 414 270 413.79347 270 413.53711 L 270 413.46289 C 270 413.20653 269.777 413 269.5 413 L 266 413 L 266 408.80859 L 269.72266 406.94727 A 0.50005 0.50005 0 0 0 269.50195 405.99609 A 0.50005 0.50005 0 0 0 269.27734 406.05273 L 265.31055 408.03516 C 265.30219 408.03831 265.29524 408.04331 265.28711 408.04688 L 265.27734 408.05273 A 0.50005 0.50005 0 0 0 265.16211 408.125 C 265.15386 408.13207 265.14638 408.13891 265.13867 408.14648 A 0.50005 0.50005 0 0 0 265 408.63867 L 265 413 L 264 413 L 264 404 L 264.44922 404 C 264.72622 404 264.94922 403.79347 264.94922 403.53711 L 264.94922 403.46289 C 264.94922 403.20653 264.72622 403 264.44922 403 L 257.5 403 z M 260 405 L 262 405 C 262.554 405 263 405.446 263 406 L 263 408 C 263 408.554 262.554 409 262 409 L 260 409 C 259.446 409 259 408.554 259 408 L 259 406 C 259 405.446 259.446 405 260 405 z "
id="toll_booth"
inkscape:label="#rect11071" />
inkscape:label="#rect11071">
<title
id="title11643">toll booth</title>
</path>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 1.3 MiB

After

Width:  |  Height:  |  Size: 1.3 MiB

Before After
Before After

View file

@ -4,7 +4,7 @@ Simple OpenStreetMap renderer.
import argparse
import logging
from pathlib import Path
from typing import Any, Iterator, Optional
from typing import Iterator, Optional
import numpy as np
import svgwrite
@ -74,9 +74,9 @@ class Map:
constructor.roads, key=lambda x: x.matcher.priority
)
for road in roads:
self.draw_road(road, road.matcher.border_color, 2)
road.draw(self.svg, self.flinger, road.matcher.border_color, 2)
for road in roads:
self.draw_road(road, road.matcher.color)
road.draw(self.svg, self.flinger, road.matcher.color)
for tree in constructor.trees:
tree.draw(self.svg, self.flinger, self.scheme)
@ -160,29 +160,6 @@ class Map:
progress_bar(-1, count, step=1, text="Drawing buildings")
def draw_road(
self, road: Road, color: Color, extra_width: float = 0
) -> None:
"""Draw road as simple SVG path."""
self.flinger.get_scale()
width: float
if road.width is not None:
width = road.width
else:
width = road.matcher.default_width
scale: float = self.flinger.get_scale(road.outers[0][0].coordinates)
path_commands: str = road.get_path(self.flinger)
path: SVGPath = SVGPath(d=path_commands)
style: dict[str, Any] = {
"fill": "none",
"stroke": color.hex,
"stroke-linecap": "round",
"stroke-linejoin": "round",
"stroke-width": scale * width + extra_width,
}
path.update(style)
self.svg.add(path)
def draw_roads(self, roads: Iterator[Road]) -> None:
"""Draw road as simple SVG path."""
nodes: dict[OSMNode, set[RoadPart]] = {}