Esempio n. 1
0
    def build_map_matching_graph(cls, road_network):
        """Return leuvenmapmatching.BaseMap used for map matching.

        """
        # Create the Leuven.MapMatching graph
        G = road_network.network
        map_con = InMemMap('road_network',
                           use_latlon=False,
                           use_rtree=True,
                           index_edges=True,
                           crs_lonlat=None,
                           crs_xy=None,
                           graph=None)
        for key in G.nodes:
            node = G.nodes[key]
            try:
                map_con.add_node(key, (node['easting'], node['northing']))
            except KeyError:
                raise Exception('Must call '
                                '\'populate_meters_from_lon_lat\' first '
                                'to define the Cartesian coordinates '
                                'associated with the latitude and '
                                'longitude coordinates.')

        for edge in G.edges:
            map_con.add_edge(*edge)

        return map_con
Esempio n. 2
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. 3
0
 def make_map(graph, latlon=True, index_edges=True):
     map_con = InMemMap(
         "athensmap",
         use_latlon=latlon,
         index_edges=index_edges,
         use_rtree=True)  # Deprecated crs style in algorithm
     nodes_proj, edges_proj = ox.graph_to_gdfs(graph,
                                               nodes=True,
                                               edges=True)
     for nid, row in nodes_proj[['y', 'x']].iterrows():
         map_con.add_node(nid, (row['y'], row['x']))
     for nid, row in edges_proj[['u', 'v']].iterrows():
         map_con.add_edge(row['u'], row['v'])
     return map_con
Esempio n. 4
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()
 def make_map(self, index_edges=True, rtree=True):
     map_con = InMemMap(
         "athensmap",
         use_latlon=self.match_latlon,
         index_edges=index_edges,
         use_rtree=rtree)  # Deprecated crs style in algorithm
     if self.match_latlon:
         for nid, rown in self.network_nodes.iterrows():
             map_con.add_node(int(rown.n1), (rown.lat1, rown.lon1))
         for eid, rowe in self.network_edges.iterrows():
             map_con.add_edge(rowe.n1, rowe.n2)
     else:
         for nid, rown in self.network_nodes.iterrows():
             map_con.add_node(int(rown.n1), (rown.y1, rown.x1))
         for eid, rowe in self.network_edges.iterrows():
             map_con.add_edge(rowe.n1, rowe.n2)
     return map_con
Esempio n. 6
0
def mk_map(graph_proj):
    map_con = InMemMap("myosm",
                       use_latlon=True,
                       use_rtree=True,
                       index_edges=True)

    #Create GeoDataFrames
    nodes_proj, edges_proj = ox.graph_to_gdfs(graph_proj,
                                              nodes=True,
                                              edges=True)

    #좌표계 변경
    nodes_proj = nodes_proj.to_crs({'init': 'epsg:4326'})
    edges_proj = edges_proj.to_crs({'init': 'epsg:4326'})

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

    return map_con
Esempio n. 7
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. 8
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
    map_con = InMemMap("osmmap",
                       use_latlon=True,
                       use_rtree=True,
                       index_edges=True)
    graph = ox.load_graphml("mynetwork.graphml")
    graph_proj = ox.project_graph(graph)

    # Create GeoDataFrames
    # Approach 2
    print("start1")
    nodes, edges = ox.graph_to_gdfs(graph_proj, nodes=True, edges=True)

    nodes_proj = nodes.to_crs("EPSG:3414")
    edges_proj = edges.to_crs("EPSG:3414")

    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)
    """## Read the SG dataframe"""
    sg_df = pd.read_csv('sg_car.csv')
    # print(sg_df.head())
    sg_df = sg_df.sort_values(by=['trj_id', 'pingtimestamp'])
    sg_df = sg_df.drop(sg_df[(sg_df.accuracy > 3000)].index)
    trj_ids = sg_df.trj_id.unique()
    n = len(trj_ids)
    print("Start")
    map_matching(map_con, sg_df, s=14000, n=20000)
Esempio n. 10
0
# G_project_file=open('G_project.pickle','wb')
# pickle.dump(graph,G_project_file)
# G_project_file.close()


# 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)