コード例 #1
0
ファイル: elements.py プロジェクト: rweait/changemonger
def add_remote_relations(coll):
    """Takes an element of collections and fetches relations as necessary"""
    elements = [ele for ele in coll if (not ele['tags']
                                        and not ele.has_key('_relations'))]
    nodes = [ele for ele in coll if ele['type'] == 'node']
    ways = [ele for ele in coll if ele['type'] == 'way']
    relations = [ele for ele in coll if ele['type'] == 'relation']
    for ele in elements:
        # We keep changing the elmements in place, so we must keep
        # checking them
        if ele['tags'] or ele.has_key('_ways') or ele.has_key('_relations'):
            continue
        data = osmapi.getRelationsforElement(ele['type'], ele['id'])
        xml = et.XML(data.encode('utf-8'))
        rels = [parser.parseRelation(rel) for rel in xml.findall('relation')]
        for rel in rels:
            coll.append(rel)
            for member in rel['members']:
                id = member['ref']
                type = member['type']
                obj = None
                if type == 'node':
                    obj = [m for m in nodes if m['id'] == id][0]
                elif type == 'way':
                    obj =  [m for m in ways if m['id'] == id][0]
                else:
                    obj = [m for m in relations if m['id'] == id][0]
                if obj:
                    # Now add the relation callback
                    if obj.has_key('_relations'):
                        obj['_relations'].append(rel)
                    else:
                        obj['_relations'] = [rel]
コード例 #2
0
ファイル: elements.py プロジェクト: ppawel/changemonger
def add_remote_relations(coll):
    """Takes an element of collections and fetches relations as necessary"""
    logging.debug("Adding remote relations")
    elements = [ele for ele in coll if (not ele["tags"] and not ele.has_key("_relations"))]
    nodes = [ele for ele in coll if ele["type"] == "node"]
    ways = [ele for ele in coll if ele["type"] == "way"]
    relations = [ele for ele in coll if ele["type"] == "relation"]
    for ele in elements:
        # We keep changing the elmements in place, so we must keep
        # checking them
        if ele["tags"] or ele.get("_ways") or ele.get("_relations"):
            continue
        data = osmapi.getRelationsforElement(ele["type"], ele["id"])
        xml = et.XML(data.encode("utf-8"))
        rels = [parser.parseRelation(rel) for rel in xml.findall("relation")]
        for rel in rels:
            logging.debug("Adding relation %s to collection" % str(rel["id"]))
            coll.append(rel)
            add_relation_references(coll, rel)
コード例 #3
0
ファイル: elements.py プロジェクト: ppawel/changemonger
def add_remote_relations(coll):
    """Takes an element of collections and fetches relations as necessary"""
    logging.debug("Adding remote relations")
    elements = [
        ele for ele in coll
        if (not ele['tags'] and not ele.has_key('_relations'))
    ]
    nodes = [ele for ele in coll if ele['type'] == 'node']
    ways = [ele for ele in coll if ele['type'] == 'way']
    relations = [ele for ele in coll if ele['type'] == 'relation']
    for ele in elements:
        # We keep changing the elmements in place, so we must keep
        # checking them
        if ele['tags'] or ele.get('_ways') or ele.get('_relations'):
            continue
        data = osmapi.getRelationsforElement(ele['type'], ele['id'])
        xml = et.XML(data.encode('utf-8'))
        rels = [parser.parseRelation(rel) for rel in xml.findall('relation')]
        for rel in rels:
            logging.debug("Adding relation %s to collection" % str(rel['id']))
            coll.append(rel)
            add_relation_references(coll, rel)