Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zuo1188/ded6d2c12533af5e0934c86e7984bbce to your computer and use it in GitHub Desktop.
Save zuo1188/ded6d2c12533af5e0934c86e7984bbce to your computer and use it in GitHub Desktop.
osrm 安装与部署
1.OSRM及前端工具安装部署与调试
1.1 OSRM安装
代码下载(https://github.com/Project-OSRM/osrm-backend)
安装依赖库
sudo apt install build-essential git cmake pkg-config \
libbz2-dev libstxxl-dev libstxxl1v5 libxml2-dev \
libzip-dev libboost-all-dev lua5.2 liblua5.2-dev libtbb-dev
编译安装
mkdir -p build
cd build
cmake ..
cmake --build .
sudo cmake --build . --target install
安装测试
#下载测试数据
wget http://download.geofabrik.de/europe/germany/berlin-latest.osm.pbf
#编译数据
osrm-extract berlin-latest.osm.pbf -p profiles/car.lua
osrm-contract berlin-latest.osrm
osrm-routed berlin-latest.osrm
#测试访问
curl http://127.0.0.1:5000/route/v1/driving/13.388860,52.517037;13.385983,52.496891?steps=true
1.2 OSRM调试环境
下载OSRM前端代码 (https://github.com/Project-OSRM/osrm-frontend.git)
在webstrom中打开相关代码
修改osrm服务地址
#src/leaflet_options.js
services: [{
label: 'Car (fastest)',
path: 'http://localhost:5000/route/v1'
}],
在webstorm的终端中执行npm install 和npm start
打开http://localhost:9966,在地图上选择起止点查看规划路线。
1.3 OSRM试验数据准备
将四维数据中的R R_LName R_Name Z_Level BL根据需要在QGIS里进行裁剪,同时将对应的osm数据进行导出,方便进行交叉对比。
1.4 安装OSM转换脚本
下载转换脚本代码(https://github.com/andrewguertin/ogr2osm.git)
安装配套的gdal库
运行脚本将测试数据导出为osm文件
使用osrm的命令将osm文件转换成osrm导航数据
2.实现方法
2.1 总体思路
为验证方案可行并尽可能简化实现方法,目前采取的思路是将四维数据通过ogr2osm脚本先转换成osm,然后将osm转换成导航数据osrm格式,然后进行发布使用。
2.2 技术路线
对比研究四维和osm数据组织格式
研究四维数据向osm数据转换的方法及各字段的对应方式
实现道路等级、路名提示、单行等基本道路规则的规划
2.3 主要原理
目前数据主要使用R R_LName R_Name Z_Level BL等数据集
道路类型:转换时需要将R中的kind字段转换到osm中的“highway”字段
if strKind == "00" or strKind == '01':
tags['highway'] ="motorway"elif strKind == "02":
tags['highway'] = "trunk" if strKind2 == "0b":
tags['highway'] = "trunk_link"elif strKind == "03":
tags['highway'] = "primary" if strKind2 == "0b":
tags['highway'] = "primary_link"elif strKind == "04":
tags['highway'] = "secondary"elif strKind == "05":
tags['highway'] = "tertiary"elif strKind == "06":
tags['highway'] = "unclassified"elif strKind == "08":
tags['highway'] = "residential"elif strKind == "0a":
tags['highway'] = "living_street"elif strKind == "0b":
tags['highway'] = "service"
增加单行处理:将R中的Direction字段转换到osm中的“oneway”字段
if strDirection == '0' or strDirection == '1':
tags['oneway'] = 'no' tags['rDirection'] = 'no'elif strDirection == '2':
tags['oneway'] = 'yes' tags['rDirection'] = 'no'elif strDirection == '3':
tags['oneway'] = 'yes' tags['rDirection'] = 'yes'else:
tags['oneway'] = 'no' tags['rDirection'] = 'no'
路线翻转:根据R中的Direction字段将道路数据中的节点翻转,保证路网的连通性
if way in featuresmap:
if featuresmap[way].tags['oneway'] == 'yes' and featuresmap[way].tags['rDirection'] == 'yes':
way.points.reverse()
上下层道路处理:分别根据Z_Level数据集和BL数据集中获取节点的分层和连接关系,对于不在一层的节点不合并,使得上下层道路正确连接,同时根据BL中的道路连接关系保证相连接的道路使用的为同一个节点。
立交桥处理:立交桥处理方式参照上下层道路处理,但是立交桥道路在四维中为多线数据,需要将多线数据转化成单线数据,同时交叉点不合并。
路名处理:根据道路数据的ID在R_LName R_Name中查询道路名,同时需要注意字符编码。
layer1 = dataSource1.GetLayer()
layer2 = dataSource2.GetLayer()
layer1.SetAttributeFilter("ID = '"+ strID + "'" );
strRouteID = "";
for feature in layer1:
strRouteID = feature.GetFieldAsString("Route_ID");
if strRouteID != "":
layer2.SetAttributeFilter("Route_ID = '"+ strRouteID + "'" + "and Language = '1'")
for feature in layer2:
tags['name'] = unicode(feature.GetFieldAsString("PathName"),'gbk')
3.目前进展
完成测试数据到服务发布的流程测试
基本了解osm及四维的数据格式
完成测试数据到osm数据的转换,考虑了道路等级、路名提示、单行、立交桥、上下级道路桥等情况,基本满足路径规划使用
4.后续工作
4.1遗留问题
现有转换OSM代码比较混乱,需要进行重构
现有代码没有考虑大数据量情况下内存使用、性能等问题,需要测试优化
大数据量路名数据及关联数据的查询效率比较低,需要改造成数据库形式
现有方法为将四维shp数据转换为osm数据,然后再转换成导航数据,中间数据转换耗费时间需要编写引擎使其直接支持四维数据
4.2工作安排
将数据导入到Posgress SQL数据库
整理现有代码,使其能够支持数据库查询
整理现有代码,优化代码结构,使其可支持大批量数据的处理
结合黑龙江的数据转换出一套完整的导航数据
结合转换的导航数据进行详细的测试,并完善代码
编写OSRM数据转换工具,直接将四维数据转换成导航数据格式
@luqinghui
Copy link

您好,我最近也在研究OSRM使用四维数据,也是希望能够将数据转换为osm格式,看完您的记录之后,发现我拿到的数据中没有您方法中所用到的R R_LName R_Name Z_Level BL 等数据集。我所获得数据包含一个Streets.shp图层,属性中也没有表明道路类型的字段,而随数据的文档中写着Streets.shp可用于导航。我想咨询一下,您是否遇到过这样的情况?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment