Implementation:CARLA simulator Carla Road
| Knowledge Sources | |
|---|---|
| Domains | Road Network, OpenDRIVE, Geometry |
| Last Updated | 2026-02-15 05:00 GMT |
Overview
Road represents a single road segment in the CARLA road network, providing access to its lanes, geometry, elevation, and connectivity with neighboring roads.
Description
The Road class (in carla::road, implementation in Road.cpp, 322 lines) models an individual road segment as defined by the OpenDRIVE specification. Each road has a unique RoadId, a reference line geometry, elevation profiles, lane sections, and connectivity to predecessor/successor roads.
Basic Properties:
- GetId() - Returns the unique road identifier
- GetName() - Returns the human-readable road name
- GetLength() - Returns the total length of the road reference line in meters
- IsJunction() - Indicates if this road is part of a junction
- GetJunctionId() - Returns the junction ID (if applicable)
- IsRHT() - Indicates if the road uses right-hand traffic convention
- GetSuccessor() / GetPredecessor() - Returns the IDs of connected roads
- GetNexts() / GetPrevs() - Returns pointers to the actual successor/predecessor road objects
Lane Access:
- GetLaneByDistance(double s, LaneId lane_id) - Finds a lane at a specific s-coordinate by iterating through lane sections at that distance
- GetLanesByDistance(double s) - Returns all lanes across all lane sections at a given s-coordinate
- GetLaneById(SectionId, LaneId) - Direct lane lookup by section and lane ID
- GetNextLane(double s, LaneId) - Finds the same lane ID in the next lane section after s
- GetPrevLane(double s, LaneId) - Finds the same lane ID in the previous lane section before s
- GetStartSection(LaneId) / GetEndSection(LaneId) - Returns the first/last lane section containing the specified lane
Geometry and Elevation:
- GetElevationOn(double s) - Returns the cubic polynomial elevation profile at distance s, throwing an exception if no elevation data exists
- GetDirectedPointIn(double s) - Computes a 3D point with heading on the road center (lane 0), applying lane offset and elevation records. This uses the road's geometry (line, arc, spiral, polynomial) to compute the reference line position, then adds the lane offset laterally and elevation vertically.
- GetDirectedPointInNoLaneOffset(double s) - Same as above but without applying the lane offset record
- GetNearestPoint(geom::Location) - Returns the s-distance and Euclidean distance from a world location to the nearest point on the road center line. Uses binary search on the geometry for arc/spiral types and analytical computation for lines.
- GetNearestLane(double s, geom::Location, uint32_t lane_type) - Finds the closest lane to a given location at distance s, filtered by lane type bitmask
Lane Section Iteration: The class provides methods to iterate over its LaneSectionMap (a multimap keyed by s-coordinate):
- GetLaneSections() - Returns iteratable views of all lane sections
- GetLaneSectionsAt(double s) - Returns lane sections that contain the given s-coordinate
Usage
Use Road to query properties of individual road segments in the network. It is accessed through the Map class, which holds the collection of all roads. The Road class is central to waypoint resolution, path planning, and mesh generation operations.
Code Reference
Source Location
- Repository: CARLA
- File:
LibCarla/source/carla/road/Road.cpp - Lines: 1-322
Signature
namespace carla {
namespace road {
class Road : private MovableNonCopyable {
public:
Road() = default;
// Properties
const MapData *GetMap() const;
RoadId GetId() const;
std::string GetName() const;
double GetLength() const;
bool IsJunction() const;
JuncId GetJunctionId() const;
bool IsRHT() const;
RoadId GetSuccessor() const;
RoadId GetPredecessor() const;
std::vector<Road *> GetNexts() const;
std::vector<Road *> GetPrevs() const;
// Lane access
Lane &GetLaneByDistance(double s, LaneId lane_id);
const Lane &GetLaneByDistance(double s, LaneId lane_id) const;
std::vector<Lane *> GetLanesByDistance(double s);
std::vector<const Lane *> GetLanesByDistance(double s) const;
Lane &GetLaneById(SectionId section_id, LaneId lane_id);
const Lane &GetLaneById(SectionId section_id, LaneId lane_id) const;
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);
// Geometry
const geom::CubicPolynomial &GetElevationOn(const double s) const;
element::DirectedPoint GetDirectedPointIn(const double s) const;
element::DirectedPoint GetDirectedPointInNoLaneOffset(const double s) const;
std::pair<double, double> GetNearestPoint(const geom::Location &loc) const;
std::pair<const Lane *, double> GetNearestLane(
const double s, const geom::Location &loc, uint32_t lane_type) const;
};
} // namespace road
} // namespace carla
Import
#include "carla/road/Road.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| s | double |
Yes | Distance along the road reference line in meters |
| lane_id | LaneId |
Yes | Identifier of the target lane (negative for right, positive for left, 0 for center) |
| section_id | SectionId |
Yes | Lane section identifier for direct lane lookup |
| loc | geom::Location |
Yes | 3D world position for nearest-point queries |
| lane_type | uint32_t |
No | Bitmask filter for lane types in nearest-lane queries |
Outputs
| Name | Type | Description |
|---|---|---|
| Lane & | Lane & |
Reference to the matching lane object |
| DirectedPoint | element::DirectedPoint |
3D point with heading on the road center line |
| NearestPoint | std::pair<double, double> |
(s-distance, Euclidean distance) to closest point on road |
| NearestLane | std::pair<const Lane *, double> |
Pointer to closest lane and its distance |
| CubicPolynomial | geom::CubicPolynomial |
Elevation polynomial at the queried s-coordinate |
Usage Examples
Querying Road Properties
#include "carla/road/Road.h"
// Access basic road properties
RoadId id = road.GetId();
double length = road.GetLength();
bool is_junction = road.IsJunction();
bool is_rht = road.IsRHT();
Accessing Lanes at a Position
// Get a specific lane at s = 50 meters
Lane &driving_lane = road.GetLaneByDistance(50.0, -1);
// Get all lanes at s = 50 meters
std::vector<Lane *> all_lanes = road.GetLanesByDistance(50.0);
for (auto *lane : all_lanes) {
// Process each lane
}
Computing a Point on the Road
// Get a 3D point with heading at s = 100 meters on the road center
auto directed_point = road.GetDirectedPointIn(100.0);
// directed_point contains location (x, y, z) and tangent heading
// Get elevation at a point
const auto &elevation = road.GetElevationOn(100.0);
double height = elevation.Evaluate(100.0);