InMemMap
- class leuvenmapmatching.map.inmem.InMemMap(name, use_latlon=True, use_rtree=False, index_edges=False, crs_lonlat=None, crs_xy=None, graph=None, linked_edges=None, dir=None, deserializing=False)[source]
In-memory representation of a map.
This is a simple database-like object to perform experiments with map matching. For production purposes it is recommended to use your own derived class (e.g. to connect to your database instance).
This class supports:
Indexing using rtrees to allow for fast searching of points on the map. When using the rtree index, only integer numbers are allowed as node labels.
Serializing to write and read from files.
Projecting points to a different frame (e.g. GPS to Lambert)
- Parameters:
name – Map name (mandatory)
use_latlon – The locations represent latitude-longitude pairs, otherwise y-x coordinates are assumed.
use_rtree – Build an rtree index to quickly search for locations.
index_edges – Build an index for the edges in the map instead of the vertices.
crs_lonlat – Coordinate reference system for the latitude-longitude coordinates.
crs_xy – Coordiante reference system for the y-x coordinates.
graph – Initial graph of form Dict[label, Tuple[Tuple[y,x], List[neighbor]]]]
dir – Directory where to serialize to. If given, the rtree index structure will be written to a file immediately.
deserializing – Internal variable to indicate that the object is being build from a file.
- add_edge(node_a, node_b)[source]
Add new edge to the map.
- Parameters:
node_a – Label for the node that is the start of the edge
node_b – Label for the node that is the end of the edge
- add_node(node, loc)[source]
Add new node to the map.
- Parameters:
node – label
loc – (lat, lon) or (y, x)
- all_edges(bb=None)[source]
Return all edges.
- Parameters:
bb – Bounding box
- Returns:
(key_a, loc_a, nbr, loc_b)
- bb()[source]
Bounding box.
- Returns:
(lat_min, lon_min, lat_max, lon_max) or (y_min, x_min, y_max, x_max)
- dump()[source]
Serialize map using pickle.
All files will be saved to the dir directory using the name as filename.
- edges_closeto(loc, max_dist=None, max_elmt=None)[source]
Return all nodes that are on an edge that is close to the given location.
- Parameters:
loc – Location
max_dist – Maximal distance from the location
max_elmt – Return only the most nearby nodes
- edges_nbrto(edge)[source]
Return all edges that are linked to
edge
.Defaults to
nodes_nbrto
.- Parameters:
edge – Edge identifier
- Returns:
list[tuple[label1, label2, loc1, loc2]]
- node_coordinates(node_key)[source]
Get the coordinates of the given node.
- Parameters:
node_key – Node label/key
- Returns:
(lat, lon)
- nodes_closeto(loc, max_dist=None, max_elmt=None)[source]
Return all nodes close to the given location.
- Parameters:
loc – Location
max_dist – Maximal distance from the location
max_elmt – Return only the most nearby nodes