コード例 #1
0
ファイル: py.py プロジェクト: ponyatov/osmos
print SAMARA_OBL.lat,SAMARA_OBL.lon

def lxm(xxx):
    return lxml.etree.tostring(xxx)

OSM = SAMARA_OBL.xpath('/osm')[0]

MP=cgmp.MP('../map/mp.mp')

MP.IMGID.Name='Samara globe (c) osm.org'
MP.IMGID.LocalName='глобус Самары (c) osm.org'
MP.IMGID.Version=OSM.attrib['version']
MP.IMGID.Copyright='(c) osm.org & [email protected]'#OSM.attrib['copyright']
 
R=SAMARA_OBL.xpath('/osm/relation[@id=72194]/member[@type="node"][@role="label"]')[0].attrib['ref']
C=SAMARA_OBL_CENTER=osm.node(R)
print C.id,C.lat,C.lon,C.name
MP.IMGID.PointView='%s %s'%(C.lat,C.lon)
MP.add(cgmp.AdminCenter(C.id,C.lat,C.lon,C.name))

R=SAMARA_OBL.xpath('/osm/relation[@id=72194]/member[@type="node"][@role="admin_centre"]')[0].attrib['ref']
C=osm.node(R)
print C.id,C.lat,C.lon,C.name
MP.IMGID.MainTown=C.name
MP.add(cgmp.MainCity(C.id,C.lat,C.lon,C.name))

print SAMARA_OBL.name,'outline:',
for i in SAMARA_OBL.xpath('//relation[@id=72194]/member[@type="way"][@role="outer"]'):
    W=osm.way(i.attrib['ref']) ; print W.id,
    MP.add(cgmp.StateBoundary(W.id,W.poly,W.name))
print
コード例 #2
0
ファイル: poly2map.py プロジェクト: rsavoye/gosm
# Write OSM file
tmp = base + ".osm"
osm = osm.osmfile(dd, tmp)
print("Output file: %r" % tmp)
osm.header()

bbox = poly.getBBox()
refs = []
# Make a rectangular polygon for tasking  manager
#Upper left
# top line
attrs = dict()
attrs['lat'] = str(bbox[3])
attrs['lon'] = str(bbox[0])
node = osm.node(list(), attrs) + 1
refs.append(node)

# Upper Right
attrs = dict()
attrs['lat'] = str(bbox[3])
attrs['lon'] = str(bbox[1])
node = osm.node(list(), attrs) + 1
refs.append(node)

# Right side
# Lower Right
attrs = dict()
attrs['lat'] = str(bbox[2])
attrs['lon'] = str(bbox[1])
node = osm.node(list(), attrs) + 1
コード例 #3
0
ファイル: filter.py プロジェクト: rsavoye/gosm
        if dist < threshold:
            logging.info("Ignoring for dist %r" % dist)
            result = dbcursor.fetchone()
            continue
        previous = (lat, lon)

        # Make the OSM Node
        attrs['user'] = dd.get('user')
        attrs['uid'] = dd.get('uid')
        attrs['lon'] = str(lon)
        attrs['lat'] = str(lat)
        tagger = osm.makeTag('addr:housenumber', result[1])
        alltags.append(tagger)
        tagger = osm.makeTag('addr:street', result[2])
        alltags.append(tagger)
        node = osm.node(alltags, attrs)
        result = dbcursor.fetchone()

    # query = """DROP TABLE sorted;"""
    # dbcursor.execute(query)
    # logging.debug("Rowcount: %r" % dbcursor.rowcount)
    # if dbcursor.rowcount < 0:
    #     logging.error("Query failed: %s" % query)

    # query = """SELECT "addr:housenumber",way,ST_Centroid(way) AS center INTO sorted FROM planet_osm_polygon WHERE "addr:housenumber" is not NULL or building='yes';"""
    # dbcursor.execute(query)
    # logging.debug("Rowcount: %r" % dbcursor.rowcount)
    # if dbcursor.rowcount < 0:
    #     logging.error("Query failed: %s" % query)

    # query = """SELECT ST_Transform(way,4326),"addr:housenumber" FROM sorted;"""
コード例 #4
0
def start_element(name, attrs):
    global n,parsing_node,w,parsing_way,r,parsing_relation,noderefs,sequence_id,cut_nodes,sequence_id,wnc
    if name == 'node':
        parsing_node=True
        n = node()
        n.lat = 'lat' in attrs and float(attrs['lat'])
        n.lon = 'lon' in attrs and float(attrs['lon'])
        n.version = 'version' in attrs and int(attrs['version'])
        n.user_id = 'uid' in attrs and int(attrs['uid']) or 0
        n.user = '******' in attrs and unicode(attrs['user']) or "__anonymous__"
        n.id = 'id' in attrs and int(attrs['id'])
        n.visible = 'visible' in attrs and attrs['visible'] == "true"
        n.timestamp = 'timestamp' in attrs and iso8601.parse_date(attrs['timestamp'])
        n.changeset_id = 'changeset' in attrs and int(attrs['changeset'])
    elif name == 'way':
        sequence_id = 0
        parsing_way=True
        w = way()
        w.version = 'version' in attrs and int(attrs['version'])
        w.user_id = 'uid' in attrs and int(attrs['uid']) or 0
        w.user = '******' in attrs and unicode(attrs['user']) or "__anonymous__"
        w.id = 'id' in attrs and int(attrs['id'])
        w.visible = 'visible' in attrs and attrs['visible'] == "true"
        w.timestamp = 'timestamp' in attrs and iso8601.parse_date(attrs['timestamp'])
        w.changeset_id = 'changeset' in attrs and int(attrs['changeset'])
    elif name == 'relation':
        parsing_relation=True
        r = relation()
        r.version = 'version' in attrs and int(attrs['version'])
        r.user_id = 'uid' in attrs and int(attrs['uid']) or 0
        r.user = '******' in attrs and unicode(attrs['user']) or "__anonymous__"
        r.id = 'id' in attrs and int(attrs['id'])
        r.visible = 'visible' in attrs and attrs['visible'] == "true"
        r.timestamp = 'timestamp' in attrs and iso8601.parse_date(attrs['timestamp'])
        r.changeset_id = 'changeset' in attrs and int(attrs['changeset'])
    elif name == 'tag':
        if parsing_node and not n:
            print "\ttag outside of node"
        elif parsing_way and not w:
            print "\ttag outside of way"
        elif parsing_relation and not r:
            print "\ttag outside of relation"
        else:
            if parsing_node:
                p = n
            elif parsing_way:
                p = w
            elif parsing_relation:
                p = r
            if 'k' in attrs and 'v' in attrs and p:
                p.tags[attrs['k']] = attrs['v']
    elif name == 'nd' and parsing_way:
        #print '\tnoderef start:', attrs['ref']
        if not w:
            print "\tnoderef outside of way"
        else:
            noderef = 'ref' in attrs and int(attrs['ref'])
            timestamp_way = w.timestamp.strftime("%Y%m%d%H%M%S")
            # find node version that corresponds to way version
            # that is the last node version that has creation date before this way version creation date.
            cursor_nodememstore.execute("select max(timestamp),version from nodes where id = ? and timestamp <= ?",(noderef,timestamp_way))
            row = cursor_nodememstore.fetchone()
            if row[0] == None:
            	# Node does not exist in file, possibly because this version was not in the extract's bbox
            	# Solution for now is to cut this node out for this way-version.
            	cut_nodes += 1
            	logging.warn("node ref %i was cut from way %i version %i because the node was not in the file" % (noderef,w.id,w.version))
            else:
                noderefs.append(noderef)
                wn.append((w.id,w.version,noderef,row[1],sequence_id))
                sequence_id += 1
                wnc += 1
    elif name == 'member' and parsing_relation:
        #print '\tmember start:', attrs['ref']
        if not r:
            print "\tnmember outside of relation"
        else:
            m = member()
            m.type = 'type' in attrs and attrs['type']
            m.ref = 'ref' in attrs and attrs['ref']
            m.role = 'role' in attrs and attrs['role']
            m.sequence_id = sequence_id
            sequence_id += 1
            r.members.append(m)