Esempio n. 1
0
def construct_nodes(drawing):
    """
    Draw nodes.
    """
    print 'Draw nodes...'

    start_time = datetime.now()

    node_number = 0
    processed_tags = 0
    skipped_tags = 0

    s = sorted(node_map.keys(), key=lambda x: -node_map[x]['lat'])

    for node_id in s:
        node_number += 1
        ui.write_line(node_number, len(node_map))
        node = node_map[node_id]
        flinged = flinger.fling(Geo(node['lat'], node['lon']))
        x = flinged.x
        y = flinged.y
        if 'tags' in node:
            tags = node['tags']
        else:
            tags = {}

        if not (options.level is None):
            if 'level' in tags:
                levels = map(lambda x:float(x), tags['level'].replace(',', '.').split(';'))
                if not options.level in levels:
                    continue
            else:
                continue

        shapes, fill, processed = process.get_icon(tags, scheme)

        if options.mode == 'user-coloring':
            fill = get_user_color(node['user'])
        if options.mode == 'time':
            fill = get_time_color(node['timestamp'])

        for k in tags:
            if k in processed or no_draw(k):
                processed_tags += 1
            else:
                skipped_tags += 1

        for k in []:  # tags:
            if to_write(k):
                draw_text(k + ': ' + tags[k], x, y + 18 + text_y, '444444')
                text_y += 10

        #if show_missed_tags:
        #    for k in tags:
        #        v = tags[k]
        #        if not no_draw(k) and not k in processed:
        #            if ('node ' + k + ': ' + v) in missed_tags:
        #                missed_tags['node ' + k + ': ' + v] += 1
        #            else:
        #                missed_tags['node ' + k + ': ' + v] = 1

        if not draw:
            continue

        if shapes == [] and tags != {}:
            shapes = [['circle']]

        drawing['nodes'].append({'shapes': shapes, 
            'x': x, 'y': y, 'color': fill, 'processed': processed, 
            'tags': tags})

    ui.write_line(-1, len(node_map))
    print 'Nodes drawed in ' + str(datetime.now() - start_time) + '.'
    print 'Tags processed: ' + str(processed_tags) + ', tags skipped: ' + \
        str(skipped_tags) + ' (' + \
        str(processed_tags / float(processed_tags + skipped_tags) * 100) + ' %).'
Esempio n. 2
0
def construct_way(drawing, nodes, tags, path, user, time):
    """
    Way construction.

    Params:
        :param drawing: structure for drawing elements.
        :param nodes: way node list.
        :param tags: way tag dictionary.
        :param path: way path (if there is no nodes).
        :param user: author name.
        :param user: way update time.
    """
    layer = 0
    level = 0

    if 'layer' in tags:
        layer = get_float(tags['layer'])
    if 'level' in tags:
        levels = map(lambda x:float(x), tags['level'].split(';'))
        level = sum(levels) / len(levels)

    layer = 100 * level + 0.01 * layer

    if nodes:
        c = line_center(nodes)

    if options.mode == 'user-coloring':
        user_color = get_user_color(user)
        drawing['ways'].append({'kind': 'way', 'nodes': nodes, 'path': path,
            'style': 'fill:none;stroke:#' + user_color + ';stroke-width:1;'})
        return

    if options.mode == 'time':
        if not time:
            return
        time_color = get_time_color(time)
        drawing['ways'].append({'kind': 'way', 'nodes': nodes, 'path': path,
            'style': 'fill:none;stroke:#' + time_color + ';stroke-width:1;'})
        return

    # Indoor features

    if 'indoor' in tags:
        v = tags['indoor']
        style = 'stroke:' + indoor_border_color + ';stroke-width:1;'
        if v == 'area':
            style += 'fill:#' + indoor_color + ';'
            layer += 10
        elif v == 'corridor':
            style += 'fill:#' + indoor_color + ';'
            layer += 11
        elif v in ['yes', 'room', 'elevator']:
            style += 'fill:#' + indoor_color + ';'
            layer += 12
        elif v == 'column':
            style += 'fill:#' + indoor_border_color + ';'
            layer += 13
        drawing['ways'].append({'kind': 'way', 'nodes': nodes, 'layer': layer,
            'priority': 50, 'style': style, 'path': path})

    # Natural

    if 'natural' in tags:
        v = tags['natural']
        style = 'stroke:none;'
        if v == 'wood':
            style += 'fill:#' + wood_color + ';'
            layer += 21
        elif v == 'scrub':
            style += 'fill:#' + wood_color + ';'
            layer += 21
        elif v == 'sand':
            style += 'fill:#' + sand_color + ';'
            layer += 20
        elif v == 'beach':
            style += 'fill:#' + beach_color + ';'
            layer += 20
        elif v == 'desert':
            style += 'fill:#' + desert_color + ';'
            layer += 20
        elif v == 'forest':
            style += 'fill:#' + wood_color + ';'
            layer += 21
        elif v == 'tree_row':
            style += 'fill:none;stroke:#' + wood_color + ';stroke-width:5;'
            layer += 21
        elif v == 'water':
            style = 'fill:#' + water_color + ';stroke:#' + \
                water_border_color + ';stroke-width:1.0;'
            layer += 21
        drawing['ways'].append({'kind': 'way', 'nodes': nodes, 'layer': layer,
            'priority': 50, 'style': style, 'path': path})

    # Landuse

    if 'landuse' in tags:
        style = 'fill:none;stroke:none;'
        if tags['landuse'] == 'grass':
            style = 'fill:#' + grass_color + ';stroke:#' + grass_border_color + ';'
            layer += 20
        elif tags['landuse'] == 'conservation':
            style = 'fill:#' + grass_color + ';stroke:none;'
            layer += 20
        elif tags['landuse'] == 'forest':
            style = 'fill:#' + wood_color + ';stroke:none;'
            layer += 20
        elif tags['landuse'] == 'garages':
            style = 'fill:#' + parking_color + ';stroke:none;'
            layer += 21
            shapes, fill, processed = \
                process.get_icon(tags, scheme, '444444')
            if nodes:
                drawing['nodes'].append({'shapes': shapes, 'tags': tags,
                    'x': c.x, 'y': c.y, 'color': fill, 'path': path,
                    'processed': processed})
        elif tags['landuse'] == 'construction':
            layer += 20
            style = 'fill:#' + construction_color + ';stroke:none;'
        elif tags['landuse'] in ['residential', 'commercial']:
            return
        drawing['ways'].append({'kind': 'way', 'nodes': nodes, 'layer': layer,
            'priority': 50, 'style': style, 'path': path})
    
    # Building

    if 'building' in tags:
        style = 'fill:none;stroke:none;'
        text_y = 0
        layer += 40
        levels = 1
        if 'building:levels' in tags:
            levels = float(tags['building:levels'])
        style = 'fill:#' + building_color + ';stroke:#' + \
            building_border_color + ';opacity:1.0;'
        shapes, fill, processed = process.get_icon(tags, scheme, '444444')
        if 'height' in tags:
            layer += float(tags['height'])
        if nodes:
            drawing['nodes'].append({'shapes': shapes, 'x': c.x, 'y': c.y, 
                'color': fill, 'priority': 1, 'processed': processed, 
                'tags': tags, 'path': path})
        drawing['ways'].append({'kind': 'building', 'nodes': nodes, 
            'layer': layer, 'priority': 50, 'style': style, 'path': path, 
            'levels': levels})

    # Amenity

    if 'amenity' in tags:
        style = 'fill:none;stroke:none;'
        layer += 21
        if tags['amenity'] == 'parking':
            style = 'fill:#' + parking_color + ';stroke:none;opacity:0.5;'
            shapes, fill, processed = process.get_icon(tags, scheme, '444444')
            if nodes:
                drawing['nodes'].append({'shapes': shapes, 'x': c.x, 'y': c.y, 
                    'color': fill, 'priority': 1, 'processed': processed, 
                    'tags': tags, 'path': path})
        drawing['ways'].append({'kind': 'way', 'nodes': nodes, 'layer': layer,
            'priority': 50, 'style': style, 'path': path})

    # Waterway

    if 'waterway' in tags:
        style = 'fill:none;stroke:none;'
        layer += 21
        if tags['waterway'] == 'riverbank':
            style = 'fill:#' + water_color + ';stroke:#' + \
                water_border_color + ';stroke-width:1.0;'
        elif tags['waterway'] == 'river':
            style = 'fill:none;stroke:#' + water_color + ';stroke-width:10.0;'
        drawing['ways'].append({'kind': 'way', 'nodes': nodes, 'layer': layer,
            'priority': 50, 'style': style, 'path': path})

    # Railway

    if 'railway' in tags:
        style = 'fill:none;stroke:none;'
        layer += 41
        v = tags['railway']
        style = 'fill:none;stroke-dasharray:none;stroke-linejoin:round;' + \
            'stroke-linecap:round;stroke-width:'
        if v == 'subway': style += '10;stroke:#DDDDDD;'
        if v in ['narrow_gauge', 'tram']: 
            style += '2;stroke:#000000;'
        if v == 'platform': 
            style = 'fill:#' + platform_color + ';stroke:#' + \
                platform_border_color + 'stroke-width:1;'
        else:
            return
        drawing['ways'].append({'kind': 'way', 'nodes': nodes, 'layer': layer,
            'priority': 50, 'style': style, 'path': path})

    # Highway

    if 'highway' in tags:
        style = 'fill:none;stroke:none;'
        layer += 42
        v = tags['highway']
        if False: #'tunnel' in tags and tags['tunnel'] == 'yes':
            style = 'fill:none;stroke:#FFFFFF;stroke-dasharray:none;' + \
                'stroke-linejoin:round;stroke-linecap:round;stroke-width:10;'
            drawing['ways'].append({'kind': 'way', 'nodes': nodes, 
                'layer': layer, 'priority': 50, 'style': style,
                'path': path})

        style = 'fill:none;stroke:#' + road_border_color + \
            ';stroke-dasharray:none;' + \
            'stroke-linejoin:round;stroke-linecap:round;stroke-width:'

        # Highway outline

        if v == 'motorway': style += '33'
        elif v == 'trunk': style += '31'
        elif v == 'primary': style += '29;stroke:#' + primary_border_color
        elif v == 'secondary': style += '27'
        elif v == 'tertiary': style += '25'
        elif v == 'unclassified': style += '17'
        elif v == 'residential': style += '17'
        elif v == 'service': 
            if 'service' in tags and tags['service'] == 'parking_aisle': 
                style += '7'
            else:
                style += '11'
        elif v == 'track': style += '3'
        elif v in ['footway', 'pedestrian', 'cycleway']: 
            if not ('area' in tags and tags['area'] == 'yes'):
                style += '3;stroke:#' + foot_border_color
        elif v in ['steps']: style += '6;stroke:#' + foot_border_color + ';stroke-linecap:butt;'
        else: style = None
        if style:
            style += ';'
            drawing['ways'].append({'kind': 'way', 'nodes': nodes, 
                'layer': layer + 41, 'priority': 50, 'style': style,
                'path': path})

        # Highway main shape

        style = 'fill:none;stroke:#FFFFFF;stroke-linecap:round;' + \
            'stroke-linejoin:round;stroke-width:'

        priority = 50

        if v == 'motorway': style += '31'
        elif v == 'trunk': style += '29'
        elif v == 'primary': style += '27;stroke:#' + primary_color
        elif v == 'secondary': style += '25'
        elif v == 'tertiary': style += '23'
        elif v == 'unclassified': style += '15'
        elif v == 'residential': style += '15'
        elif v == 'service': 
            if 'service' in tags and tags['service'] == 'parking_aisle': 
                style += '5'
            else:
                style += '9'
        elif v == 'cycleway': 
            style += '1;stroke-dasharray:8,2;istroke-linecap:butt;' + \
                'stroke:#' + cycle_color
        elif v in ['footway', 'pedestrian']:
            priority = 55
            if 'area' in tags and tags['area'] == 'yes':
                style += '1;stroke:none;fill:#DDDDDD'
                layer -= 55  # FIXME!
            else:
                style += '1.5;stroke-dasharray:7,3;stroke-linecap:round;' + \
                    'stroke:#'
                if 'guide_strips' in tags and tags['guide_strips'] == 'yes':
                    style += guide_strips_color
                else:
                    style += foot_color
        elif v == 'steps': 
            style += '5;stroke-dasharray:1.5,2;stroke-linecap:butt;' + \
                'stroke:#' 
            if 'conveying' in tags:
                style += '888888'
            else:
                style += foot_color
        elif v == 'path': 
            style += '1;stroke-dasharray:5,5;stroke-linecap:butt;' + \
                'stroke:#' + foot_color
        style += ';'
        drawing['ways'].append({'kind': 'way', 'nodes': nodes, 'layer': layer + 42,
            'priority': priority, 'style': style, 'path': path})
        if 'oneway' in tags and tags['oneway'] == 'yes' or \
            'conveying' in tags and tags['conveying'] == 'forward':
            for k in range(7):
                drawing['ways'].append({'kind': 'way', 'nodes': nodes, 'layer': layer + 43, 'priority': 50, 'path': path, 'style': 'fill:none;stroke:#222288;stroke-linecap:butt;stroke-width:' + str(7 - k) + ';stroke-dasharray:' + str(k) + ',' + str(40 - k) + ';'})
        if 'access' in tags and tags['access'] == 'private':
            drawing['ways'].append({'kind': 'way', 'nodes': nodes, 
                'layer': layer + 0.1, 'priority': 50, 'path': path,
                'style': 'fill:none;' + \
                        'stroke:#' + private_access_color + ';' + \
                        'stroke-linecap:butt;' + \
                        'stroke-width:10;stroke-dasharray:1,5;' + \
                        'opacity:0.4;'})
    # Leisure

    if 'leisure' in tags:
        style = 'fill:none;stroke:none;'
        layer += 21
        if tags['leisure'] == 'playground':
            style = 'fill:#' + playground_color + ';opacity:0.2;'
            if nodes:
                draw_point_shape('toy_horse', c.x, c.y, '444444')
        elif tags['leisure'] == 'garden':
            style = 'fill:#' + grass_color + ';'
        elif tags['leisure'] == 'pitch':
            style = 'fill:#' + playground_color + ';opacity:0.2;'
        elif tags['leisure'] == 'park':
            return 
        else:
            style = 'fill:#FF0000;opacity:0.2;'
        drawing['ways'].append({'kind': 'way', 'nodes': nodes, 'layer': layer,
            'priority': 50, 'style': style, 'path': path})

    # Barrier

    if 'barrier' in tags:
        style = 'fill:none;stroke:none;'
        layer += 40
        if tags['barrier'] == 'hedge':
            style += 'fill:none;stroke:#' + wood_color + ';stroke-width:4;'
        elif tags['barrier'] == 'fense':
            style += 'fill:none;stroke:#000000;stroke-width:1;opacity:0.4;'
        elif tags['barrier'] == 'kerb':
            style += 'fill:none;stroke:#000000;stroke-width:1;opacity:0.2;'
        else:
            style += 'fill:none;stroke:#000000;stroke-width:1;opacity:0.3;'
        drawing['ways'].append({'kind': 'way', 'nodes': nodes, 'layer': layer,
            'priority': 50, 'style': style, 'path': path})

    # Border

    if 'border' in tags:
        style = 'fill:none;stroke:none;'
        style += 'fill:none;stroke:#FF0000;stroke-width:0.5;' + \
            'stroke-dahsarray:10,20;'
        drawing['ways'].append({'kind': 'way', 'nodes': nodes, 'layer': layer,
            'priority': 50, 'style': style, 'path': path})
    if 'area:highway' in tags:
        style = 'fill:none;stroke:none;'
        if tags['area:highway'] == 'yes':
            style += 'fill:#FFFFFF;stroke:#DDDDDD;stroke-width:1;'
        drawing['ways'].append({'kind': 'way', 'nodes': nodes, 'layer': layer,
            'priority': 50, 'style': style, 'path': path})
    #drawing['ways'].append({'kind': 'way', 'nodes': nodes, 'layer': layer,
    #    'priority': 50, 'style': style, 'path': path})
    if False:
        if 'highway' in tags and tags['highway'] != 'steps' and not ('surface' in tags):
            drawing['ways'].append({'kind': 'way', 'nodes': nodes, 
                'layer': layer + 0.1, 'priority': 50, 'path': path,
                'style': 'fill:none;' + \
                'stroke:#FF0000;stroke-linecap:butt;' + \
                'stroke-width:5;opacity:0.4;'})