示例#1
0
def osmSaxReader(path, features):
    parser = xml.sax.make_parser()      # 创建一个 XMLReader
    parser.setFeature(xml.sax.handler.feature_namespaces, 0)    # turn off namepsaces  ??????
    Handler = osmHandler(features)      # 重写 ContextHandler
    parser.setContentHandler(Handler)
    parser.parse(path)

    for p in Handler.dicOfRelations.itervalues():  # 这里要学习迭代遍历dic的方法
        tmplist = Handler.parseRelations(p)
        # pprint.pprint(tmplist)
        # assemList = Handler.nodeAssembly(tmplist)  # 装配“描绘点集”
        # if res:
        #     print "not all member found!"
        # else:
        #     print "Find all members!"
        actor = visu.getlsactor(tmplist)
        visu.showact(actor)

    # if Handler.gotObject:
    #     actor = visu.getlsactor(Handler.noTypebdSets)
    #     visu.showact(actor)
    #     # for b in Handler.bdSets:
    #     #     actor = visu.getlsactor(b)
    #     #     visu.showact2(actor)
    # else:
    #     print "未找到目标设施数据"
    pass
示例#2
0
def drawOSM(input):

    tree = ET.parse(input)
    root = tree.getroot()
    print root.tag

    latlon = []
    elenum = {}
    nodes = {}
    ps = []
    for ch in root:
        if ch.tag in elenum:
            elenum[ch.tag] += 1
        else:
            elenum[ch.tag] = 0

        if ch.tag == 'node':
            lat = float(ch.attrib['lat'])

            lon = float(ch.attrib['lon'])
            latlon.append([lon,lat])
            nodes[ch.attrib['id']] = [lon, lat]


    ls = []
    for ch in root:
        if ch.tag == 'node':
            x = float(ch.attrib['lat'])
            y = float(ch.attrib['lon'])
            ps.append([x, y, 0])
        if ch.tag == 'way':
            lines = []
            for nd in ch:
                if nd.tag == 'nd':
                    lines.append(nodes[nd.attrib['ref']])

            for i in range(len(lines)-1):
                # print len(lines),lines[i][0]*100000
                c0 = getXY(lines[i])
                c1 = getXY(lines[i+1])
                # x2,y2 = getXY(lines[i+1][0],lines[i+1][1])
                l = [c0, c1]
                ls.append(l)
                pass
                # draw.line((x1,y1, x2,y2), fill=128)



    #im.show()
    #im.save(out)

    print len(ls), ls[:10]
    #visulines(ls[:20])
    #print nodes
    print elenum
    return visu.getlsactor(ls)
            return None
        pass



if __name__ == '__main__':
    # tmplist = [1, 2, 3, 4, 5, 6]
    # tmp = tmplist.append([])
    # print tmplist
    # print [[p,V] for p, V in tmplist ]
    import visu
    handler = osmdbOperation("osmdb.db")
    # tmplist = handler.Readrelationsfromdb("200257")
    # # handler.Readwaysfromdb('28771749')
    # actor = visu.getlsactor(tmplist)
    # visu.showact(actor)
    ID = '200257'
    query = 'SELECT id FROM relations'  #  WHERE id = %s' % ID
    handler.curs.execute(query)
    tmplist = handler.curs.fetchall()
    for p in tmplist:
        try:
            q = handler.Readrelationsfromdb(p)
            actor = visu.getlsactor(q)
            visu.showact(actor)
        except TypeError, e:
            # print e
            continue
    pass