mappymatch.maps.igraph.igraph_map#

Classes

IGraphMap(graph)

A road map that uses an igraph graph to represent its roads.

class mappymatch.maps.igraph.igraph_map.IGraphMap(graph)[source]#

A road map that uses an igraph graph to represent its roads.

Attributes:

ig: The igraph graph that represents the road map road_mapping: A mapping from road ids to igraph edge ids crs: The coordinate reference system of the map

Parameters:

graph (ig.Graph)

property distance_weight: str#

Get the distance weight

Returns:

The distance weight

property time_weight: str#

Get the time weight

Returns:

The time weight

road_by_id(road_id)[source]#

Get a road by its id

Return type:

Optional[Road]

Parameters:

road_id (RoadId)

Args:

road_id: The id of the road to get

Returns:

The road with the given id, or None if it does not exist

set_road_attributes(attributes)[source]#

Set the attributes of the roads in the map

Args:

attributes: A dictionary mapping road ids to dictionaries of attributes

Returns:

None

Parameters:

attributes (Dict[RoadId, Dict[str, Any]])

property roads: List[Road]#

Get a list of all the roads in the map

Returns:

A list of all the roads in the map

classmethod from_nx_graph(nx_graph)[source]#

Build an IGraphMap from a networkx graph

Return type:

IGraphMap

Parameters:

nx_graph (MultiDiGraph)

classmethod from_file(file)[source]#

Build a IGraphMap instance from a file

Return type:

IGraphMap

Parameters:

file (str | Path)

Args:

file: The graph pickle file to load the graph from

Returns:

A IGraphMap instance

classmethod from_geofence(geofence, xy=True, network_type=NetworkType.DRIVE)[source]#

Read an OSM network graph into a IGraphMap

Return type:

IGraphMap

Parameters:
Args:

geofence: the geofence to clip the graph to xy: whether to use xy coordinates or lat/lon network_type: the network type to use for the graph

Returns:

a IGraphMap

to_file(outfile)[source]#

Save the graph to a pickle file

Args:

outfile: The file to save the graph to

Parameters:

outfile (str | Path)

nearest_road(coord, buffer=10.0)[source]#

A helper function to get the nearest road.

Return type:

Road

Parameters:
Args:

coord: The coordinate to find the nearest road to buffer: The buffer to search around the coordinate

Returns:

The nearest road to the coordinate

shortest_path(origin, destination, weight=None)[source]#

Computes the shortest path between an origin and a destination

Return type:

List[Road]

Parameters:
Args:

origin: The origin coordinate destination: The destination coordinate weight: The weight to use for the path, either a string or a function

Returns:

A list of roads that form the shortest path