Converting Veins Coordinates to GPS

2019-02-07 15:00发布

问题:

I am using realistic street networks imported from OpenStreetMap for simulations with Veins, for example the Luxembourg scenario from Lara Codeca. Now, to prepare a visualisation (using Google Earth), I want to export the vehicle positions in the simulation from SUMO or OmNET coordinates to GPS coordinates.

As material I have the OSM file used for generating the scenario, including the GPS positions of all nodes there. I was hoping to find a simple mapping from the simulation coordinates to GPS coordinates, for example, by knowing the GPS coordinates of the corners of the bounding box and the simulation playground.

Is there a simple way to make this conversion, and how can I find the actual corners that were used by the OSM conversion when generating the playground?

回答1:

The conversion works as follows:

1. Accessing the Location Information from OmNET

// Adapt your path to the mobility module here  
Veins::TraCIMobility* mobility =
  check_and_cast<Veins::TraCIMobility*>(
    getParentModule()->getSubmodule("veinsmobility"));

Veins::TraCICommandInterface* traci = mobility->getCommandInterface();

Coord currPos = mobility->getCurrentPosition();
std::pair<double, double> currLonLat = traci->getLonLat(currPos);

getLonLat() returned absolute 2D coordinates for me, so there is a conversion step required.

2. Finding the Transformation

The .net.xml file from SUMO contains the required transformation. The <location> tag contains the attributes netOffset and projParameters that are needed.

For the Luxembourg scenario, these are

netOffset="-285448.66,-5492398.13"
projParameter="+proj=utm +zone=32 +ellps=WGS84 +datum=WGS84 +units=m +no_defs"

3. Inversing the Transformation

The library PROJ.4 can be used to do the inversion. A Python interface is also available (pyproj).

import pyproj

projection = pyproj.Proj(
  "+proj=utm +zone=32 +ellps=WGS84 +datum=WGS84 +units=m +no_defs")

# x, y obtained from OmNET
lon, lat = projection(x, y, inverse=True)

In case only the relative location information is available, the x, y values must be adjusted first by adding the netOffset values to them.

Edit

Only the first step is necessary when you build SUMO --with-proj-gdal support, the result of getLonLat() will be in the desired format immediately.