注:实际使用发现,这个只是个warning,并不影响最终结果的输出,不需要修改,保留原样就好
今天在使用OpenStreetMap导出了osm格式的文件,想给Carla使用,就使用了官网的提供的Python代码来准换为xodr格式:
import io
# Read the .osm data
f = io.open("test", mode="r", encoding="utf-8")
osm_data = f.read()
f.close()
# Define the desired settings. In this case, default values.
settings = carla.Osm2OdrSettings()
# Set OSM road types to export to OpenDRIVE
settings.set_osm_way_types(["motorway", "motorway_link", "trunk", "trunk_link", "primary", "primary_link", "secondary", "secondary_link", "tertiary", "tertiary_link", "unclassified", "residential"])
# Convert to .xodr
xodr_data = carla.Osm2Odr.convert(osm_data, settings)
# save opendrive file
f = open("path/to/output/file", 'w')
f.write(xodr_data)
f.close()
运行后发现报错了:
Warning: Could not write OpenDRIVE geoReference. Only unshifted Coordinate systems are supported (center_map and use_offsets need to be set to False)
其实问题很简单,已经提示是 center_map 和 use_offsets 的问题,但是要先意识到要查官方文档,链接:https://carla.readthedocs.io/en/latest/python_api/
(我使用的Carla是最新的0.9.12版本,大概8月初更新的)
在Osm2OdrSettings的Instance Variables 可以看到这两个参数。
所以只需要在代码中加上settings.center_map =False;即可
修改后:
import io
# Read the .osm data
f = io.open("test", mode="r", encoding="utf-8")
osm_data = f.read()
f.close()
# Define the desired settings. In this case, default values.
settings = carla.Osm2OdrSettings()
# Set OSM road types to export to OpenDRIVE
settings.set_osm_way_types(["motorway", "motorway_link", "trunk", "trunk_link", "primary", "primary_link", "secondary", "secondary_link", "tertiary", "tertiary_link", "unclassified", "residential"])
#修改开始,添加新设置
settings.use_offsets =False;
settings.center_map =False;
#修改结束
# Convert to .xodr
xodr_data = carla.Osm2Odr.convert(osm_data, settings)
# save opendrive file
f = open("path/to/output/file", 'w')
f.write(xodr_data)
f.close()
附:
查看0.9.12的更新发现,center_map是这个版本才加入的变量:
所以无论在百度还是谷歌的相关的介绍和错误解决方法都很少, 记录下来给后来学习的人少踩坑。