Implementation:CARLA simulator Carla Road Interface
| Knowledge Sources | |
|---|---|
| Domains | Road Network, Simulation |
| Last Updated | 2026-02-15 05:00 GMT |
Overview
The Road class represents a single road segment in the OpenDRIVE road network, containing lane sections, geometry, elevation, and connectivity information.
Description
carla::road::Road is a MovableNonCopyable class that models one road element from the OpenDRIVE specification. Each road has:
- Identity -- a unique
RoadId, name, length, and whether it belongs to a junction - Lane sections -- a map of
LaneSectionobjects indexed by road-coordinate s, providing access to all lanes at any given distance along the road - Connectivity -- successor and predecessor road IDs, plus resolved next/previous road pointers
- Geometry and elevation -- accessed through templated
GetInfo<T>(s)methods that retrieveRoadInfoGeometry,RoadInfoElevation, and lane offset records - Directed points -- methods to compute center-line points with elevation and lane offset applied
- Nearest point/lane -- methods to find the closest point on the road and the nearest lane to a given location
The class uses an InformationSet to store heterogeneous road information records and a LaneSectionMap for efficient lane section lookup by distance.
Usage
Use this class when you need to query properties of a specific road segment, retrieve lanes at a given distance along the road, compute directed points on the road center line, or traverse the road's connectivity graph.
Code Reference
Source Location
- Repository: CARLA
- File:
LibCarla/source/carla/road/Road.h
Signature
class Road : private MovableNonCopyable {
public:
Road() = default;
const MapData *GetMap() const;
RoadId GetId() const;
std::string GetName() const;
double GetLength() const;
bool IsJunction() const;
JuncId GetJunctionId() const;
bool IsRHT() const;
Lane &GetLaneByDistance(double s, LaneId lane_id);
std::vector<Lane*> GetLanesByDistance(double s);
RoadId GetSuccessor() const;
RoadId GetPredecessor() const;
Lane &GetLaneById(SectionId section_id, LaneId lane_id);
Lane *GetNextLane(const double s, const LaneId lane_id);
Lane *GetPrevLane(const double s, const LaneId lane_id);
LaneSection *GetStartSection(LaneId id);
LaneSection *GetEndSection(LaneId id);
std::vector<Road *> GetNexts() const;
std::vector<Road *> GetPrevs() const;
element::DirectedPoint GetDirectedPointIn(const double s) const;
const std::pair<double, double> GetNearestPoint(const geom::Location &loc) const;
const std::pair<const Lane *, double> GetNearestLane(const double s, const geom::Location &loc, uint32_t type) const;
template <typename T> const T *GetInfo(const double s) const;
template <typename T> std::vector<const T*> GetInfos() const;
auto GetLaneSections() const;
auto GetLaneSectionsAt(const double s) const;
std::map<LaneId, const Lane *> GetLanesAt(const double s) const;
double UpperBound(double s) const;
};
Import
#include "carla/road/Road.h"
I/O Contract
| Input | Type | Description |
|---|---|---|
double | Distance along the road from its start
| ||
LaneId | Lane identifier (negative = right, positive = left, 0 = center)
| ||
geom::Location | 3D location for nearest-point queries
|
| Output | Type | Description |
|---|---|---|
element::DirectedPoint | 3D point with tangent, pitch on the road center line
| ||
Lane & | Reference to a lane at the specified position
| ||
pair<double, double> | (s distance, Euclidean distance) to nearest center point
|
Usage Examples
// Access a road from MapData
const auto &road = map_data.GetRoad(road_id);
// Get a directed point at distance s=50 along the road
auto dp = road.GetDirectedPointIn(50.0);
// Get all lanes at s=30
auto lanes = road.GetLanesAt(30.0);
// Find nearest lane to a location
auto [lane_ptr, dist] = road.GetNearestLane(50.0, location);