export

Export road network to OpenDRIVE

Description

example

export(scenario,'OpenDRIVE',filename) exports the roads, lanes, and junctions in a driving scenario to the OpenDRIVE® 1.4H file format. There may be variations between the original scenario and the exported scenario. For details, see Limitations.

Examples

collapse all

Create a driving scenario.

inputScenario = drivingScenario;

Import a OpenStreetMap road network into the driving scenario. For more information about the osm file, see [1].

fileName = 'chicago.osm';
roadNetwork(inputScenario,'OpenStreetMap',fileName);

Export to OpenDRIVE file.

fileName = 'chicago.xodr';
export(inputScenario,'OpenDRIVE',fileName);
Warning: There may be minor variation between the actual driving scenario and the exported OpenDRIVE road networks. For more information, see <a href="matlab:helpview(fullfile(docroot,'toolbox','driving','helptargets.map'),'exportOpenDriveCLI')">export</a>.

Read the exported OpenDRIVE file by using the roadNetwork function.

scenario = drivingScenario;
roadNetwork(scenario,'OpenDRIVE',fileName);

Plot the exported scenario. Notice that the display for the exported road network is flipped along the x and y dimensions and does not have the border lines.

figure
plot(inputScenario)
zoom(2);
title('Actual Scenario')

figure
plot(scenario)
zoom(2);
title('Exported Scenario')

Appendix

[1] The osm file is downloaded from https://www.openstreetmap.org, which provides access to crowd-sourced map data all over the world. The data is licensed under the Open Data Commons Open Database License (ODbL), https://opendatacommons.org/licenses/odbl/.

Create the driving scenario with one road having an S-curve.

scenario = drivingScenario;
roadcenters = [-35 20 0; -20 -20 0; 0 0 0; 20 20 0; 35 -20 0];

Create the lanes and add them to the road.

lm = [laneMarking('Solid','Color','w') ...
     laneMarking('Dashed','Color','y') ...
     laneMarking('Dashed','Color','y') ...
     laneMarking('Solid','Color','w')];
ls = lanespec(3,'Marking',lm);
road(scenario,roadcenters,'Lanes',ls);

Plot the scenario.

plot(scenario)

Export the road network in the scenario to OpenDRIVE file.

fileName = 'scurveroad.xodr';
export(scenario,'OpenDRIVE',fileName)
Warning: There may be minor variation between the actual driving scenario and the exported OpenDRIVE road networks. For more information, see <a href="matlab:helpview(fullfile(docroot,'toolbox','driving','helptargets.map'),'exportOpenDriveCLI')">export</a>.

You can import the OpenDRIVE file to MATLAB workspace by using the roadNetwork function.

scenario = drivingScenario;
roadNetwork(scenario,'OpenDRIVE',fileName)
plot(scenario)

Input Arguments

collapse all

Driving scenario, specified as a drivingScenario object. The driving scenario must contain one or more road networks in order to export it to the OpenDRIVE file format.

If the driving scenario does not have lane specifications, then the export function assigns a default lane specification while exporting to the OpenDRIVE file format.

Name of the destination OpenDRIVE file, specified as a character vector or string scalar. You can specify the file name with or without the file extension. If you choose to specify a file extension, the file extension must be either .xodr or .xml. The function uses .xodr as the default. If the specified file name, including the file extension already exists, then the function overwrites the data in the existing file with the road network specified in the scenario argument.

Data Types: char | string

Limitations

  • The export function does not export the actors and their properties from the original scenario to the OpenDRIVE format.

  • The cubic polynomial and the parametric cubic polynomial geometry types in the scenario are exported as spiral geometry types. This causes some variations in the exported road geometry if the road is a curved road. For example, in the figure below, notice that the sharp corners in the input road became relatively smooth when exported to the OpenDRIVE format.

    Input RoadExported OpenDRIVE Road

    Original road

    Exported road

  • The junctions of the road network are processed without lane connection information and so, the junction shapes may not be accurate in the exported scenario.

    Input RoadExported OpenDRIVE Road

    Original junction

    Exported junction

  • The limitations in OpenDRIVE import applies to OpenDRIVE export, if you export a driving scenario object that contains an imported OpenDRIVE scenario. You can import an OpenDRIVE scenario to a drivingScenario object by using the roadNetwork function. For information on limitations in OpenDRIVE import, see roadNetwork.

Introduced in R2020b