Implementation:CARLA simulator Carla Road Map Interface
| Knowledge Sources | |
|---|---|
| Domains | Road Network, Simulation |
| Last Updated | 2026-02-15 05:00 GMT |
Overview
The Map class provides the central interface for querying and navigating the road network in CARLA, built from OpenDRIVE map data with spatial indexing via an R-tree.
Description
carla::road::Map is a MovableNonCopyable class that wraps a MapData instance and builds a spatial R-tree index upon construction for efficient waypoint lookups. It provides comprehensive methods for:
- Waypoint generation -- generating waypoints at regular intervals, at road entries, and at lane topology boundaries
- Waypoint navigation -- finding successors, predecessors, next/previous waypoints at a given distance, and left/right lane neighbors
- Geometry queries -- computing transforms, lane widths, lane types, closest waypoints, and crosswalk zones
- Signal retrieval -- searching for traffic signals within a distance and returning all signal references
- Mesh generation -- building road meshes, junction meshes, crosswalk meshes, wall meshes, and line markings for visualization, with support for multithreaded and chunked generation
- Junction analysis -- computing junction conflicts, bounding boxes, and filtering junctions/roads by spatial position
The R-tree is constructed once at initialization via CreateRtree() and supports segment-based nearest-neighbor queries for efficient closest-waypoint resolution.
Usage
Use this class whenever you need to query the road network topology, generate waypoints for path planning, compute vehicle transforms relative to the road, or generate 3D mesh geometry from the OpenDRIVE data. It is the primary map abstraction used by the client API and the traffic manager.
Code Reference
Source Location
- Repository: CARLA
- File:
LibCarla/source/carla/road/Map.h
Signature
class Map : private MovableNonCopyable {
public:
using Waypoint = element::Waypoint;
Map(MapData m);
const geom::GeoLocation &GetGeoReference() const;
std::optional<element::Waypoint> GetClosestWaypointOnRoad(
const geom::Location &location, int32_t lane_type = ...) const;
std::optional<element::Waypoint> GetWaypoint(
const geom::Location &location, int32_t lane_type = ...) const;
std::optional<element::Waypoint> GetWaypoint(RoadId road_id, LaneId lane_id, float s) const;
geom::Transform ComputeTransform(Waypoint waypoint) const;
const Lane &GetLane(Waypoint waypoint) const;
Lane::LaneType GetLaneType(Waypoint waypoint) const;
double GetLaneWidth(Waypoint waypoint) const;
JuncId GetJunctionId(RoadId road_id) const;
bool IsJunction(RoadId road_id) const;
std::vector<Waypoint> GetSuccessors(Waypoint waypoint) const;
std::vector<Waypoint> GetPredecessors(Waypoint waypoint) const;
std::vector<Waypoint> GetNext(Waypoint waypoint, double distance) const;
std::vector<Waypoint> GetPrevious(Waypoint waypoint, double distance) const;
std::optional<Waypoint> GetRight(Waypoint waypoint) const;
std::optional<Waypoint> GetLeft(Waypoint waypoint) const;
std::vector<Waypoint> GenerateWaypoints(double approx_distance) const;
std::vector<std::pair<Waypoint, Waypoint>> GenerateTopology() const;
geom::Mesh GenerateMesh(const double distance, ...) const;
std::vector<std::unique_ptr<geom::Mesh>> GenerateChunkedMesh(...) const;
geom::Mesh GetAllCrosswalkMesh() const;
Junction* GetJunction(JuncId id);
std::vector<carla::geom::BoundingBox> GetJunctionsBoundingBoxes() const;
};
Import
#include "carla/road/Map.h"
I/O Contract
| Input | Type | Description |
|---|---|---|
MapData | Complete road network data (roads, junctions, signals, controllers)
| ||
geom::Location | Query point for waypoint lookups
| ||
int32_t | Bitmask filter for lane types (default: Driving)
| ||
double | Distance parameter for waypoint generation or traversal
|
| Output | Type | Description |
|---|---|---|
element::Waypoint | Discrete position on the road network (road_id, section_id, lane_id, s)
| ||
geom::Transform | 3D position and rotation on the road
| ||
geom::Mesh | Triangle mesh geometry for rendering
|
Usage Examples
// Build a map from OpenDRIVE data
auto map_opt = carla::opendrive::OpenDriveParser::Load(opendrive_xml);
auto &map = *map_opt;
// Find closest waypoint to a location
auto wp = map.GetWaypoint(geom::Location(10.0f, 20.0f, 0.0f));
if (wp) {
auto transform = map.ComputeTransform(*wp);
auto next_wps = map.GetNext(*wp, 5.0);
}
// Generate waypoints every 2 meters
auto all_waypoints = map.GenerateWaypoints(2.0);