mirror of
https://github.com/enzet/map-machine.git
synced 2025-06-06 04:41:54 +02:00
Add processed tags set for labels.
This commit is contained in:
parent
0fc290d844
commit
617265dce5
9 changed files with 30 additions and 28 deletions
BIN
doc/grid.png
BIN
doc/grid.png
Binary file not shown.
Before Width: | Height: | Size: 71 KiB After Width: | Height: | Size: 72 KiB |
Binary file not shown.
Before Width: | Height: | Size: 652 B After Width: | Height: | Size: 14 KiB |
11
roentgen.py
11
roentgen.py
|
@ -6,14 +6,13 @@ Author: Sergey Vartanov (me@enzet.ru).
|
|||
import argparse
|
||||
import os
|
||||
import sys
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
|
||||
import numpy as np
|
||||
import svgwrite
|
||||
|
||||
from roentgen import ui
|
||||
from roentgen.ui import error, parse_options
|
||||
from roentgen.constructor import Constructor
|
||||
from roentgen.flinger import Flinger
|
||||
from roentgen.grid import draw_all_icons
|
||||
|
@ -35,7 +34,7 @@ def main(argv) -> None:
|
|||
|
||||
:param argv: command-line arguments
|
||||
"""
|
||||
options: argparse.Namespace = ui.parse_options(argv)
|
||||
options: argparse.Namespace = parse_options(argv)
|
||||
|
||||
if not options:
|
||||
sys.exit(1)
|
||||
|
@ -47,7 +46,7 @@ def main(argv) -> None:
|
|||
else:
|
||||
content = get_osm(options.boundary_box)
|
||||
if not content:
|
||||
ui.error("cannot download OSM data")
|
||||
error("cannot download OSM data")
|
||||
input_file_names = ["map" / Path(options.boundary_box + ".osm")]
|
||||
|
||||
scheme: Scheme = Scheme(Path(TAGS_FILE_NAME))
|
||||
|
@ -123,8 +122,8 @@ def main(argv) -> None:
|
|||
painter.draw(constructor)
|
||||
|
||||
print("Writing output SVG...")
|
||||
svg.write(open(options.output_file_name, "w"))
|
||||
print("Done.")
|
||||
with open(options.output_file_name, "w") as output_file:
|
||||
svg.write(output_file)
|
||||
|
||||
|
||||
def draw_element(target: str, tags_description: str):
|
||||
|
|
|
@ -12,8 +12,9 @@ from colour import Color
|
|||
from roentgen import ui
|
||||
from roentgen.color import get_gradient_color
|
||||
from roentgen.flinger import Flinger
|
||||
from roentgen.icon import (DEFAULT_SMALL_SHAPE_ID, Icon, IconSet,
|
||||
ShapeExtractor, ShapeSpecification)
|
||||
from roentgen.icon import (
|
||||
DEFAULT_SMALL_SHAPE_ID, Icon, IconSet, ShapeExtractor, ShapeSpecification
|
||||
)
|
||||
from roentgen.osm_reader import (
|
||||
Map, OSMMember, OSMNode, OSMRelation, OSMWay, Tagged
|
||||
)
|
||||
|
@ -257,6 +258,7 @@ class Constructor:
|
|||
"""
|
||||
Röntgen node and way constructor.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self, map_: Map, flinger: Flinger, scheme: Scheme,
|
||||
icon_extractor: ShapeExtractor, check_level=lambda x: True,
|
||||
|
@ -270,11 +272,11 @@ class Constructor:
|
|||
self.scheme: Scheme = scheme
|
||||
self.icon_extractor = icon_extractor
|
||||
|
||||
self.nodes: List[Point] = []
|
||||
self.points: List[Point] = []
|
||||
self.figures: List[Figure] = []
|
||||
self.buildings: List[Figure] = []
|
||||
|
||||
self.levels: Set[float] = {0.5, 1}
|
||||
self.levels: Set[float] = {0.5, 1.0}
|
||||
|
||||
def add_building(self, building: Building) -> None:
|
||||
"""
|
||||
|
@ -371,7 +373,7 @@ class Constructor:
|
|||
)
|
||||
labels = self.scheme.construct_text(line.tags, "all")
|
||||
|
||||
self.nodes.append(Point(
|
||||
self.points.append(Point(
|
||||
icon_set, labels, line.tags, center_point,
|
||||
center_coordinates, is_for_node=False, priority=priority
|
||||
))
|
||||
|
@ -391,7 +393,7 @@ class Constructor:
|
|||
)
|
||||
labels = self.scheme.construct_text(line.tags, "all")
|
||||
|
||||
self.nodes.append(Point(
|
||||
self.points.append(Point(
|
||||
icon_set, labels, line.tags, center_point, center_coordinates,
|
||||
is_for_node=False, priority=priority
|
||||
))
|
||||
|
@ -471,9 +473,9 @@ class Constructor:
|
|||
icon_set, priority = self.scheme.get_icon(
|
||||
self.icon_extractor, tags
|
||||
)
|
||||
labels = self.scheme.construct_text(tags, True)
|
||||
labels = self.scheme.construct_text(tags, "all")
|
||||
|
||||
self.nodes.append(Point(
|
||||
self.points.append(Point(
|
||||
icon_set, labels, tags, flung, node.coordinates,
|
||||
priority=priority, draw_outline=draw_outline
|
||||
))
|
||||
|
|
|
@ -76,7 +76,7 @@ class Painter:
|
|||
|
||||
# Trees
|
||||
|
||||
for node in constructor.nodes:
|
||||
for node in constructor.points:
|
||||
if not (node.get_tag("natural") == "tree" and
|
||||
("diameter_crown" in node.tags or
|
||||
"circumference" in node.tags)):
|
||||
|
@ -167,7 +167,7 @@ class Painter:
|
|||
|
||||
# Directions
|
||||
|
||||
for node in constructor.nodes: # type: Point
|
||||
for node in constructor.points: # type: Point
|
||||
|
||||
angle = None
|
||||
is_revert_gradient: bool = False
|
||||
|
@ -232,7 +232,7 @@ class Painter:
|
|||
occupied = Occupied(
|
||||
self.flinger.size[0], self.flinger.size[1], self.overlap)
|
||||
|
||||
nodes = sorted(constructor.nodes, key=lambda x: -x.priority)
|
||||
nodes = sorted(constructor.points, key=lambda x: -x.priority)
|
||||
steps: int = len(nodes)
|
||||
|
||||
for index, node in enumerate(nodes): # type: int, Point
|
||||
|
|
|
@ -2,15 +2,14 @@
|
|||
Reading OpenStreetMap data from XML file.
|
||||
"""
|
||||
import json
|
||||
import xml.etree.ElementTree as ET
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, List, Optional, Set, Union
|
||||
from typing import Any, Dict, List, Optional, Set
|
||||
|
||||
import numpy as np
|
||||
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
from roentgen.util import MinMax
|
||||
|
||||
__author__ = "Sergey Vartanov"
|
||||
|
|
|
@ -49,7 +49,7 @@ class Point(Tagged):
|
|||
"""
|
||||
Object on the map with no dimensional attributes.
|
||||
|
||||
It may have icons and text.
|
||||
It may have icons and labels.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
|
|
|
@ -363,7 +363,8 @@ class Scheme:
|
|||
if draw_captions == "main":
|
||||
return texts
|
||||
|
||||
texts += get_text(tags)
|
||||
processed: Set[str] = set()
|
||||
texts += get_text(tags, processed)
|
||||
|
||||
if "route_ref" in tags:
|
||||
texts.append(Label(tags["route_ref"].replace(";", " ")))
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
OSM address tag processing.
|
||||
"""
|
||||
from dataclasses import dataclass
|
||||
from typing import Any, Dict, List
|
||||
from typing import Any, Dict, List, Set
|
||||
|
||||
from colour import Color
|
||||
|
||||
|
@ -74,13 +74,10 @@ def format_frequency(value: str) -> str:
|
|||
"""
|
||||
Format frequency value to more human-readable form.
|
||||
"""
|
||||
try:
|
||||
return f"{value} Hz"
|
||||
except ValueError:
|
||||
return value
|
||||
return f"{value} "
|
||||
|
||||
|
||||
def get_text(tags: Dict[str, Any]) -> List[Label]:
|
||||
def get_text(tags: Dict[str, Any], processed: Set[str]) -> List[Label]:
|
||||
"""
|
||||
Get text representation of writable tags.
|
||||
"""
|
||||
|
@ -89,10 +86,13 @@ def get_text(tags: Dict[str, Any]) -> List[Label]:
|
|||
values: List[str] = []
|
||||
if "voltage:primary" in tags:
|
||||
values.append(tags["voltage:primary"])
|
||||
processed.add("voltage:primary")
|
||||
if "voltage:secondary" in tags:
|
||||
values.append(tags["voltage:secondary"])
|
||||
processed.add("voltage:secondary")
|
||||
if "voltage" in tags:
|
||||
values = tags["voltage"].split(";")
|
||||
processed.add("voltage")
|
||||
if values:
|
||||
texts.append(Label(", ".join(map(format_voltage, values))))
|
||||
|
||||
|
@ -100,5 +100,6 @@ def get_text(tags: Dict[str, Any]) -> List[Label]:
|
|||
texts.append(Label(", ".join(map(
|
||||
format_frequency, tags["frequency"].split(";")
|
||||
))))
|
||||
processed.add("frequency")
|
||||
|
||||
return texts
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue