Esempio n. 1
0
def create_map(fn=osm_fn, include_footways=False, include_parking=False):
    map_con = InMemMap("map", use_latlon=True)
    cnt = 0
    ways_filter = ['bridleway', 'bus_guideway', 'track']
    if not include_footways:
        ways_filter += ['footway', 'cycleway', 'path']
    parking_filter = ['driveway']
    if not include_parking:
        parking_filter += ['parking_aisle']
    for entity in osmread.parse_file(str(fn)):
        if isinstance(entity, osmread.Way):
            tags = entity.tags
            if 'highway' in tags \
                and not (tags['highway'] in ways_filter) \
                and not ('access' in tags and tags['access'] == 'private') \
                and not ('landuse' in tags and tags['landuse'] == 'square') \
                and not ('amenity' in tags and tags['amenity'] == 'parking') \
                and not ('service' in tags and tags['service'] in parking_filter) \
                and not ('area' in tags and tags['area'] == 'yes'):
                for node_a, node_b in zip(entity.nodes, entity.nodes[1:]):
                    map_con.add_edge(node_a, node_b)
                    # Some roads are one-way. We'll add both directions.
                    map_con.add_edge(node_b, node_a)
        if isinstance(entity, osmread.Node):
            map_con.add_node(entity.id, (entity.lat, entity.lon))
    map_con.purge()
    return map_con
Esempio n. 2
0
def create_map_osmread() -> None:
    xml_file = Path("./tests") / "osm.xml"
    map_con = InMemMap("myosm",
                       use_latlon=True,
                       use_rtree=True,
                       index_edges=True)
    for entity in osmread.parse_file(str(xml_file)):
        if isinstance(entity, osmread.Way) and 'highway' in entity.tags:
            for node_a, node_b in zip(entity.nodes, entity.nodes[1:]):
                map_con.add_edge(node_a, node_b)
                # Some roads are one-way. We'll add both directions.
                map_con.add_edge(node_b, node_a)
        if isinstance(entity, osmread.Node):
            map_con.add_node(entity.id, (entity.lat, entity.lon))
    map_con.purge()
Esempio n. 3
0
def make_map(graph):
    graph_proj = ox.project_graph(graph)

    map_con = InMemMap("myosm",
                       use_latlon=True,
                       use_rtree=True,
                       index_edges=True)

    nodes, _ = ox.graph_to_gdfs(graph_proj, nodes=True, edges=True)

    nodes_proj = nodes.to_crs("EPSG:3395")

    for nid, row in nodes_proj.iterrows():
        map_con.add_node(nid, (row['lat'], row['lon']))

    # adding edges using networkx graph
    for nid1, nid2, _ in graph.edges:
        map_con.add_edge(nid1, nid2)

    map_con.purge()
    return map_con
Esempio n. 4
0
def get_InMemMap(graph):
    '''
        This function takes the OSMNX road network graph and returns a leuvenmapmatching InMem map

        Parameters:
        ___________
            graph: OSMNX road network
        Returns:
        __________
            leuvenmapmatching InMem map   
    '''
    # Leuven Map Matching is using a different internal graph structure for the street data.
    # Therefore, the OSMnx graph needs to be transformed to the InMemMap
    streetmap = InMemMap("enviroCar",
                         use_latlon=True,
                         use_rtree=True,
                         index_edges=True)
    # add nodes
    nodes = list(graph.nodes)
    for node in nodes:
        lng = graph.nodes[node]['x']
        lat = graph.nodes[node]['y']
        streetmap.add_node(node, (lat, lng))

    # add edges
    edges = list(graph.edges)
    for edge in edges:
        node_a, node_b = edge[0], edge[1]
        streetmap.add_edge(node_a, node_b)

        # exclude bi-directional edges when street is oneway
        if not graph.edges[edge]['oneway']:
            streetmap.add_edge(node_b, node_a)

    streetmap.purge()

    # returns streetmap
    return streetmap
Esempio n. 5
0

# Create GeoDataFrames
file=open('G_project.pickle','rb')
graph_proj = pickle.load(file)
nodes_proj, edges_proj = ox.graph_to_gdfs(graph_proj, nodes=True, edges=True)



map_con = InMemMap("myosm", use_rtree=True, index_edges=True)

for nid, row in nodes_proj[['x', 'y']].iterrows():
    map_con.add_node(int(nid), (row['x'], row['y']))
for nid, row in edges_proj[['u', 'v']].iterrows():
    map_con.add_edge(row['u'], row['v'])
map_con.purge()

# from leuvenmapmatching.util.gpx import gpx_to_path

# #track = gpx_to_path("mytrack.gpx")
# matcher = DistanceMatcher(map_con,
#                          max_dist=0.8,
#                          max_dist_init=25,  # meter
#                          min_prob_norm=0.01,
#                          #non_emitting_length_factor=0.75,
#                          obs_noise=0.5, obs_noise_ne=0.7,  # meter
#                          dist_noise=5,  # meter
#                          non_emitting_states=True)
matcher = DistanceMatcher(map_con, min_prob_norm=0.05)
# states, lastidx = matcher.match(list(path))