igp2.opendrive.elements package

Submodules

igp2.opendrive.elements.eulerspiral module

class igp2.opendrive.elements.eulerspiral.EulerSpiral(gamma)[source]

Bases: object

calc(s, x0=0, y0=0, kappa0=0, theta0=0)[source]
Parameters:
  • s

  • x0 – (Default value = 0)

  • y0 – (Default value = 0)

  • kappa0 – (Default value = 0)

  • theta0 – (Default value = 0)

Returns:

static createFromLengthAndCurvature(length, curvStart, curvEnd)[source]

Create an EulerSpiral from a given length with curveStart and curvEnd. This is how the OpenDrive format specifies EulerSpirals.

Parameters:
  • length – Length of EulerSpiral.

  • curvStart – Curvature at start of EulerSpiral.

  • curvEnd – Curvature at end of EulerSpiral.

Returns:

A new Clothoid.

Return type:

EulerSpiral

igp2.opendrive.elements.geometry module

class igp2.opendrive.elements.geometry.Arc(start_position, heading, length, curvature)[source]

Bases: Geometry

This record describes an arc as part of the road’s reference line.

(Section 5.3.4.1.3 of OpenDRIVE 1.4)

calc_position(s_pos)[source]
Parameters:

s_pos

Returns:

class igp2.opendrive.elements.geometry.Geometry(start_position: float, heading: float, length: float)[source]

Bases: ABC

A road geometry record defines the layout of the road’s reference line in the in the x/y-plane (plan view).

The geometry information is split into a header which is common to all geometric elements.

(Section 5.3.4.1 of OpenDRIVE 1.4)

abstract calc_position(s_pos)[source]

Calculates the position of the geometry as if the starting point is (0/0)

Parameters:

s_pos

Returns:

property heading: float

Get heading of geometry.

Returns:

Heading, in which direction the geometry heads at start.

property length: float

Returns the overall geometry length

property start_position: Tuple[float, float]

Returns the starting position of the geometry in cartesian coordinates

class igp2.opendrive.elements.geometry.Line(start_position: float, heading: float, length: float)[source]

Bases: Geometry

This record describes a straight line as part of the road’s reference line.

(Section 5.3.4.1.1 of OpenDRIVE 1.4)

calc_position(s_pos)[source]
Parameters:

s_pos

Returns:

class igp2.opendrive.elements.geometry.ParamPoly3(start_position, heading, length, aU, bU, cU, dU, aV, bV, cV, dV, pRange)[source]

Bases: Geometry

This record describes a parametric cubic curve as part of the road’s reference line in a local u/v co-ordinate system.

This record describes an arc as part of the road’s reference line.

(Section 5.3.4.1.5 of OpenDRIVE 1.4)

calc_position(s_pos)[source]
Parameters:

s_pos

Returns:

class igp2.opendrive.elements.geometry.Poly3(start_position, heading, length, a, b, c, d)[source]

Bases: Geometry

This record describes a cubic polynomial as part of the road’s reference line.

(Section 5.3.4.1.4 of OpenDRIVE 1.4)

calc_position(s_pos)[source]
Parameters:

s_pos

Returns:

class igp2.opendrive.elements.geometry.Spiral(start_position, heading, length, curv_start, curv_end)[source]

Bases: Geometry

This record describes a spiral as part of the road’s reference line.

For this type of spiral, the curvature change between start and end of the element is linear.

(Section 5.3.4.1.2 of OpenDRIVE 1.4)

calc_position(s_pos)[source]
Parameters:

s_pos

Returns:

igp2.opendrive.elements.geometry.normalise_angle(angle)[source]

Normalise angle to the range [-pi, pi] in radians

igp2.opendrive.elements.geometry.ramer_douglas(curve: List[Tuple[float, float]], dist: float)[source]

Ramer-Douglas-Peucker simplification of a curve given a distance threshold.

Parameters:
  • curve – List of coordinate tuples describing the curve

  • dist – Distance threshold to merge points

Returns:

A simplified curve based on RDP.

igp2.opendrive.elements.junction module

class igp2.opendrive.elements.junction.Connection[source]

Bases: object

Object representing a Junction in the OpenDrive standard

Add a new LaneLink to the Junction

Parameters:

lane_link – The LaneLink object to add

property connecting_road

The connecting Road object

property contact_point: str

Contact point of the connecting road. Either ‘start’ or ‘end’

property id: int

Unique ID for the Connection

property incoming_road

The incoming Road object

List of LaneLinks between lanes of the incoming and connecting road

class igp2.opendrive.elements.junction.Junction[source]

Bases: object

Represents a Junction object in the OpenDrive standard

add_connection(connection: Connection)[source]

Add a new connection to the Junction

Parameters:

connection – The Connection object to add

add_priority(priority: JunctionPriority)[source]

Add a new priority field to the Junction

Parameters:

priority – The JunctionPriority object to add

property boundary

The boundary of the Junction formed as the union of all roads in the Junction

calculate_boundary()[source]

Calculate the boundary of the Junction given the list of roads in it

property connections: List[Connection]

The list of connections in the junction

get_all_connecting_lanes(incoming_lane: Lane) List[Lane][source]

Return all connecting lanes of the given incoming Lane.

Parameters:

incoming_lane – The incoming Lane object

Returns:

List of connecting Lanes

get_all_connecting_roads(incoming_road: Road) List[Road][source]

Return all connecting roads of the given incoming Road.

Parameters:

incoming_road – The incoming Road object

Returns:

List of all connecting roads

get_all_roads() List[Road][source]

Return all roads that are part of this Junction. Warning: This function assumes that all roads in the junction are connecting roads.

property id: int

Unique ID of the junction

property in_roundabout: bool

True if the junction is a roudabout junction.

property junction_group: JunctionGroup
property name: str

Name for the junction

property priorities: List[JunctionPriority]
property roads: List[Road]
class igp2.opendrive.elements.junction.JunctionGroup(name: str, group_id: int, group_type: str)[source]

Bases: object

A Junction group.

Reference: OpenDrive 1.6.1 - Section 10.5

add_junction(junction: Junction)[source]

Add a new Junction element to the group

Bases: object

Lane connections between the incoming road and the connecting road

property from_id: int

ID of lane on the incoming road

property to_id

ID of lane on the connecting road

property to_lane: Lane

ID of lane on the incoming road

class igp2.opendrive.elements.junction.JunctionPriority(high_id: int, low_id: int)[source]

Bases: object

Priority specification between incoming and connecting roads.

igp2.opendrive.elements.opendrive module

class igp2.opendrive.elements.opendrive.Header(rev_major: str | None = None, rev_minor: str | None = None, name: str | None = None, version: str | None = None, date: str | None = None, north: str | None = None, south: str | None = None, east: str | None = None, west: str | None = None, vendor: str | None = None, geo_reference: str | None = None, program: str | None = None)[source]

Bases: object

Dataclass holding header information of the OpenDrive file

date: str = None
east: str = None
geo_reference: str = None
name: str = None
north: str = None
program: str = None
rev_major: str = None
rev_minor: str = None
south: str = None
vendor: str = None
version: str = None
west: str = None
class igp2.opendrive.elements.opendrive.OpenDrive[source]

Bases: object

An object storing the parsed OpenDrive file

property controllers

Get all controllers of the OpenDrive file

get_junction(junction_id)[source]

Get a Junction object by ID

Parameters:

junction_id – The ID of the required Junction

Returns:

A Junction object or None

get_road(road_id)[source]

Get a Road object by ID

Parameters:

road_id – The ID of the required Road

Returns:

A Road object or None

property junction_groups
property junctions

Get all junctions of the OpenDrive file

property roads

Get all roads of the OpenDrive file

property stations

igp2.opendrive.elements.road module

class igp2.opendrive.elements.road.Road[source]

Bases: object

Road object of the OpenDrive standard (OpenDrive 1.6.1 - Section 8)

property all_lane_backwards: bool

True if all lanes are backwards directed on the road (e.g., all-left lanes in right-handed traffic).

property all_lane_forwards: bool

True if all lanes are forwards directed on the road (e.g., all-right lanes in right-handed traffic).

property boundary

Get the outer boundary of the road with all lanes

calculate_center_lane(resolution: float)[source]

Calculate center lane of the road by applying lane offsets and store them in the respective center lanes.

calculate_road_geometry(resolution: float = 0.25, fix_eps: float = 0.01)[source]

Calculate the boundary Polygon of the road. Calculates boundaries of lanes as a sub-function.

Parameters:
  • resolution – Sampling resolution for geometries

  • fix_eps – If positive, then the algorithm attempts to fix sliver geometry in the map with this threshold

distance_at(point: Point | Tuple[float, float] | ndarray) float[source]

Return the distance along the Road midline at the given point.

Parameters:

point – The point to check

Returns:

distance float

property drivable: bool

True if at least one lane is drivable in the road.

property elevation_profile: ElevationProfile
property id: int

Unique ID of the Road

property junction

Junction object if the Road is part of a junction

property lanes: Lanes

Container object for all LaneSections of the road

property lateral_profile: LateralProfile
property length
property midline: LineString

The Road midline

property name: str

Name of the Road

property plan_view: PlanView

PlanView describing the RoadGeometry of the Road in the OpenDrive standard (OpenDrive 1.6.1 - Section 7)

point_at(distance: float) ndarray[source]

Return the point along the Road midline at the given distance.

Parameters:

distance – The point to check

Returns:

1d numpy array

property types

igp2.opendrive.elements.road_elevation_profile module

class igp2.opendrive.elements.road_elevation_profile.ElevationProfile[source]

Bases: object

The elevation profile record contains a series of elevation records which define the characteristics of the road’s elevation along the reference line.

(Section 5.3.5 of OpenDRIVE 1.4)

class igp2.opendrive.elements.road_elevation_profile.ElevationRecord(*polynomial_coefficients: float, start_pos: float | None = None)[source]

Bases: RoadRecord

The elevation record defines an elevation entry at a given reference line position.

(Section 5.3.5.1 of OpenDRIVE 1.4)

igp2.opendrive.elements.road_lanes module

class igp2.opendrive.elements.road_lanes.CenterLanes[source]

Bases: LeftLanes

class igp2.opendrive.elements.road_lanes.Lane(parent_road, lane_section)[source]

Bases: object

Represent a single Lane of a LaneSection in the OpenDrive standard

property borders: List[LaneBorder]

Get all LaneBorders of this Lane

property boundary: Polygon

The boundary Polygon of the lane

distance_at(point: ndarray) float[source]

Return the distance along the Lane midline at the given point.

Parameters:

point – The point to check

Returns:

distance float

get_direction_at(ds: float) ndarray[source]

Gets the direction at a position along the lane

Parameters:

ds – Distance along the lane

Returns:

2d vector giving direction

get_heading_at(ds: float, lane_direction: bool = True) float[source]

Gets the heading at a distance along the lane using the parent road’s geometry.

Returns the final heading of the lane if the distance is larger than length of the parent Road.

Parameters:
  • ds – Distance along the lane

  • lane_direction – If True, then account for the direction of the lane in the heading. Else, just retrieve the heading of the parent road instead.

Returns:

Heading at given distance

get_last_lane_width_idx()[source]

Returns the index of the last width sector of the lane

get_width_at(ds: float) float[source]

Calculate lane width at the given distance

Returns the final width of the lane if ds is greater than lane length

Parameters:

ds – Distance along the lane

Returns:

Width at given distance or None if invalid distance

get_width_idx(width_idx) LaneWidth | None[source]

Get the LaneWidth object with the given index.

Parameters:

width_idx – The queried index

Returns:

LaneWidth with given index or None

property id: int

Unique identifier of the lane within its lane section

property lane_section: LaneSection

The LaneSection this Lane is contained in

property length
property level
property markers: List[LaneMarker]

Get all LaneMarkers of this Lane

property midline: LineString

Return a line along the center of the lane

property parent_road: Road

The Road this Lane is contained in

point_at(distance: float) ndarray[source]

Return the point along the Lane midline at the given distance.

Parameters:

distance – The point to check

Returns:

1d numpy array

property reference_line: LineString

Return the reference line of the lane. For right lane this is the right edge; for left lanes the left edge; for center lanes it is the road midline.

sample_geometry(sample_distances: ndarray, center_line: LineString, reference_segment: LineString, reference_widths: ndarray) Tuple[Polygon, LineString, ndarray][source]

Sample points of the lane boundary and midline.

Parameters:
  • sample_distances – The points to sample at

  • center_line – The center line of the road

  • reference_segment – The reference segment of the adjacent lane

  • reference_widths – The cumulative widths calculated from the road midline

Returns:

The lane boundary, lane midline, and the actual widths of the lane at each sample

traversable_neighbours()[source]
property type: str

Return the type of this Lane

property widths: List[LaneWidth]

List of LaneWidths describing the width of the lane along its length

class igp2.opendrive.elements.road_lanes.LaneBorder(*polynomial_coefficients: float, idx: int | None = None, start_offset: float | None = None)[source]

Bases: LaneWidth

Describe lane by width in respect to reference path.

(Section 5.3.7.2.1.2.0 of OpenDRIVE 1.4)

Instead of describing lanes by their width entries and, thus, invariably depending on influences of inner lanes on outer lanes, it might be more convenient to just describe the outer border of each lane independent of any inner lanes’ parameters.

Bases: object

Represent a Link between two Lanes in separate LaneSections

property predecessor: List[Lane]

The preceding Lane(s).

property predecessor_id: int

Lane ID of the preceding Lane

property successor: List[Lane]

The successor Lane(s)

property successor_id: int

Lane ID of the successor Lane

class igp2.opendrive.elements.road_lanes.LaneMarker(width: float, color: str, weight: str, type: str, idx: int, start_offset: float)[source]

Bases: object

Dataclass for storing RoadMarking data in the OpenDrive standard

color: str
property color_to_rgb
idx: int
property plot_width
start_offset: float
type: str
property type_to_linestyle
weight: str
width: float
class igp2.opendrive.elements.road_lanes.LaneOffset(*polynomial_coefficients: float, start_pos: float | None = None)[source]

Bases: RoadRecord

The lane offset record defines a lateral shift of the lane reference line (which is usually identical to the road reference line).

(Section 5.3.7.1 of OpenDRIVE 1.4)

class igp2.opendrive.elements.road_lanes.LaneSection(road=None)[source]

Bases: object

The lane section record defines the characteristics of a road cross-section. (Section 5.3.7.2 of OpenDRIVE 1.4)

property all_lanes: List[Lane]

Concatenate all lanes into a single array. Lanes are not sorted by id!

property center_lanes: List[Lane]

The center Lane of the LaneSection

property drivable: bool

True if the lane section has a driving lane.

get_lane(lane_id: int) Lane[source]

Get a Lane by its ID

Parameters:

lane_id – The ID of the Lane to look-up

property left_lanes: List[Lane]

Get list of sorted lanes always starting in the middle (lane id -1)

property parent_road

The Road in which this LaneSection is contained

property right_lanes: List[Lane]

Get list of sorted lanes always starting in the middle (lane id 1)

property single_side: bool

Indicator if lane section entry is valid for one side only.

property start_distance: float

Starting distance of the LaneSection along the Road

class igp2.opendrive.elements.road_lanes.LaneTypes[source]

Bases: object

BIDIRECTIONAL = 'bidirectional'
BIKING = 'biking'
BORDER = 'border'
CURB = 'curb'
DRIVING = 'driving'
ENTRY = 'entry'
EXIT = 'exit'
MEDIAN = 'median'
NONE = 'none'
OFFRAMP = 'offramp'
ONRAMP = 'onramp'
PARKING = 'parking'
RAIL = 'rail'
RESTRICTED = 'restricted'
ROADWORKS = 'roadworks'
SHOULDER = 'shoulder'
SIDEWALK = 'sidewalk'
SPECIAL1 = 'special1'
SPECIAL2 = 'special2'
SPECIAL3 = 'special3'
STOP = 'stop'
TRAM = 'tram'
all_types = ['none', 'driving', 'stop', 'shoulder', 'biking', 'sidewalk', 'border', 'restricted', 'parking', 'bidirectional', 'median', 'special1', 'special2', 'special3', 'roadWorks', 'curb', 'tram', 'rail', 'entry', 'exit', 'offRamp', 'onRamp']
class igp2.opendrive.elements.road_lanes.LaneWidth(*polynomial_coefficients: float, idx: int | None = None, start_offset: float | None = None)[source]

Bases: RoadRecord

Entry for a lane describing the width for a given position. (Section 5.3.7.2.1.2.0 of OpenDRIVE 1.4)

start_offset being the offset of the entry relative to the preceding lane section record

property constant_width
property start_offset

Return start_offset, which is the offset of the entry to the start of the lane section.

width_at(ds: float) float[source]

Return the width of the lane at ds.

Parameters:

ds – Distance along the lane

Returns:

Distance at ds

class igp2.opendrive.elements.road_lanes.Lanes[source]

Bases: object

Collection class for LaneSections of a Road

get_lane_section(lane_section_idx)[source]

Get a LaneSection by index

Parameters:

lane_section_idx – The index of the LaneSection to look-up

get_last_lane_section_idx()[source]

Get the index of the last LaneSection in this Road

property lane_offsets

Offsets of LaneSections

property lane_sections: List[LaneSection]

Return all LaneSections sorted from start of the Road to its end

class igp2.opendrive.elements.road_lanes.LeftLanes[source]

Bases: object

property lanes
sort_direction = False
class igp2.opendrive.elements.road_lanes.RightLanes[source]

Bases: LeftLanes

sort_direction = True

igp2.opendrive.elements.road_lateral_profile module

class igp2.opendrive.elements.road_lateral_profile.Crossfall(*polynomial_coefficients: float, start_pos: float | None = None, side: str | None = None)[source]

Bases: RoadRecord

The crossfall of the road is defined as the road surface ́s angle relative to the t-axis.

(Section 5.3.6.2 of OpenDRIVE 1.4)

property side: str

The side of the crossfall.

Returns:

The side as a string.

Note

Setter only allows to set the side for ‘left’, ‘right’ or ‘both’.

class igp2.opendrive.elements.road_lateral_profile.LateralProfile[source]

Bases: object

The lateral profile record contains a series of superelevation and crossfall records which define the characteristics of the road surface’s banking along the reference line.

(Section 5.3.6 of OpenDRIVE 1.4)

property crossfalls

Crossfalls of a LateralProfile.

property shapes
property superelevations

The superelevations of a LateralProfile.

class igp2.opendrive.elements.road_lateral_profile.Shape(*polynomial_coefficients: float, start_pos: float | None = None, start_pos_t: float | None = None)[source]

Bases: RoadRecord

The shape of the road is defined as the road section’s surface relative to the reference plane.

This shape may be described as a series of 3 order polynomials for a given “s” station.

The absolute position of a shape value is calculated by:

t = start_pos_t + dt

h_shape is the height above the reference path at a given position and is calculated by:

h_shape = a + b*dt + c*dt² + d*dt³

dt being the distance perpendicular to the reference line between the start of the entry and the actual position.

(Section 5.3.6.3 of OpenDRIVE 1.4)

class igp2.opendrive.elements.road_lateral_profile.Superelevation(*polynomial_coefficients: float, start_pos: float | None = None)[source]

Bases: RoadRecord

The superelevation of the road is defined as the road section’s roll angle around the s-axis.

(Section 5.3.6.1 of OpenDRIVE 1.4)

igp2.opendrive.elements.road_plan_view module

class igp2.opendrive.elements.road_plan_view.PlanView[source]

Bases: object

The plan view record contains a series of geometry records which define the layout of the road’s reference line in the x/y-plane (plan view).

(Section 5.3.4 of OpenDRIVE 1.4)

add_arc(start_pos, heading, length, curvature)[source]
Parameters:
  • start_pos

  • heading

  • length

  • curvature

add_line(start_pos, heading, length)[source]
Parameters:
  • start_pos

  • heading

  • length

add_param_poly3(start_pos, heading, length, aU, bU, cU, dU, aV, bV, cV, dV, pRange)[source]
Parameters:
  • start_pos

  • heading

  • length

  • aU

  • bU

  • cU

  • dU

  • aV

  • bV

  • cV

  • dV

  • pRange

add_poly3(start_pos, heading, length, a, b, c, d)[source]
Parameters:
  • start_pos

  • heading

  • length

  • a

  • b

  • c

  • d

add_spiral(start_pos, heading, length, curve_start, curve_end)[source]
Parameters:
  • start_pos

  • heading

  • length

  • curve_start

  • curve_end

calc(s_pos: float) Tuple[ndarray, float][source]

Calculate position and tangent at s_pos.

Either interpolate values if it possible or delegate calculation to geometries.

Parameters:

s_pos – Position on PlanView in ds.

Returns:

Position (x,y) in cartesian coordinates. Tangent in radians at position s_pos in range [-pi, pi].

calc_geometry(s_pos: float) Tuple[ndarray, float][source]

Calc position and tangent at s_pos by delegating calculation to geometry.

Parameters:

s_pos – Position on PlanView in ds.

Returns:

Position (x,y) in cartesian coordinates. Angle in radians at position s_pos.

property end_position: ndarray
property geometries: List[Geometry]

Return the list of geometric objects that define the road layout.

interpolate_angle(idx: int, s_pos: float) float[source]

Interpolate two angular values using the shortest angle between both values.

Parameters:
  • idx – Index where values in _precalculation should be accessed.

  • s_pos – Position at which interpolated angle should be calculated.

Returns:

Interpolated angle in radians.

interpolate_cached_values(s_pos: float) Tuple[ndarray, float][source]

Calc position and tangent at s_pos by interpolating values in _precalculation array.

Parameters:

s_pos – Position on PlanView in ds.

Returns:

Position (x,y) in cartesian coordinates. Angle in radians at position s_pos.

property length: float

Get length of whole plan view

property midline: LineString

The midline of the entire road geometry

precalculate(precision: float = 0.25, linestring: bool = False)[source]

Precalculate coordinates of planView to save computing resources and time. Save result in _precalculation array.

Parameters:
  • precision – Precision with which to calculate points on the geometry

  • linestring – True if pre-calculation should also be stored as a LineString into the field midline. Overrides the should_precalculate flag

property start_position: ndarray

igp2.opendrive.elements.road_record module

class igp2.opendrive.elements.road_record.RoadRecord(*polynomial_coefficients: float, start_pos: float | None = None)[source]

Bases: ABC

Abstract base class to model Records (e.g. ElevationRecord) of the OpenDRIVE specification.

These Records all have attributes start_pos, a, b, c, d. The attribute attr which is defined the RoadRecord at a given reference line position is calculated with the following equation: attr = a + b*ds + c*ds² + d*ds³ where ds being the distance along the reference line between the start of the entry and the actual position.

ds starts at zero for each RoadRecord.

The absolute position of an elevation value is calculated by

s = start_pos + ds

start_pos

Position in curve parameter ds where the RoadRecord starts.

polynomial_coefficients

List of values [a, b, c, d, …] which can be evaluated with an polynomial function.

property start_offset: float

igp2.opendrive.elements.road_type module

class igp2.opendrive.elements.road_type.RoadType(s_pos=None, use_type=None, speed=None)[source]

Bases: object

allowedTypes = ['unknown', 'rural', 'motorway', 'town', 'lowSpeed', 'pedestrian', 'bicycle']
property speed
property start_pos
property use_type
class igp2.opendrive.elements.road_type.Speed(max_speed=None, unit=None)[source]

Bases: object

property max
property unit

Module contents