Ways and nodes drawing refactoring.

This commit is contained in:
Sergey Vartanov 2015-08-12 12:14:09 +03:00
parent 4e129259b3
commit 4cf5a8c882
4 changed files with 144 additions and 138 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 27 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 83 KiB

After

Width:  |  Height:  |  Size: 82 KiB

Before After
Before After

View file

@ -239,104 +239,88 @@ def line_center(node_ids):
return Vector((ma.x + mi.x) / 2.0, (ma.y + mi.y) / 2.0) return Vector((ma.x + mi.x) / 2.0, (ma.y + mi.y) / 2.0)
def draw_ways(show_missed_tags=False): def construct_ways(drawing):
for level in sorted(layers.keys()): for way_id in way_map:
layer = layers[level] way = way_map[way_id]
#for entity in ['b', 'h1', 'h2', 'r', 'n', 'l', 'a', 'le', 'ba']: tags = way['tags']
nodes = way['nodes']
# Pre part. if nodes[0] == nodes[-1]:
style = 'fill:#0000FF;stroke:none;'
for way in layer['le']:
if way['tags']['leisure'] == 'park':
style = 'fill:#' + grass_color + ';'
else: else:
continue style = 'stroke:#0000FF;fill:none;'
draw_path(way['nodes'], style) layer = float(tags['layer']) if ('layer' in tags) else 0
c = line_center(nodes)
# Post part. if 'landuse' in tags:
if tags['landuse'] == 'grass':
way_number = 0
for way in layer['l']:
way_number += 1
ui.write_line(way_number, len(layer['l']))
text_y = 0
c = line_center(way['nodes'])
if way['tags']['landuse'] == 'grass':
style = 'fill:#' + grass_color + ';stroke:none;' style = 'fill:#' + grass_color + ';stroke:none;'
draw_path(way['nodes'], style) elif tags['landuse'] == 'conservation':
elif way['tags']['landuse'] == 'conservation':
style = 'fill:#' + grass_color + ';stroke:none;' style = 'fill:#' + grass_color + ';stroke:none;'
draw_path(way['nodes'], style) elif tags['landuse'] == 'forest':
elif way['tags']['landuse'] == 'forest':
style = 'fill:#' + wood_color + ';stroke:none;' style = 'fill:#' + wood_color + ';stroke:none;'
draw_path(way['nodes'], style) elif tags['landuse'] == 'garages':
elif way['tags']['landuse'] == 'garages':
style = 'fill:#' + parking_color + ';stroke:none;' style = 'fill:#' + parking_color + ';stroke:none;'
draw_path(way['nodes'], style) shapes, fill, processed = process.get_icon(tags, scheme, '444444')
draw_point_shape('parking', c.x, c.y, '444444') drawing['nodes'].append({'shapes': shapes,
'x': c.x, 'y': c.y, 'color': fill, 'processed': processed})
elif way['tags']['landuse'] == 'construction': elif way['tags']['landuse'] == 'construction':
style = 'fill:#' + construction_color + ';stroke:none;' style = 'fill:#' + construction_color + ';stroke:none;'
draw_path(way['nodes'], style)
elif way['tags']['landuse'] in ['residential', 'commercial']: elif way['tags']['landuse'] in ['residential', 'commercial']:
continue continue
else: elif 'building' in tags:
style = 'fill:#0000FF;stroke:none;' text_y = 0
draw_path(way['nodes'], style) style = 'fill:#' + building_color + ';stroke:#' + \
#for tag in way['tags']: building_border_color + ';opacity:1.0;'
# if not (tag in ['landuse', 'layer']): shapes, fill, processed = process.get_icon(tags, scheme, '444444')
# point(tag, str(way['tags'][tag]), c.x, c.y, '000000', text_y) drawing['nodes'].append({'shapes': shapes, 'x': c.x, 'y': c.y,
# text_y += 10 'color': fill, 'priority': 1, 'processed': processed,
for way in layer['a']: 'tags': tags})
c = line_center(way['nodes']) elif 'amenity' in tags:
if way['tags']['amenity'] == 'parking': if tags['amenity'] == 'parking':
style = 'fill:#' + parking_color + ';stroke:none;' style = 'fill:#' + parking_color + ';stroke:none;'
draw_path(way['nodes'], style)
draw_point_shape('parking', c.x, c.y, '444444') draw_point_shape('parking', c.x, c.y, '444444')
elif way['tags']['amenity'] == 'school': elif 'natural' in tags:
continue v = way['tags']['natural']
else: style = 'stroke:none;'
style = 'fill:#0000FF;stroke:none;' if v == 'wood':
draw_path(way['nodes'], style) style += 'fill:#' + wood_color + ';'
for way in layer['n']: elif v == 'scrub':
if way['tags']['natural'] == 'wood': style += 'fill:#' + wood_color + ';'
style = 'fill:#' + wood_color + ';stroke:none;' elif v == 'sand':
elif way['tags']['natural'] == 'scrub': style += 'fill:#' + sand_color + ';'
style = 'fill:#' + wood_color + ';stroke:none;' elif v == 'beach':
elif way['tags']['natural'] == 'sand': style += 'fill:#' + beach_color + ';'
style = 'fill:#' + sand_color + ';stroke:none;' elif v == 'desert':
elif way['tags']['natural'] == 'beach': style += 'fill:#' + desert_color + ';'
style = 'fill:#' + beach_color + ';stroke:none;' elif v == 'forest':
elif way['tags']['natural'] == 'desert': style += 'fill:#' + wood_color + ';'
style = 'fill:#' + desert_color + ';stroke:none;' elif v == 'water':
elif way['tags']['natural'] == 'water': style = 'fill:#' + water_color + ';stroke:#' + \
style = 'fill:#' + water_color + ';stroke:#' + water_border_color + ';stroke-width:1.0;' water_border_color + ';stroke-width:1.0;'
elif way['tags']['natural'] == 'forest': elif 'waterway' in tags:
style = 'fill:#' + wood_color + ';stroke:none;' if tags['waterway'] == 'riverbank':
else: style = 'fill:#' + water_color + ';stroke:#' + \
continue water_border_color + ';stroke-width:1.0;'
draw_path(way['nodes'], style) elif tags['waterway'] == 'river':
for way in layer['w']:
if way['tags']['waterway'] == 'riverbank':
style = 'fill:#' + water_color + ';stroke:#' + water_border_color + ';stroke-width:1.0;'
elif way['tags']['waterway'] == 'river':
style = 'fill:none;stroke:#' + water_color + ';stroke-width:10.0;' style = 'fill:none;stroke:#' + water_color + ';stroke-width:10.0;'
draw_path(way['nodes'], style) elif 'railway' in tags:
for way in layer['r']: v = tags['railway']
v = way['tags']['railway'] style = 'fill:none;stroke-dasharray:none;stroke-linejoin:round;' + \
style = 'fill:none;stroke-dasharray:none;stroke-linejoin:round;stroke-linecap:round;stroke-width:' 'stroke-linecap:round;stroke-width:'
if v == 'subway': style += '10;stroke:#DDDDDD;' if v == 'subway': style += '10;stroke:#DDDDDD;'
if v in ['narrow_gauge', 'tram']: if v in ['narrow_gauge', 'tram']:
style += '2;stroke:#000000;' style += '2;stroke:#000000;'
else: else:
continue continue
draw_path(way['nodes'], style) elif 'highway' in tags:
for way in layer['h1']: v = tags['highway']
if 'tunnel' in way['tags'] and way['tags']['tunnel'] == 'yes': if 'tunnel' in tags and tags['tunnel'] == 'yes':
style = 'fill:none;stroke:#FFFFFF;stroke-dasharray:none;stroke-linejoin:round;stroke-linecap:round;stroke-width:10;' style = 'fill:none;stroke:#FFFFFF;stroke-dasharray:none;' + \
draw_path(way['nodes'], style) 'stroke-linejoin:round;stroke-linecap:round;stroke-width:10;'
for way in layer['h1']: drawing['ways'].append({'kind': 'way', 'nodes': nodes,
v = way['tags']['highway'] 'layer': layer - 100, 'priority': 50, 'style': style})
style = 'fill:none;stroke:#AAAAAA;stroke-dasharray:none;stroke-linejoin:round;stroke-linecap:round;stroke-width:'
style = 'fill:none;stroke:#AAAAAA;stroke-dasharray:none;' + \
'stroke-linejoin:round;stroke-linecap:round;stroke-width:'
if v == 'motorway': style += '30' if v == 'motorway': style += '30'
elif v == 'trunk': style += '25' elif v == 'trunk': style += '25'
elif v == 'primary': style += '20;stroke:#' + primary_border_color elif v == 'primary': style += '20;stroke:#' + primary_border_color
@ -346,16 +330,14 @@ def draw_ways(show_missed_tags=False):
elif v == 'residential': style += '8' elif v == 'residential': style += '8'
elif v == 'service': style += '7' elif v == 'service': style += '7'
elif v == 'track': style += '3' elif v == 'track': style += '3'
elif v in ['footway', 'pedestrian']: style += '1;stroke-dasharray:3,3;stroke-linecap:butt;stroke:#888888' else: style = None
elif v == 'steps': style += '5;stroke-dasharray:1,2;stroke-linecap:butt' if style:
elif v == 'path': style += '1;stroke-dasharray:5,5;stroke-linecap:butt'
else:
continue
style += ';' style += ';'
draw_path(way['nodes'], style) drawing['ways'].append({'kind': 'way', 'nodes': nodes,
for way in layer['h2']: 'layer': layer - 0.01, 'priority': 50, 'style': style})
v = way['tags']['highway']
style = 'fill:none;stroke:#FFFFFF;stroke-linecap:round;stroke-linejoin:round;stroke-width:' style = 'fill:none;stroke:#FFFFFF;stroke-linecap:round;' + \
'stroke-linejoin:round;stroke-width:'
if v == 'motorway': style += '28' if v == 'motorway': style += '28'
elif v == 'trunk': style += '23' elif v == 'trunk': style += '23'
elif v == 'primary': style += '19;stroke:#' + primary_color elif v == 'primary': style += '19;stroke:#' + primary_color
@ -364,43 +346,40 @@ def draw_ways(show_missed_tags=False):
elif v == 'unclassified': style += '7' elif v == 'unclassified': style += '7'
elif v == 'residential': style += '6' elif v == 'residential': style += '6'
elif v == 'service': style += '5' elif v == 'service': style += '5'
else: elif v in ['footway', 'pedestrian']:
continue style += '1;stroke-dasharray:3,3;stroke-linecap:butt;stroke:#888888'
elif v == 'steps':
style += '5;stroke-dasharray:1,2;stroke-linecap:butt;stroke:#888888'
elif v == 'path':
style += '1;stroke-dasharray:5,5;stroke-linecap:butt;stroke:#888888'
style += ';' style += ';'
draw_path(way['nodes'], style) elif 'leisure' in tags:
for way in layer['b']:
floors = 0
text_y = 0
#if 'building:levels' in way['tags']:
#floors = float(way['tags']['building:levels'])
draw_path(way['nodes'], 'fill:#' + building_color + ';stroke:#' + building_border_color + ';opacity:1.0;')
c = line_center(way['nodes']) c = line_center(way['nodes'])
shapes, fill, processed = process.get_icon(way['tags'], scheme, '444444') if tags['leisure'] == 'playground':
draw_shapes(shapes, True, points, c.x, c.y, fill, show_missed_tags, way['tags'], processed)
icons_to_draw.append({'shapes': shapes, 'x': c.x, 'y': c.y, 'fill': fill, 'priority': 1})
for way in layer['le']:
c = line_center(way['nodes'])
if way['tags']['leisure'] == 'playground':
style = 'fill:#' + playground_color + ';opacity:0.2;' style = 'fill:#' + playground_color + ';opacity:0.2;'
draw_point_shape('toy_horse', c.x, c.y, '444444') draw_point_shape('toy_horse', c.x, c.y, '444444')
elif way['tags']['leisure'] == 'garden': elif tags['leisure'] == 'garden':
style = 'fill:#' + grass_color + ';' style = 'fill:#' + grass_color + ';'
elif way['tags']['leisure'] == 'pitch': elif tags['leisure'] == 'pitch':
style = 'fill:#' + playground_color + ';opacity:0.2;' style = 'fill:#' + playground_color + ';opacity:0.2;'
elif way['tags']['leisure'] == 'park': elif tags['leisure'] == 'park':
continue continue
else: else:
style = 'fill:#FF0000;opacity:0.2;' style = 'fill:#FF0000;opacity:0.2;'
draw_path(way['nodes'], style) elif 'barrier' in tags:
for way in layer['ba']: if tags['barrier'] == 'hedge':
if way['tags']['barrier'] == 'hedge':
style += 'fill:none;stroke:#' + wood_color + ';stroke-width:4;' style += 'fill:none;stroke:#' + wood_color + ';stroke-width:4;'
else: else:
style += 'fill:none;stroke:#000000;stroke-width:1;opacity:0.4;' style += 'fill:none;stroke:#000000;stroke-width:1;opacity:0.4;'
draw_path(way['nodes'], style) elif 'border' in tags:
for way in layer['bo']: style += 'fill:none;stroke:#FF0000;stroke-width:0.5;' + \
style += 'fill:none;stroke:#FF0000;stroke-width:0.5;stroke-dahsarray:10,20;' 'stroke-dahsarray:10,20;'
draw_path(way['nodes'], style) else:
continue
drawing['ways'].append({'kind': 'way', 'nodes': nodes, 'layer': layer,
'priority': 50, 'style': style})
# Nodes drawing # Nodes drawing
@ -426,7 +405,8 @@ def to_write(key):
return True return True
return False return False
def draw_shapes(shapes, overlap, points, x, y, fill, show_missed_tags, tags, processed): def draw_shapes(shapes, overlap, points, x, y, fill, show_missed_tags, tags,
processed):
text_y = 0 text_y = 0
xxx = -(len(shapes) - 1) * 8 xxx = -(len(shapes) - 1) * 8
@ -453,7 +433,7 @@ def draw_shapes(shapes, overlap, points, x, y, fill, show_missed_tags, tags, pro
point(k, tags[k], x, y, fill, text_y) point(k, tags[k], x, y, fill, text_y)
text_y += 10 text_y += 10
def draw_nodes(show_missed_tags=False, overlap=14, draw=True): def construct_nodes(drawing):
print 'Draw nodes...' print 'Draw nodes...'
start_time = datetime.datetime.now() start_time = datetime.datetime.now()
@ -489,19 +469,21 @@ def draw_nodes(show_missed_tags=False, overlap=14, draw=True):
draw_text(k + ': ' + tags[k], x, y + 18 + text_y, '444444') draw_text(k + ': ' + tags[k], x, y + 18 + text_y, '444444')
text_y += 10 text_y += 10
if show_missed_tags: #if show_missed_tags:
for k in tags: # for k in tags:
v = tags[k] # v = tags[k]
if not no_draw(k) and not k in processed: # if not no_draw(k) and not k in processed:
if ('node ' + k + ': ' + v) in missed_tags: # if ('node ' + k + ': ' + v) in missed_tags:
missed_tags['node ' + k + ': ' + v] += 1 # missed_tags['node ' + k + ': ' + v] += 1
else: # else:
missed_tags['node ' + k + ': ' + v] = 1 # missed_tags['node ' + k + ': ' + v] = 1
if not draw: if not draw:
continue continue
draw_shapes(shapes, overlap, points, x, y, fill, show_missed_tags, tags, processed) drawing['nodes'].append({'shapes': shapes,
'x': x, 'y': y, 'color': fill, 'processed': processed,
'tags': tags})
ui.write_line(-1, len(node_map)) ui.write_line(-1, len(node_map))
print 'Nodes drawed in ' + str(datetime.datetime.now() - start_time) + '.' print 'Nodes drawed in ' + str(datetime.datetime.now() - start_time) + '.'
@ -509,6 +491,27 @@ def draw_nodes(show_missed_tags=False, overlap=14, draw=True):
str(skipped_tags) + ' (' + \ str(skipped_tags) + ' (' + \
str(processed_tags / float(processed_tags + skipped_tags) * 100) + ' %).' str(processed_tags / float(processed_tags + skipped_tags) * 100) + ' %).'
def way_sorter(element):
if 'layer' in element:
return element['layer']
else:
return 0
def node_sorter(element):
if 'layer' in element:
return element['layer']
else:
return 0
def draw(drawing, show_missed_tags=False, overlap=14, draw=True):
ways = sorted(drawing['ways'], key=way_sorter)
for way in ways:
draw_path(way['nodes'], way['style'])
nodes = sorted(drawing['nodes'], key=node_sorter)
for node in nodes:
draw_shapes(node['shapes'], overlap, points, node['x'], node['y'],
node['color'], show_missed_tags, node['tags'], node['processed'])
# Actions # Actions
options = ui.parse_options(sys.argv) options = ui.parse_options(sys.argv)
@ -563,14 +566,16 @@ else:
flinger = GeoFlinger(minimum, maximum, Vector(25, 25), Vector(975, 975)) flinger = GeoFlinger(minimum, maximum, Vector(25, 25), Vector(975, 975))
print 'Done.' print 'Done.'
if options['draw_ways']:
layers = construct_layers()
icons = extract_icon.IconExtractor(icons_file_name) icons = extract_icon.IconExtractor(icons_file_name)
drawing = {'nodes': [], 'ways': []}
if options['draw_ways']: if options['draw_ways']:
draw_ways(show_missed_tags=options['show_missed_tags']) construct_ways(drawing)
draw_nodes(show_missed_tags=options['show_missed_tags'],
construct_nodes(drawing)
draw(drawing, show_missed_tags=options['show_missed_tags'],
overlap=options['overlap'], draw=options['draw_nodes']) overlap=options['overlap'], draw=options['draw_nodes'])
if flinger.space.x == 0: if flinger.space.x == 0:

View file

@ -24,8 +24,8 @@
borderopacity="1.0" borderopacity="1.0"
inkscape:pageopacity="0.0" inkscape:pageopacity="0.0"
inkscape:pageshadow="2" inkscape:pageshadow="2"
inkscape:zoom="45.254834" inkscape:zoom="16"
inkscape:cx="231.13126" inkscape:cx="191.13126"
inkscape:cy="368.67156" inkscape:cy="368.67156"
inkscape:current-layer="layer1" inkscape:current-layer="layer1"
inkscape:document-units="px" inkscape:document-units="px"
@ -5314,7 +5314,7 @@
<path <path
style="fill:#d40000;fill-opacity:1;stroke:none" style="fill:#d40000;fill-opacity:1;stroke:none"
d="M 179 227 L 179 238 L 189 238 L 189 227 L 179 227 z M 181 228 C 181.55228 228 182 228.44772 182 229 C 182 229.31044 181.84698 229.56658 181.625 229.75 C 181.94473 230.76178 182.87876 231.5 184 231.5 C 185.12124 231.5 186.05527 230.76178 186.375 229.75 C 186.15302 229.56658 186 229.31044 186 229 C 186 228.44772 186.44772 228 187 228 C 187.55228 228 188 228.44772 188 229 C 188 229.41421 187.73391 229.75444 187.375 229.90625 C 186.97709 231.40165 185.61736 232.5 184 232.5 C 182.38264 232.5 181.02291 231.40165 180.625 229.90625 C 180.26609 229.75444 180 229.41421 180 229 C 180 228.44772 180.44772 228 181 228 z " d="M 179 227 L 179 238 L 189 238 L 189 227 L 179 227 z M 181 228 C 181.55228 228 182 228.44772 182 229 C 182 229.31044 181.84698 229.56658 181.625 229.75 C 181.94473 230.76178 182.87876 231.5 184 231.5 C 185.12124 231.5 186.05527 230.76178 186.375 229.75 C 186.15302 229.56658 186 229.31044 186 229 C 186 228.44772 186.44772 228 187 228 C 187.55228 228 188 228.44772 188 229 C 188 229.41421 187.73391 229.75444 187.375 229.90625 C 186.97709 231.40165 185.61736 232.5 184 232.5 C 182.38264 232.5 181.02291 231.40165 180.625 229.90625 C 180.26609 229.75444 180 229.41421 180 229 C 180 228.44772 180.44772 228 181 228 z "
id="bag" id="bag_2"
inkscape:label="#rect4569" /> inkscape:label="#rect4569" />
<rect <rect
ry="0" ry="0"
@ -5348,7 +5348,8 @@
<path <path
style="fill:#000000;fill-opacity:1;stroke:none" style="fill:#000000;fill-opacity:1;stroke:none"
d="M 195 227 L 195 238 L 205 238 L 205 227 L 195 227 z M 197.5 228.5 C 198.05228 228.5 198.5 228.94772 198.5 229.5 C 198.5 229.86497 198.292 230.16914 198 230.34375 L 198 232 C 198 232.55821 198.44179 233 199 233 L 201 233 C 201.55821 233 202 232.55821 202 232 L 202 230.34375 C 201.708 230.16914 201.5 229.86497 201.5 229.5 C 201.5 228.94772 201.94772 228.5 202.5 228.5 C 203.05228 228.5 203.5 228.94772 203.5 229.5 C 203.5 229.86497 203.292 230.16914 203 230.34375 L 203 232 C 203 233.09865 202.09865 234 201 234 L 199 234 C 197.90135 234 197 233.09865 197 232 L 197 230.34375 C 196.708 230.16914 196.5 229.86497 196.5 229.5 C 196.5 228.94772 196.94772 228.5 197.5 228.5 z " d="M 195 227 L 195 238 L 205 238 L 205 227 L 195 227 z M 197.5 228.5 C 198.05228 228.5 198.5 228.94772 198.5 229.5 C 198.5 229.86497 198.292 230.16914 198 230.34375 L 198 232 C 198 232.55821 198.44179 233 199 233 L 201 233 C 201.55821 233 202 232.55821 202 232 L 202 230.34375 C 201.708 230.16914 201.5 229.86497 201.5 229.5 C 201.5 228.94772 201.94772 228.5 202.5 228.5 C 203.05228 228.5 203.5 228.94772 203.5 229.5 C 203.5 229.86497 203.292 230.16914 203 230.34375 L 203 232 C 203 233.09865 202.09865 234 201 234 L 199 234 C 197.90135 234 197 233.09865 197 232 L 197 230.34375 C 196.708 230.16914 196.5 229.86497 196.5 229.5 C 196.5 228.94772 196.94772 228.5 197.5 228.5 z "
id="rect4610" /> id="bag"
inkscape:label="#rect4610" />
<path <path
style="fill:none;stroke:#d4aa00;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1" style="fill:none;stroke:#d4aa00;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1"
d="m 197.5,214 0,2 0,0 c 0,0.82843 0.67157,1.5 1.5,1.5 l 2,0 c 0.82843,0 1.5,-0.67157 1.5,-1.5 l 0,0 0,-2" d="m 197.5,214 0,2 0,0 c 0,0.82843 0.67157,1.5 1.5,1.5 l 2,0 c 0.82843,0 1.5,-0.67157 1.5,-1.5 l 0,0 0,-2"

Before

Width:  |  Height:  |  Size: 276 KiB

After

Width:  |  Height:  |  Size: 276 KiB

Before After
Before After