pyroutelib3.protocols

pyroutelib3.protocols.Position

Position describes the physical location of a node. For on-Earth positions, this should be WGS84 degrees, first latitude, then longitude.

alias of Tuple[float, float]

class pyroutelib3.protocols.WithPosition(*args, **kwargs)

Bases: Protocol

WithPosition describes any object with a position property of Position type.

property position: Tuple[float, float]
class pyroutelib3.protocols.NodeLike(*args, **kwargs)

Bases: WithPosition, Protocol

NodeLike describes the protocol of a node in a graph.

property id: int

id property must uniquely identify this node in its graph.

class pyroutelib3.protocols.ExternalNodeLike(*args, **kwargs)

Bases: NodeLike, Protocol

ExternalNodeLike is an extension of the NodeLike protocol for describing nodes coming from external datasets.

property external_id: int

external_id property should return the ID used to lookup this node in an external dataset, for example an OpenStreetMap node ID.

external_id may be reused by multiple nodes, for example processing OpenStreetMap turn restrictions may create multiple graph nodes corresponding to a single OpenStreetMap node.

Used by find_route_without_turn_around() to prevent turn restriction circumvention by forbidding A-B-A paths.

class pyroutelib3.protocols.GraphLike(*args, **kwargs)

Bases: Protocol[NodeLikeT_co]

GraphLike describes the protocol of a graph.

get_edges(id: int) Iterable[Tuple[int, float]]

get_edges must return all edges outgoing from a node with the provided ID. The edges are a pair of (node_id, cost). All returned neighbor nodes must exist in the graph.

If there are no outgoing edges from the provided node, must return an empty iterable. If a node with the given ID, may return an empty iterable, or raise KeyError.

get_node(id: int) NodeLikeT_co

get_node must return a NodeLike of a node by the provided ID. If such a node doesn’t exist, must raise KeyError.

pyroutelib3.protocols.DistanceFunction

DistanceFunction describes a callable for determining the shortest crow-flies distance between two points.

alias of Callable[[Tuple[float, float], Tuple[float, float]], float]