Separate ways and buildings.

This commit is contained in:
Sergey Vartanov 2020-09-19 21:01:31 +03:00
parent 2da1bfe972
commit 604fd0d14c
4 changed files with 45 additions and 44 deletions

View file

@ -515,7 +515,6 @@ nodes:
- tags: - tags:
railway: station railway: station
station: subway station: subway
transport: subway
network: London Underground network: London Underground
icon: [tfl] icon: [tfl]
- tags: {railway: subway_entrance, network: London Underground} - tags: {railway: subway_entrance, network: London Underground}

View file

@ -76,15 +76,19 @@ class Way:
Way in Röntgen terms. Way in Röntgen terms.
""" """
def __init__( def __init__(
self, kind: str, inners, outers, style: Dict[str, Any], self, inners, outers, style: Dict[str, Any],
layer: float = 0.0, levels=None): layer: float = 0.0, levels=None):
self.kind = kind self.inners = []
self.inners = inners self.outers = []
self.outers = outers
self.style: Dict[str, Any] = style self.style: Dict[str, Any] = style
self.layer = layer self.layer = layer
self.levels = levels self.levels = levels
for inner_nodes in inners:
self.inners.append(make_clockwise(inner_nodes))
for outer_nodes in outers:
self.outers.append(make_counter_clockwise(outer_nodes))
def get_path( def get_path(
self, flinger: Flinger, shift: np.array = np.array((0, 0))) -> str: self, flinger: Flinger, shift: np.array = np.array((0, 0))) -> str:
""" """
@ -95,12 +99,10 @@ class Way:
path: str = "" path: str = ""
for outer_nodes in self.outers: for outer_nodes in self.outers:
path += get_path( path += get_path(outer_nodes, shift, flinger) + " "
make_counter_clockwise(outer_nodes), shift, flinger) + " "
for inner_nodes in self.inners: for inner_nodes in self.inners:
path += get_path( path += get_path(inner_nodes, shift, flinger) + " "
make_clockwise(inner_nodes), shift, flinger) + " "
return path return path
@ -234,6 +236,7 @@ class Constructor:
self.nodes: List[Node] = [] self.nodes: List[Node] = []
self.ways: List[Way] = [] self.ways: List[Way] = []
self.buildings: List[Way] = []
def construct_ways(self): def construct_ways(self):
""" """
@ -289,7 +292,7 @@ class Constructor:
return return
user_color = get_user_color(way.user, self.seed) user_color = get_user_color(way.user, self.seed)
self.ways.append( self.ways.append(
Way("way", inners, outers, Way(inners, outers,
{"fill": "none", "stroke": user_color.hex, {"fill": "none", "stroke": user_color.hex,
"stroke-width": 1})) "stroke-width": 1}))
return return
@ -299,7 +302,7 @@ class Constructor:
return return
time_color = get_time_color(way.timestamp) time_color = get_time_color(way.timestamp)
self.ways.append( self.ways.append(
Way("way", inners, outers, Way(inners, outers,
{"fill": "none", "stroke": time_color.hex, {"fill": "none", "stroke": time_color.hex,
"stroke-width": 1})) "stroke-width": 1}))
return return
@ -355,10 +358,13 @@ class Constructor:
style["stroke-width"] = \ style["stroke-width"] = \
element["r2"] * \ element["r2"] * \
self.flinger.get_scale(center_coordinates) + 2 self.flinger.get_scale(center_coordinates) + 2
self.ways.append( w = Way(inners, outers, style, layer, levels)
Way(kind, inners, outers, style, layer, levels)) if kind == "way":
self.ways.append(w)
elif kind == "building":
self.buildings.append(w)
if center_point is not None and \ if center_point is not None and \
(way.is_cycle() or "area" in tags and tags["area"]): (way.is_cycle() and "area" in tags and tags["area"]):
icon_set: IconSet = self.scheme.get_icon(tags) icon_set: IconSet = self.scheme.get_icon(tags)
self.nodes.append(Node( self.nodes.append(Node(
icon_set, tags, center_point, center_coordinates, icon_set, tags, center_point, center_coordinates,

View file

@ -229,9 +229,6 @@ class Painter:
Draw area between way and way shifted by the vector. Draw area between way and way shifted by the vector.
""" """
for way in ways: for way in ways:
if way.kind != "building":
continue
if stage == 1: if stage == 1:
shift_1 = [0, 0] shift_1 = [0, 0]
shift_2 = [0, -1] shift_2 = [0, -1]
@ -256,26 +253,26 @@ class Painter:
np.add(flung_1, shift_2), "Z"), np.add(flung_1, shift_2), "Z"),
fill=color.hex, stroke=color.hex, stroke_width=1)) fill=color.hex, stroke=color.hex, stroke_width=1))
def draw(self, nodes: List[Node], ways: List[Way], points): def draw(self, constructor: Constructor, points):
""" """
Draw map. Draw map.
""" """
ways = sorted(ways, key=lambda x: x.layer) ways = sorted(constructor.ways, key=lambda x: x.layer)
for way in ways: # type: Way ways_length: int = len(ways)
if way.kind == "way": for index, way in enumerate(ways): # type: Way
path: str = way.get_path(self.flinger) ui.progress_bar(index, ways_length, step=10, text="Drawing ways")
if path: path: str = way.get_path(self.flinger)
p = Path(d=path) if path:
p.update(way.style) p = Path(d=path)
self.svg.add(p) p.update(way.style)
self.svg.add(p)
ui.progress_bar(-1, 0, text="Drawing ways")
# Building shade # Building shade
building_shade = Group(opacity=0.1) building_shade = Group(opacity=0.1)
for way in ways: # type: Way for way in constructor.buildings: # type: Way
if way.kind != "building":
continue
shift = [-5, 5] shift = [-5, 5]
if way.levels: if way.levels:
shift = [-5 * way.levels, 5 * way.levels] shift = [-5 * way.levels, 5 * way.levels]
@ -292,17 +289,15 @@ class Painter:
# Building walls # Building walls
self.draw_building_walls(1, Color("#AAAAAA"), ways) self.draw_building_walls(1, Color("#AAAAAA"), constructor.buildings)
self.draw_building_walls(2, Color("#C3C3C3"), ways) self.draw_building_walls(2, Color("#C3C3C3"), constructor.buildings)
self.draw_building_walls(3, Color("#DDDDDD"), ways) self.draw_building_walls(3, Color("#DDDDDD"), constructor.buildings)
# Building roof # Building roof
building_paths: List[(str, Dict)] = [] building_paths: List[(str, Dict)] = []
for way in ways: # type: Way for way in constructor.buildings: # type: Way
if way.kind != "building":
continue
shift = [0, -3] shift = [0, -3]
if way.levels: if way.levels:
shift = np.array([0 * way.levels, min(-3, -1 * way.levels)]) shift = np.array([0 * way.levels, min(-3, -1 * way.levels)])
@ -323,7 +318,7 @@ class Painter:
# Trees # Trees
for node in nodes: for node in constructor.nodes:
if not (node.get_tag("natural") == "tree" and if not (node.get_tag("natural") == "tree" and
("diameter_crown" in node.tags or ("diameter_crown" in node.tags or
"circumference" in node.tags)): "circumference" in node.tags)):
@ -343,7 +338,7 @@ class Painter:
# Directions # Directions
for node in nodes: # type: Node for node in constructor.nodes: # type: Node
angle = None angle = None
is_revert_gradient: bool = False is_revert_gradient: bool = False
@ -356,18 +351,18 @@ class Painter:
angle = float(node.get_tag("angle")) angle = float(node.get_tag("angle"))
direction_radius: float = \ direction_radius: float = \
25 * self.flinger.get_scale(node.coordinates) 25 * self.flinger.get_scale(node.coordinates)
direction_color: str = \ direction_color: Color = \
self.scheme.get_color("direction_camera_color") self.scheme.get_color("direction_camera_color")
elif node.get_tag("traffic_sign") == "stop": elif node.get_tag("traffic_sign") == "stop":
direction = node.get_tag("direction") direction = node.get_tag("direction")
direction_radius: float = \ direction_radius: float = \
25 * self.flinger.get_scale(node.coordinates) 25 * self.flinger.get_scale(node.coordinates)
direction_color: str = Color("red") direction_color: Color = Color("red")
else: else:
direction = node.get_tag("direction") direction = node.get_tag("direction")
direction_radius: float = \ direction_radius: float = \
50 * self.flinger.get_scale(node.coordinates) 50 * self.flinger.get_scale(node.coordinates)
direction_color: str = \ direction_color: Color = \
self.scheme.get_color("direction_view_color") self.scheme.get_color("direction_view_color")
is_revert_gradient = True is_revert_gradient = True
@ -399,15 +394,15 @@ class Painter:
# All other nodes # All other nodes
nodes = sorted(nodes, key=lambda x: x.layer) nodes = sorted(constructor.nodes, key=lambda x: x.layer)
for index, node in enumerate(nodes): # type: int, Node for index, node in enumerate(nodes): # type: int, Node
if node.get_tag("natural") == "tree" and \ if node.get_tag("natural") == "tree" and \
("diameter_crown" in node.tags or ("diameter_crown" in node.tags or
"circumference" in node.tags): "circumference" in node.tags):
continue continue
ui.progress_bar(index, len(nodes), step=10, text="Draw nodes") ui.progress_bar(index, len(nodes), step=10, text="Drawing nodes")
self.draw_shapes(node, points) self.draw_shapes(node, points)
ui.progress_bar(-1, len(nodes), step=10, text="Draw nodes") ui.progress_bar(-1, len(nodes), step=10, text="Drawing nodes")
if self.draw_captions == "no": if self.draw_captions == "no":
return return
@ -589,7 +584,7 @@ def main(argv):
draw_captions=options.draw_captions, draw_captions=options.draw_captions,
map_=map_, flinger=flinger, svg=svg, icon_extractor=icon_extractor, map_=map_, flinger=flinger, svg=svg, icon_extractor=icon_extractor,
scheme=scheme) scheme=scheme)
painter.draw(constructor.nodes, constructor.ways, points) painter.draw(constructor, points)
if options.show_index: if options.show_index:
draw_index(flinger, map_, max1, min1, svg) draw_index(flinger, map_, max1, min1, svg)

View file

@ -107,6 +107,7 @@ def progress_bar(
:param length: progress bar length. :param length: progress bar length.
:param step: frequency of progress bar updating (assuming that numbers go :param step: frequency of progress bar updating (assuming that numbers go
subsequently) subsequently)
:param text: short description
""" """
if number == -1: if number == -1:
print(f"100 % {length * ''}{text}") print(f"100 % {length * ''}{text}")