mappymatch.maps.nx.nx_map#

Classes

NxMap(graph)

A road map that uses a networkx graph to represent its roads.

class mappymatch.maps.nx.nx_map.NxMap(graph)[source]#

A road map that uses a networkx graph to represent its roads.

Attributes:

g: The networkx graph that represents the road map crs: The coordinate reference system of the map

Parameters:

graph (nx.MultiDiGraph)

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_file(file)[source]#

Build a NxMap instance from a file

Return type:

NxMap

Parameters:

file (str | Path)

Args:

file: The graph pickle file to load the graph from

Returns:

A NxMap instance

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

Read an OSM network graph into a NxMap

Return type:

NxMap

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 custom_filter: a custom filter to pass to osmnx like '["highway"~"motorway|primary"]'

Returns:

a NxMap

to_file(outfile)[source]#

Save the graph to a pickle file

Args:

outfile: The file to save the graph to

Parameters:

outfile (str | Path)

classmethod from_dict(d)[source]#

Build a NxMap instance from a dictionary

Return type:

NxMap

Parameters:

d (Dict[str, Any])

to_dict()[source]#

Convert the map to a dictionary

Return type:

Dict[str, Any]

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