Implementation:CARLA simulator Carla Python Map Bindings
| Knowledge Sources | |
|---|---|
| Domains | Python Bindings, Map and Navigation |
| Last Updated | 2026-02-15 05:00 GMT |
Overview
Boost.Python binding file that exposes the CARLA Map, Waypoint, Junction, Landmark, and lane marking types to the Python API.
Description
This file defines the export_map() function that registers map-related C++ classes with Boost.Python. It exposes extensive enumerations including LaneType (Driving, Stop, Shoulder, Biking, Sidewalk, and many more), LaneChange (None, Right, Left, Both), LaneMarkingColor, LaneMarkingType (Broken, Solid, SolidSolid, etc.), and LandmarkOrientation. The Map class provides get_spawn_points, get_waypoint, get_waypoint_xodr, get_topology, generate_waypoints, transform_to_geolocation, to_opendrive, save_to_disk, get_crosswalks, landmark queries, and cook_in_memory_map. The Waypoint class exposes road/lane IDs, transform, width, lane change info, lane type, lane markings, and navigation methods (next, previous, next_until_lane_end, get_right_lane, get_left_lane). Junction provides bounding box and waypoint pairs. Landmark contains road signal metadata (type, subtype, value, orientation, etc.) and LandmarkType offers static properties for common signal types.
Usage
This binding is essential for route planning, waypoint navigation, lane exploration, and extracting road network topology from OpenDRIVE maps in CARLA.
Code Reference
Source Location
- Repository: CARLA
- File: PythonAPI/carla/src/Map.cpp
Signature
void export_map();
// Key classes exposed:
class_<cc::Map>("Map", no_init)
class_<cc::Waypoint>("Waypoint", no_init)
class_<cc::Junction>("Junction", no_init)
class_<cc::Landmark>("Landmark", no_init)
class_<cre::LaneMarking>("LaneMarking", no_init)
class_<cr::SignalType>("LandmarkType", no_init)
Import
import carla
world = client.get_world()
carla_map = world.get_map()
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| location | carla.Location | Yes (get_waypoint) | Query location to find nearest waypoint |
| project_to_road | bool | No | Whether to project to nearest road (default: True) |
| lane_type | carla.LaneType | No | Lane type filter (default: Driving) |
| distance | float | Yes (next/previous/generate_waypoints) | Distance in meters for waypoint queries |
Outputs
| Name | Type | Description |
|---|---|---|
| waypoint | carla.Waypoint | Closest waypoint to query location |
| spawn_points | list[carla.Transform] | Recommended spawn points on the map |
| topology | list[tuple] | List of (start_waypoint, end_waypoint) pairs |
| landmarks | list[carla.Landmark] | Road landmarks/signals found |
Usage Examples
import carla
client = carla.Client('localhost', 2000)
world = client.get_world()
carla_map = world.get_map()
# Get spawn points
spawn_points = carla_map.get_spawn_points()
# Query nearest waypoint
wp = carla_map.get_waypoint(carla.Location(x=100, y=200, z=0))
print(f"Road: {wp.road_id}, Lane: {wp.lane_id}")
# Navigate forward
next_wps = wp.next(2.0)
# Get topology
topology = carla_map.get_topology()
# Save OpenDRIVE to disk
carla_map.save_to_disk('my_map.xodr')