Graph
distance
- pytrack.graph.distance.add_edge_lengths(G, precision=3)[source]
Method that adds the length of individual edges to the graph.
- Parameters
G (networkx.MultiDiGraph) – Road network graph.
precision (float, optional, default: 3) – Number of decimal digits of the length of individual edges.
- Returns
G – Street network graph.
- Return type
networkx.MultiDiGraph
- pytrack.graph.distance.enlarge_bbox(north, south, west, east, dist)[source]
Method that expands a bounding box by a specified distance.
- Parameters
- Returns
north, south, west, east – North, south, west, east coordinates of the expanded bounding box
- Return type
- pytrack.graph.distance.get_bearing(lat1, lon1, lat2, lon2)[source]
Get bearing between two points.
- Parameters
- Returns
bearing – Bearing between two points.
- Return type
- pytrack.graph.distance.haversine_dist(lat1, lon1, lat2, lon2, earth_radius=6371009)[source]
Calculate the great circle distance between two points on the earth (specified in decimal degrees)
- Parameters
lat1 (float) – Latitude of the first point specified in decimal degrees
lon1 (float) – Longitude of the first point specified in decimal degrees
lat2 (float) – Latitude of the second point specified in decimal degrees
lon2 (float) – Longitude of the second point specified in decimal degrees
earth_radius (float, optional, default: 6371009.0 meters) – Earth’s radius
- Returns
dist – Distance in units of earth_radius
- Return type
- pytrack.graph.distance.interpolate_geom(geom, dist=1)[source]
Method that interpolates a geometry created using the
shapely.geometry.LineStringmethod.- Parameters
geom (shapely.geometry.LineString) – Geometry to be interpolated.
dist (float, optional, default: 1) – Distance between one node and the next.
- Returns
geom – Interpolated geometry.
- Return type
shapely.geometry
- pytrack.graph.distance.interpolate_graph(G, dist=1)[source]
Method that creates a graph by interpolating the nodes of a graph.
- Parameters
G (networkx.MultiDiGraph) – Road network graph.
dist (float, optional, default: 1) – Distance between one node and the next.
- Returns
G – Street network graph.
- Return type
networkx.MultiDiGraph
download
- pytrack.graph.download.get_filters(network_type='drive')[source]
Get the filters with which to interrogate the OpenStreetMao API service.
- pytrack.graph.download.osm_download(bbox, network_type='drive', custom_filter=None)[source]
Get the OpenStreetMap response.
- Parameters
bbox (tuple) – bounding box within N, S, E, W coordinates.
network_type (str, optional, default: 'drive') – Type of street network to obtain.
custom_filter (str or None, optional, default: None) – Custom filter to be used instead of the predefined ones to query the Overpass API. An example of a custom filter is the following ‘[highway][!”footway”]’. For more information visit https://overpass-turbo.eu and https://taginfo.openstreetmap.org.
- Returns
response – Response of the OpenStreetMao API service.
- Return type
json
graph
- pytrack.graph.graph.add_edges(G, paths, bidirectional=False, all_oneway=False)[source]
Add OSM edges to a
networkx.MultiDiGraph.
- pytrack.graph.graph.convert_edge(element)[source]
Convert an OSM edge into an edge to construct a street network graph.
- pytrack.graph.graph.convert_node(element)[source]
Convert an OSM node into a node to construct a street network graph.
- pytrack.graph.graph.create_graph(response_json)[source]
Method that creates a networkx.MultiDiGraph representing a network street graph.
- Parameters
response_json (json) – Response of OpenStreetMap API service got with``osm_download``method.
- Returns
G – Street network graph.
- Return type
networkx.MultiDiGraph
- pytrack.graph.graph.get_nodes_edges(response_json)[source]
Extract nodes and paths from the OpenStreetMap query response.
- Parameters
response_json (json) – Response of OpenStreetMap API service got with``osm_download``method
- Returns
nodes (dict) – Dictionary of OSM nodes.
paths (dict) – Dictionary of OSM paths.
- pytrack.graph.graph.graph_from_bbox(north, south, west, east, simplify=True, network_type='drive', custom_filter=None, buffer_dist=0)[source]
Create a graph from OpenStreetMap within some bounding box.
- Parameters
north (float) – Northern latitude of bounding box.
south (float) – southern latitude of bounding box.
west (float) – Western longitude of bounding box.
east (float) – Eastern longitude of bounding box.
simplify (bool, optional, default: True) – if True, simplify graph topology with the
simplify_graphmethod.network_type (str, optional, default: 'drive') – Type of street network to obtain.
custom_filter (str or None, optional, default: None) – Custom filter to be used instead of the predefined ones to query the Overpass API.
buffer_dist (float, optional, default: 0) – Distance in meters indicating how much to expand the bounding box.
- Returns
G – Street network graph.
- Return type
networkx.MultiDiGraph
utils
- pytrack.graph.utils.get_unique_number(lon, lat)[source]
Assigns a unique identifier to a geographical coordinate. :param lon: Longitude of the point :type lon: float :param lat: Latitude of the point :type lat: float
- Returns
val – Unique identifier.
- Return type
- pytrack.graph.utils.graph_to_gdfs(G, nodes=True, edges=True, node_geometry=True, edge_geometry=True)[source]
Convert a networkx.MultiDiGraph to node and/or edge pandas DataFrame.
- Parameters
G (networkx.MultiDiGraph) – Street network graph.
nodes (bool, optional, default: True) – Whether to extract graph nodes.
edges (bool, optional, default: True) – Whether to extract graph edges.
node_geometry (bool, optional, default: True) – Whether to compute graph node geometries.
edge_geometry (bool, optional, default: True) – Whether to extract graph edge geometries.
- Returns
gdf_nodes (pandas.DataFrame) – Dataframe collecting graph nodes.
gdf_edges (pandas.DataFrame) – Dataframe collecting graph edges