openlr_dereferencer.maps package

Submodules

openlr_dereferencer.maps.abstract module

Contains an abstract MapReader base class, which must be implemented for each map format to decode location references on.

A MapReader is an interface with which the decoder can traverse the map. An implementation may consist of a database connection or something similar. Its purpose is to let the decoder read map objects.

In order to implement a reader for a new map, the following interfaces have to be implemented:

The map model

Nodes

A node is an object with an ID and a WGS84 longitude/latitude position.

Lines

A line interconnects exactly two nodes in exactly one direction. As additional attributes, it has a shape, a functional road class and a form of way.

Note that the map you want to implement may have a different line concept. For example, it is common that roads are not necessarily directed. Also, roads may connect more than two nodes.

Let’s consider an example map format that defines ways like this:

_images/Mapformat_1_Way.svg

Roads in the map are modeled as multi-directional ways.

If we write a MapReader adapter for this format, we could consider every directed link between nodes being a line, yielding multiple lines per way.

As lines and ways are now different things, our line IDs have to include more than just the way ID. It can be, for example, a tuple of the way ID and both node IDs.

_images/Mapformat_2_Lines.svg

Line IDs are required to be hashable. Since tuples of numbers are hashable, they can be used to implement line IDs.

class openlr_dereferencer.maps.abstract.GeometricObject[source]

Bases: abc.ABC

geometry

Returns the geometry of this object

class openlr_dereferencer.maps.abstract.Line[source]

Bases: openlr_dereferencer.maps.abstract.GeometricObject

Abstract Line class, modelling a line coming from a map reader

coordinates() → Sequence[openlr.locations.Coordinates][source]

Returns the shape of the line as list of Coordinates

distance_to(coord: openlr.locations.Coordinates) → int[source]

Compute the point-to-line distance

end_node

Returns the node on which this line ends

fow

Returns the form of way of this line

frc

Returns the functional road class of this line

geometry

Returns the geometric shape as a linestring

length

Return the line length in meters

line_id

Returns the id of the line.

A type is not specified here, but the ID has to be usable as key of a dictionary.

start_node

Returns the node from which this line starts

class openlr_dereferencer.maps.abstract.MapReader[source]

Bases: abc.ABC

Abstract base class for map readers.

This is an adapter class that fulfills the map requirements of OpenLR.

find_lines_close_to(coord: openlr.locations.Coordinates, dist: float) → Iterable[openlr_dereferencer.maps.abstract.Line][source]

Iterates over all lines within dist meters around coord.

No order specified here.

find_nodes_close_to(coord: openlr.locations.Coordinates, dist: float) → Iterable[openlr_dereferencer.maps.abstract.Node][source]

Iterates over all nodes within dist meters around coord.

No order specified here.

get_line(line_id: Hashable) → openlr_dereferencer.maps.abstract.Line[source]

Returns a line by its id

get_linecount() → int[source]

Returns the number of lines in the map.

get_lines() → Iterable[openlr_dereferencer.maps.abstract.Line][source]

Yields all lines in the map.

get_node(node_id: Hashable) → openlr_dereferencer.maps.abstract.Node[source]

Returns a node by its id.

get_nodecount() → int[source]

Returns the number of nodes in the map.

get_nodes() → Iterable[openlr_dereferencer.maps.abstract.Node][source]

Yields all nodes contained in the map.

class openlr_dereferencer.maps.abstract.Node[source]

Bases: openlr_dereferencer.maps.abstract.GeometricObject

Abstract class modelling a node returned by a map reader

connected_lines() → Iterable[openlr_dereferencer.maps.abstract.Line][source]

Returns lines which touch this node

coordinates

Returns the lon, lat coordinates of this node

geometry

Returns the position of this node as shapely point

incoming_lines() → Iterable[openlr_dereferencer.maps.abstract.Line][source]

Yields all lines coming directly to this node.

node_id

Returns the id of this node.

outgoing_lines() → Iterable[openlr_dereferencer.maps.abstract.Line][source]

Yields all lines coming directly from this node

openlr_dereferencer.maps.abstract.path_length(lines: Iterable[openlr_dereferencer.maps.abstract.Line]) → float[source]

Length of a path in the map, in meters

openlr_dereferencer.maps.wgs84 module

Some geo coordinates related tools

openlr_dereferencer.maps.wgs84.bearing(point_a: openlr.locations.Coordinates, point_b: openlr.locations.Coordinates) → float[source]

Returns the angle between self and other relative to true north

The result of this function is between -pi, pi, including them

openlr_dereferencer.maps.wgs84.distance(point_a: openlr.locations.Coordinates, point_b: openlr.locations.Coordinates) → float[source]

Returns the distance of two WGS84 coordinates on our planet, in meters

openlr_dereferencer.maps.wgs84.project(point: openlr.locations.Coordinates, dist: float, angle: float) → openlr.locations.Coordinates[source]

Creates a new point that is dist meters away in direction angle

openlr_dereferencer.maps.wgs84.project_along_path(path: Sequence[openlr.locations.Coordinates], distance_meters: float) → openlr.locations.Coordinates[source]

Go distance meters along the path and return the resulting point

When the length of the path is too short, returns its last coordinate

Module contents

This module describes the handling of maps. It provides an interface through which the decoder accesses the map.