将静脉坐标转换为GPS [英] Converting Veins Coordinates to GPS
问题描述
我正在使用从 OpenStreetMap 导入的现实街道网络进行静脉模拟,例如Lara Codeca的卢森堡场景.现在,要准备可视化(使用Google Earth),我想将仿真中的车辆位置从SUMO或OmNET坐标导出到GPS坐标.
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.
作为材料,我具有用于生成场景的OSM文件,包括那里所有节点的GPS位置.我希望能找到一个从模拟坐标到GPS坐标的简单映射,例如,通过了解边界框和模拟运动场角的GPS坐标.
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.
是否有一种简单的转换方法?在生成运动场时,如何找到OSM转换使用的实际拐角?
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?
推荐答案
转换如下:
// 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()
为我返回了绝对的2D坐标,因此需要一个转换步骤.
getLonLat()
returned absolute 2D coordinates for me, so there is a conversion step required.
SUMO的.net.xml文件包含所需的转换. <location>
标记包含所需的属性netOffset
和projParameters
.
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.逆转转变
可以使用库 PROJ.4 进行反转.还提供了Python界面( pyproj ).
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)
如果只有相对位置信息可用,则必须先通过向其添加netOffset值来调整x,y值.
In case only the relative location information is available, the x, y values must be adjusted first by adding the netOffset values to them.
构建SUMO --with-proj-gdal
支持时仅第一步是必要的,getLonLat()
的结果将立即以所需的格式显示.
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.
这篇关于将静脉坐标转换为GPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!