More tags and icons.

This commit is contained in:
Sergey Vartanov 2015-07-29 12:52:45 +03:00
parent efe3fcfba8
commit 4c01cded68
3 changed files with 1112 additions and 205 deletions

929
icons.svg

File diff suppressed because it is too large Load diff

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 83 KiB

Before After
Before After

384
mapper.py
View file

@ -41,7 +41,7 @@ output_file = svg.SVG(open(sys.argv[2], 'w+'))
w, h = 2000, 2000
background_color = '000000' # 'EEEEEE'
background_color = 'EEEEEE'
grass_color = 'C8DC94'
sand_color = 'F0E0D0'
beach_color = 'F0E0C0'
@ -54,11 +54,17 @@ wood_color = 'B8CC84'
tags_to_write = ['operator', 'opening_hours', 'cuisine', 'network', 'website',
'phone', 'branch', 'route_ref', 'brand', 'ref', 'wikipedia',
'description', 'level', 'wikidata', 'name']
'description', 'level', 'wikidata', 'name', 'alt_name',
'image', 'fax', 'old_name', 'artist_name', 'int_name',
'official_name', 'full_name', 'email', 'designation']
prefix_to_write = ['addr', 'contact', 'name', 'operator', 'wikipedia']
prefix_to_write = ['addr', 'contact', 'name', 'operator', 'wikipedia',
'alt_name', 'description', 'old_name', 'inscription',
'route_ref', 'is_in', 'website']
tags_to_skip = ['note', 'layer']
tags_to_skip = ['note', 'layer', 'source', 'building:part', 'fixme', 'comment']
prefix_to_skip = ['source']
output_file.begin(w, h)
output_file.rect(0, 0, w, h, color=background_color)
@ -147,16 +153,23 @@ def draw_path(nodes, style, shift=Vector()):
def draw_point_shape(name, x, y, fill):
if not isinstance(name, list):
name = [name]
for one_name in name:
shape, xx, yy = get_d_from_file(one_name)
draw_point_outline(shape, x, y, fill, size=16, xx=xx, yy=yy)
for one_name in name:
shape, xx, yy = get_d_from_file(one_name)
draw_point(shape, x, y, fill, size=16, xx=xx, yy=yy)
def draw_point(shape, x, y, fill, size=16, xx=0, yy=0):
def draw_point_outline(shape, x, y, fill, size=16, xx=0, yy=0):
x = int(float(x))
y = int(float(y))
output_file.write('<path d="' + shape + \
'" style="fill:#FFFFFF;opacity:0.5;stroke:#FFFFFF;stroke-width:3;stroke-linejoin:round;" transform="translate(' + \
str(x - size / 2.0 - xx * 16) + ',' + str(y - size / 2.0 - yy * 16) + ')" />\n')
def draw_point(shape, x, y, fill, size=16, xx=0, yy=0):
x = int(float(x))
y = int(float(y))
output_file.write('<path d="' + shape + \
'" style="fill:#' + fill + ';fill-opacity:1" transform="translate(' + \
str(x - size / 2.0 - xx * 16) + ',' + str(y - size / 2.0 - yy * 16) + ')" />\n')
@ -168,10 +181,9 @@ def draw_text(text, x, y, fill):
if text[:7] == 'http://' or text[:8] == 'https://':
text = 'link'
fill = '0000FF'
return
output_file.write('<text x="' + x + '" y="' + y + \
output_file.write('<text x="' + str(x) + '" y="' + str(y) + \
'" style="font-size:10;text-anchor:middle;font-family:Myriad Pro;fill:#FFFFFF;stroke-linejoin:round;stroke-width:5;stroke:#FFFFFF;opacity:0.5;">' + text + '</text>')
output_file.write('<text x="' + x + '" y="' + y + \
output_file.write('<text x="' + str(x) + '" y="' + str(y) + \
'" style="font-size:10;text-anchor:middle;font-family:Myriad Pro;fill:#' + fill + ';">' + text + '</text>')
def point(k, v, x, y, fill, text_y):
@ -179,12 +191,10 @@ def point(k, v, x, y, fill, text_y):
missed_tags['node ' + k + ': ' + v] += 1
else:
missed_tags['node ' + k + ': ' + v] = 1
#output_file.circle(float(x), float(y), 2, fill=fill, color=fill)
text = k + ': ' + v
if type(text) == unicode:
text = text.encode('utf-8')
output_file.write('<text x="' + str(x) + '" y="' + str(int(float(y)) + text_y + 10) + \
'" style="font-size:10;text-anchor:middle;font-family:Myriad Pro;fill:#FF0000;">' + text + '</text>')
draw_text(text, x, float(y) + text_y + 18, '734A08')
# Ways drawing
@ -201,7 +211,7 @@ def construct_layers():
if not (int(way['tags']['layer']) in layers):
layers[int(way['tags']['layer'])] = \
{'b': [], 'h1': [], 'h2': [], 'r': [], 'n': [], 'l': [],
'a': [], 'le': [], 'ba': [], 'bo': []}
'a': [], 'le': [], 'ba': [], 'bo': [], 'w': []}
layer = layers[int(way['tags']['layer'])]
if 'building' in way['tags']:
layer['b'].append(way)
@ -222,6 +232,8 @@ def construct_layers():
layer['h2'].append(way)
if 'boundary' in way['tags']:
layer['bo'].append(way)
if 'waterway' in way['tags']:
layer['w'].append(way)
#else:
# empty = True
# for key in way['tags'].keys():
@ -289,10 +301,10 @@ def draw_ways():
else:
style = 'fill:#0000FF;stroke:none;'
draw_path(way['nodes'], style)
for tag in way['tags']:
if not (tag in ['landuse', 'layer']):
point(tag, str(way['tags'][tag]), c.x, c.y, '000000', text_y)
text_y += 10
#for tag in way['tags']:
# if not (tag in ['landuse', 'layer']):
# point(tag, str(way['tags'][tag]), c.x, c.y, '000000', text_y)
# text_y += 10
for way in layer['a']:
c = line_center(way['nodes'])
if way['tags']['amenity'] == 'parking':
@ -322,6 +334,12 @@ def draw_ways():
else:
continue
draw_path(way['nodes'], style)
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;'
draw_path(way['nodes'], style)
for way in layer['r']:
v = way['tags']['railway']
style = 'fill:none;stroke-dasharray:none;stroke-linejoin:round;stroke-linecap:round;stroke-width:'
@ -348,7 +366,7 @@ def draw_ways():
elif v == 'service': style += '7'
elif v == 'track': style += '3'
elif v in ['footway', 'pedestrian']: style += '2'
elif v == 'steps': style += '5;stroke-dasharray:1,2;stroke-linecap:round'
elif v == 'steps': style += '5;stroke-dasharray:1,2;stroke-linecap:butt'
elif v == 'path': style += '1;stroke-dasharray:5,5;stroke-linecap:round'
else:
continue
@ -401,18 +419,18 @@ def draw_ways():
draw_point_shape('shop_gift', c.x, c.y, '444444')
elif tag == 'power':
draw_point_shape('electricity', c.x, c.y, '444444')
elif tag in ['name', 'addr:housenumber', 'cladr:code',
'addr:city', 'addr:street', 'website',
'wikidata'] or \
'name' in tag or 'wikipedia' in tag:
draw_text(v, str(c.x), str(c.y + 18 + text_y), '444444')
text_y += 10
elif tag == 'addr:country':
if v == 'RU':
draw_text('Россия', str(c.x), str(c.y + 18 + text_y), '444444')
else:
draw_text(v, str(c.x), str(c.y + 18 + text_y), '444444')
text_y += 10
#elif tag in ['name', 'addr:housenumber', 'cladr:code',
# 'addr:city', 'addr:street', 'website',
# 'wikidata'] or \
# 'name' in tag or 'wikipedia' in tag:
# draw_text(v, str(c.x), str(c.y + 18 + text_y), '444444')
# text_y += 10
#elif tag == 'addr:country':
# if v == 'RU':
# draw_text('Россия', str(c.x), str(c.y + 18 + text_y), '444444')
# else:
# draw_text(v, str(c.x), str(c.y + 18 + text_y), '444444')
# text_y += 10
elif tag in ['layer', 'height']:
pass
elif tag in ['building:levels']:
@ -461,6 +479,14 @@ def draw_raw_nodes():
def no_draw(key):
if key in tags_to_write or key in tags_to_skip:
return True
for prefix in prefix_to_write + prefix_to_skip:
if key[:len(prefix) + 1] == prefix + ':':
return True
return False
def to_write(key):
if key in tags_to_write:
return True
for prefix in prefix_to_write:
if key[:len(prefix) + 1] == prefix + ':':
return True
@ -472,29 +498,47 @@ def draw_nodes():
for node_id in node_map:
node = node_map[node_id]
flinged = flinger.fling(Geo(node['lat'], node['lon']))
x = `flinged.x`
y = `flinged.y`
x = flinged.x
y = flinged.y
text_y = 0
if 'tags' in node:
p = node['tags']
else:
p = {}
fill = '444444'
if 'colour' in p:
if p['colour'] == 'blue':
processed = set([])
if 'colour' in p or 'color' in p:
k = 'color' if 'color' in p else 'colour'
v = p[k]
processed.add(k)
if v == 'blue':
fill='2233AA'
radius=3
elif v == 'lightblue':
fill='2288CC'
elif v == 'red':
fill='CC0000'
elif v == 'violet':
fill='75507B'
elif v == 'green':
fill='4E9A06'
elif v == 'yellow':
fill='EDD400'
else:
processed.remove(k)
shapes = []
if p == {}:
pass
elif 'amenity' in p:
k = 'amenity'
v = p['amenity']
processed = set([k])
processed.add(k)
if v in ['bench', 'bicycle_parking', 'cafe', 'waste_basket',
'clinic', 'restaurant', 'pharmacy', 'drinking_water',
'toilets', 'theatre', 'bar', 'bank', 'pub', 'post_office']:
draw_point_shape(v, x, y, fill)
shapes.append(v)
elif v == 'fast_food':
shape = 'fast_food'
if 'operator' in p:
@ -505,177 +549,190 @@ def draw_nodes():
if p['operator:en'] == "McDonald's":
shape = 'mcdonalds'
processed.add('operator:en')
draw_point_shape(shape, x, y, fill)
shapes.append(shape)
elif v == 'shop':
if 'shop' in p:
if p['shop'] in ['fishing']:
draw_point_shape('shop_' + p['shop'], x, y, fill)
elif v == 'fountain':
draw_point_shape('fountain', x, y, water_border_color)
shapes.append('fountain')
fill = water_border_color
elif v == 'recycling':
if not 'recycling_type' in p:
draw_point_shape('recycling', x, y, fill)
shapes.append('recycling')
else:
processed.remove(k)
for k in p:
if 'karaoke' in p:
if p['karaoke'] == 'yes':
draw_point_shape('microphone', flinged.x + 16, y, fill)
else:
point(k, p[k], x, y, fill, text_y)
elif not no_draw(k) and not (k in processed):
point(k, p[k], x, y, fill, text_y)
text_y += 10
if 'karaoke' in p and p['karaoke'] == 'yes':
draw_point_shape('microphone', flinged.x + 16, y, fill)
processed.add('karaoke')
elif 'building' in p:
k = 'building'
v = p['building']
for k in p:
if 'roof:material' in p and p['roof:material'] == 'metal':
draw_point_shape('metal_roof', flinged.x + 16, y, fill)
processed.add('roof:material')
elif 'railway' in p:
k = 'railway'
v = p['railway']
processed.add(k)
if v == 'subway_entrance':
shapes.append('train')
else:
processed.remove(k)
for k in p:
if 'roof:material' in p and p['roof:material'] == 'metal':
draw_point_shape('metal_roof', flinged.x + 16, y, fill)
processed.add('roof:material')
elif 'natural' in p:
k = 'natural'
v = p['natural']
processed = set([k])
processed.add(k)
if v == 'tree':
shape = 'tree'
if 'leaf_type' in p and p['leaf_type'] in ['broadleaved', 'needleleaved']:
shape = p['leaf_type']
processed.add(p['leaf_type'])
if 'denotation' in p and p['denotation'] == 'urban':
draw_point_shape([shape, 'urban_tree_pot'], x, y, wood_color)
processed.add('denotation')
processed.add('leaf_type')
if 'type' in p and p['type'] == 'conifer':
shape = 'needleleaved'
processed.add('type')
if 'denotation' in p:
if p['denotation'] == 'urban':
draw_point_shape([shape, 'urban_tree_pot'], x, y, wood_color)
processed.add('denotation')
elif p['denotation'] == 'avenue':
draw_point_shape([shape, 'avenue_tree'], x, y, wood_color)
processed.add('denotation')
elif v == 'cave_entrance':
draw_point_shape('cave', x, y, fill)
shapes.append('cave')
elif v == 'bush':
draw_point_shape('bush', x, y, wood_color)
shapes.append('bush')
fill = wood_color
else:
processed.remove(k)
for k in p:
if not no_draw(k) and not (k in processed):
point(k, p[k], x, y, fill, text_y)
text_y += 10
elif 'entrance' in p:
k = 'entrance'
v = p['entrance']
processed = set([k])
processed.add(k)
if v == 'yes':
draw_point_shape('entrance', x, y, fill)
shapes.append('entrance')
elif v == 'main':
shapes.append('main_entrance')
elif v == 'staircase':
draw_point_shape('staircase', x, y, fill)
shapes.append('staircase')
else:
processed.remove(k)
for k in p:
if not no_draw(k) and not (k in processed):
point(k, p[k], x, y, fill, text_y)
text_y += 10
elif 'highway' in p:
k = 'highway'
v = p['highway']
processed = set([k])
processed.add(k)
if v == 'crossing':
shape = 'crossing'
if 'crossing' in p:
if p['crossing'] == 'zebra':
shape = 'zebra'
processed.add('crossing')
elif p['crossing'] == 'uncontrolled':
draw_point_shape('no_traffic_signals', x + 16, y, fill)
processed.add('crossing')
elif p['crossing'] == 'traffic_signals':
draw_point_shape('traffic_signals', x + 16, y, fill)
processed.add('crossing')
elif 'crossing_ref' in p:
if p['crossing_ref'] == 'zebra':
shape = 'zebra'
draw_point_shape(shape, x, y, fill)
processed.add('crossing_ref')
shapes.append(shape)
elif v == 'traffic_signals':
shapes.append('traffic_signals')
elif v == 'street_lamp':
draw_point_shape('street_lamp', x, y, fill)
shapes.append('street_lamp')
else:
processed.remove(k)
for k in p:
if not no_draw(k) and not (k in processed):
point(k, p[k], x, y, fill, text_y)
text_y += 10
else:
for k in p:
if not no_draw(k):
point(k, p[k], x, y, fill, text_y)
text_y += 10
for k in []:
v = p[k]
if k == 'amenity':
if v in ['bench', 'bicycle_parking', 'cafe', 'waste_basket',
'restaurant', 'pharmacy', 'drinking_water', 'toilets',
'fast_food', 'theatre']:
draw_point_shape(v, x, y, fill)
elif k == 'artwork_type':
if v == 'statue':
draw_point_shape('monument', x, y, fill)
if v == 'sculpture':
draw_point_shape('monument', x, y, fill)
else:
point(k, v, flinged.x, flinged.y, fill, text_y)
text_y += 10
elif k == 'barrier':
if v == 'lift_gate':
draw_point_shape('liftgate', x, y, fill)
elif k in ['crossing', 'crossing_ref']:
if v == 'zebra':
draw_point_shape('crossing', x, y, fill)
elif k == 'entrance':
draw_point_shape('entrance', x, y, fill)
elif k == 'highway':
if v == 'street_lamp':
draw_point_shape('street_lamp', x, y, fill)
elif v == 'bus_stop':
draw_point_shape('bus_stop', x, y, fill)
elif v == 'traffic_signals':
draw_point_shape('traffic_signal', x, y, fill)
elif v == 'crossing':
if not ('crossing' in p):
draw_point_shape('crossing', x, y, fill)
else:
point(k, v, flinged.x, flinged.y, fill, text_y)
text_y += 10
elif k == 'man_made':
if v == 'pole':
draw_point_shape('pole', x, y, fill)
elif v == 'flagpole':
draw_point_shape('flagpole', x, y, fill)
else:
point(k, v, flinged.x, flinged.y, fill, text_y)
text_y += 10
elif k == 'recycling_type':
if v == 'centre':
draw_point_shape('recycling', x, y, fill)
else:
draw_point_shape('recycling', x, y, fill)
elif k == 'shop':
if v == 'florist':
draw_point_shape('florist', x, y, fill)
elif v in ['clothes', 'shoes', 'gift']:
draw_point_shape('shop_' + v, x, y, fill)
else:
point(k, v, flinged.x, flinged.y, fill, text_y)
text_y += 10
elif k == 'traffic_calming':
if v == 'bump':
draw_point_shape('bump', x, y, fill)
else:
point(k, v, flinged.x, flinged.y, fill, text_y)
text_y += 10
elif k == 'emergency':
if v == 'fire_hydrant':
draw_point_shape(v, x, y, fill)
elif k == 'historic':
if v == 'memorial':
draw_point_shape('monument', x, y, fill)
elif k == 'tourism':
if v == 'artwork':
if not ('artwork_type' in p):
draw_point_shape('monument', x, y, fill)
if v == 'attraction':
draw_point_shape('monument', x, y, fill)
elif k in undraw or ('name' in k):
if k == 'route_ref':
v = v.replace(';', ' ')
draw_text(v, x, str(flinged.y + 18 + text_y), fill)
text_y += 10
elif k in ['layer', 'level', 'source', 'note', 'description']:
pass # NOTHING TO DRAW
elif 'historic' in p:
k = 'historic'
v = p['historic']
processed.add(k)
if v == 'memorial':
shape = v
if v in p:
if p[v] == 'statue':
shape = p[v]
processed.add(v)
elif p[v] == 'plaque':
shape = p[v]
processed.add(v)
shapes.append(shape)
elif v == 'tomb':
shape = v
if v in p:
if p[v] == 'mausoleum':
shape = p[v]
processed.add(v)
shapes.append(shape)
else:
point(k, v, flinged.x, flinged.y, fill, text_y)
processed.remove(k)
elif 'barrier' in p:
k = 'barrier'
v = p['barrier']
processed.add(k)
if v == 'gate':
shapes.append('gate')
elif v == 'lift_gate':
shapes.append('lift_gate')
elif v == 'turnstile':
shapes.append('turnstile')
else:
processed.remove(k)
elif 'man_made' in p:
k = 'man_made'
v = p['man_made']
processed.add(k)
if v == 'pole':
shapes.append('pole')
elif v == 'flagpole':
shapes.append('flagpole')
else:
processed.remove(k)
elif 'tourism' in p:
k = 'tourism'
v = p['tourism']
processed.add(k)
if v == 'attraction':
shape = v
if v in p:
if p[v] == 'amusement_ride':
shape = p[v]
processed.add(v)
shapes.append(shape)
else:
processed.remove(k)
for k in []: # p:
if to_write(k):
draw_text(k + ': ' + p[k], x, y + 18 + text_y, '444444')
text_y += 10
for k in p:
if k == 'foot' and p[k] == 'yes':
shapes.append('foot')
processed.add(k)
elif k == 'bicycle' and p[k] == 'yes':
shapes.append('bicycle')
processed.add(k)
elif k == 'internet_access' and p[k] == 'wlan':
shapes.append('wlan')
processed.add(k)
elif not no_draw(k) and not k in processed:
point(k, p[k], x, y, fill, text_y)
text_y += 10
xxx = -(len(shapes) - 1) * 8
for shape in shapes:
draw_point_shape(shape, x + xxx, y, fill)
xxx += 16
print 'Done.'
#draw_raw_nodes()
@ -699,7 +756,8 @@ output_file.end()
print '\nMissing tags:\n'
top_missed_tags = reversed(sorted(missed_tags.keys(), key=lambda x: -missed_tags[x]))
for tag in top_missed_tags:
print tag + ' (' + str(missed_tags[tag]) + ')'
if tag[:4] == 'node':
print tag + ' (' + str(missed_tags[tag]) + ')'
sys.exit(0)

View file

@ -125,12 +125,12 @@ def parse_osm_file(file_name, silent=False):
elif line[:5] in [' <way', '\t<way']:
if line[-3] == '/':
way = parse_way(line[6:-3])
node_map[node['id']] = node
way_map[node['id']] = way
else:
element = parse_way(line[6:-2])
element['tags'] = {}
element['nodes'] = []
elif line == [' </way>\n', '\t</way>\n']:
elif line in [' </way>\n', '\t</way>\n']:
way_map[element['id']] = element
# Relation parsing.