Network#
This module contains the class to manage Network
- class tracklib.core.Network.Node(id, coord)[source]#
Node / vertice of a network
- __init__(id, coord)[source]#
Node
constructor- Parameters
id (
int
) – unique id of Nodecoord (
Union
[ECEFCoords
,ENUCoords
,GeoCoords
]) – A coordinate object
- distanceTo(node)[source]#
Distance to an other node
- Parameters
node (
Node
) – Node to compute the distance- Return type
float
- Returns
3d distance
- class tracklib.core.Network.Edge(id, track)[source]#
Class to define an edge / arc
- DOUBLE_SENS = 0#
- SENS_DIRECT = 1#
- SENS_INVERSE = -1#
- class tracklib.core.Network.Network[source]#
Define a network
- ROUTING_ALGO_DIJKSTRA = 0#
- ROUTING_ALGO_ASTAR = 1#
- AF_LINK = '#link'#
- AF_WEIGHT = '#weight'#
- setRoutingMethod(method)[source]#
Define the routing algorithm
- Parameters
method (
int
) –Algorithm of routing. Two values are possible :
ROUTING_ALGO_DIJKSTRA [default].
ROUTING_ALGO_ASTAR.
NB: A* is an efficient approximate version of Dijkstra. It returns exact solution under theoretical assumptions on the metrics used to set weights on graph edges.
- toGeoCoords(base)[source]#
Convert network to
core.Coords.GeoCoords
- Parameters
base (
Union
[ECEFCoords
,ENUCoords
]) – Base coordinate for conversion
- toENUCoords(base)[source]#
Convert network to
core.Coords.ENUCoords
- Parameters
base (
Union
[GeoCoords
,ECEFCoords
]) – Base coordinate for conversion
- simplify(tolerance, mode=1)[source]#
Simplification of current network
- Parameters
tolerance – TODO
mode (
int
) –Mode of simplification. The possibles values are:
DOUGLAS_PEUCKER
VISVALINGAM
MINIMIZE_LARGEST_DEVIATION
MINIMIZE_ELONGATION_RATIO
PRECLUDE_LARGE_DEVIATION
FREE
FREE_MAXIMIZE
See
algo.Simplification.simplify()
documentation for more infos
- createSpatialIndex(resolution=None, margin=0.05, verbose=True)[source]#
Create a spatial index
- Parameters
resolution – TODO
margin (
float
) – TODOverbose (
bool
) – Verbose creation
- exportSpatialIndex(filename)[source]#
Export the spatial index to a file
- Parameters
filename (
str
) – File to export
- importSpatialIndex(filename)[source]#
Import a spatial index from a file
- Parma filename
File to import
- degree(node_id)[source]#
Compute the degree of a node
- Parameters
node_id (
int
) – id of a node- Return type
int
- Returns
in degree
- degreeIn(node_id)[source]#
Compute the in degree of a node
- Parameters
node_id (
int
) – id of a node- Return type
int
- Returns
in degree
- degreeOut(node_id)[source]#
Compute the out degree of a node
- Parameters
node_id (
int
) – id of a node- Return type
int
- Returns
out degree
- getIndexNodes()[source]#
Return the list of seted nodes
- Return type
list
[int
]- Returns
A list of nodes id
- getNumberOfVertices()[source]#
Number of vertices in the network
- Return type
int
- Returns
Number of vertices
- getNodeId(n)[source]#
The return the id of the n-est Node
- Parameters
n (
int
) – Position of the node- Return type
int
- Returns
Id of the node
- getEdgeId(n)[source]#
The return the id of the n-est Edge
- Parameters
n (
int
) – Position of the Edge- Return type
int
- Returns
Id of the Edge
- getRandomNode()[source]#
Return a random node of network
- Return type
- Returns
A node randomly choosed
- hasNode(id)[source]#
Check if a node with a given id exist
- Parameters
id (
int
) – node id to test- Return type
bool
- hasEdge(id)[source]#
Check if a node with a given id exist
- Parameters
id (
int
) – edge id to test- Return type
bool
- getNode(id)[source]#
Return the node with a give id
- Parameters
id (
int
) – node id to get- Return type
- getEdge(id)[source]#
Return the edge with a give id
- Parameters
id (
int
) – edge id to get- Return type
- getAllEdgeGeoms()[source]#
Return a TrackCollection of all edges
- Return type
- Returns
All edges of
Network
- plot(edges='k-', nodes='', direct='k--', indirect='k--', size=0.5, append=<module 'matplotlib.pyplot' from '/home/marie-dominique/.pyenv/versions/3.9.1/lib/python3.9/site-packages/matplotlib/pyplot.py'>, v=None)[source]#
- __correctInputNode(node)#
TODO
- sub_network(source, cut, mode='TOPOLOGIC', verbose=True)[source]#
Extracts sub-network from routing forward search
An edge is added to the output network if bot its ends have been visited during the search process (TOPOGRAPHIC mode) or if one of its ends are located in a circle centered on source with radius = cut
- Parameters
source (
Union
[int
,Node
,GeoCoords
,ENUCoords
,ECEFCoords
]) – a source node (id or node object) or a coordcut (
float
) – a maximal distance for searchmode (
Literal
[‘TOPOLOGIC’, ‘GEOMETRIC’]) – “TOPOLOGIC” (default) or “GEOMETRIC”verbose (
bool
) – Verbose creation
- Result
a network containing only visited nodes reachable from source with a cost lower than cut distance.
- Return type
- __sub_network_routing(verbose)#
Sub network generation
- Parameters
verbose (
bool
) – Verbose creation- Return type
- Returns
A sub part of the current network
- __sub_network_geometric(source, cut, verbose)#
Sub network generation, based on geometry
- __resetFlags()#
Internal function to call before dijkstra forward step
- run_routing_forward(source, target=None, cut=1e+300, output_dict=None)[source]#
Executes forward pass of routing algorithm to find shortest distance between source node and all other nodes in graph.
Execution may be stopped prematurely by specifying target node and/or cut distance. For each nodes reached (with a distance d < cut) during the search process, an entry {key=(source, n), value=d} is added to an output dictionnary (if specified as input)
- shortest_distance(source, target=None, cut=1e+300, output_dict=None)[source]#
Finds shortest distance between source node and either a target node or a list of target nodes.
In every case, time complexity is \(O((n+m) \cdot \log(n))\) with \(n\) the number of node and \(m\) the number of edges. That amounts roughly to \(O(n \cdot \log(n))\) for a typical planar road network, and to \(O(n^2 \cdot \log(n))\) for a general network
- Parameters
- Return type
Union
[float
,list
[float
]]- Returns
The distance between source and target nodes If target node is not specified, returns a list of distances between source node and all other nodes in the network (non-reachable nodes are associated to 1e300 distance).
- all_shortest_distances(cut=1e+300, output_dict=None)[source]#
Computes all shortest distances between pairs of nodes
The results are saved in a dictionnary {key=(source, n), value=d}.
If output dictionnary structure is provided as input, it is directly incremented during the process, otherwise, it is created before begining to search for shortest distances.
Time complexity is \(O(n \cdot (n+m) \cdot \log(n))\) with \(n\) the number of nodes and \(n\) the number of edges. That amounts roughly to \(O(n^2.log(n))\) for a typical planar road network, and to \(O(n^3.log(n))\) for a general network.
- Parameters
cut (
float
) – a maximal distance for search (optional)output_dict (
Optional
[dict
]) – output structure for retrieved distances
- Return type
Dict
[Tuple
[int
,int
],float
]- Returns
The distances between all pairs of nodes. Nodes separated by a distance > cut are not registered in the output dictionnary. If dictionnary is provided as input it is incremented during the process, hence it is possble tocall ‘all_shortest_distances’ successively with the same output dictionnary structure.
- run_routing_backward(target)[source]#
Computes shortest path between the source node used in forward step
run_routing_forward()
and any target node.If target node has not been reached during forward search, a None object is returned by the function.
- Parameters
target (
Union
[int
,Node
]) – A target node- Return type
Optional
[Track
]- Returns
A track between the source node specified in
run_routing_forward()
and a target node. The track contains topologic and non-topologic vertices. If the node target has not been reached during forward step, None object is output
- shortest_path(source, target, cut=1e+300, output_dict=None)[source]#
Computes shortest path between source and target nodes
- Parameters
- Return type
Optional
[Track
]- Returns
A track between source and target node. If target is not reachable during forward step, None object is output
- distanceBtwPts(edge1, abs_curv_1, edge2, abs_curv_2)[source]#
Distance between 2 points
Each points being described by:
Edge id number
Curvilinear abscissa on edge geometry from source
- Parameters
edge1 (
int
) – edge 1 id numberabs_curv_1 (
float
) – curvilinear abscissa on edge 1 geometry from sourceedge2 (
int
) – edge 2 id numberabs_curv_2 (
float
) – curvilinear abscissa on edge 2 geometry from source
- Return type
float
- Returns
Distance between points
- prepare(cut=1e+300)[source]#
Precomputes shortest distances between all pairs of nodes and saves the result in
DISTANCES
attribute.- Parameters
cut (
Optional
[float
]) – A maximal distance for search
- has_prepared_shortest_distance(source, target)[source]#
Tests if a shortest distance has been precomputed
- prepared_shortest_distance(source, target)[source]#
Finds shortest distance from the precomputation. May be called only after
prepare()
orload_prep.()