使用graphhopper(map-matching)进行地图匹配

  因为在做国创项目的时候需要进行地图匹配,在地图匹配的过程中也遇见了很多问题,在此记录,希望我的经历可以帮助大家规避一些问题,节约时间

在github上面有关地图匹配的开源项目有很多,我在此分享一下:

bmwcarit/barefoot: Java map matching library for integrating the map into software and services with state-of-the-art online and offline map matching that can be used stand-alone and in the cloud. (github.com)这个是barefoot,用java写的。因为在GitHub上面介绍的使用方式:它是在Unix系统上面运行的,所以在地图匹配的时候,我就没有使用它(但是因为java是跨平台语言,所以在Windows上面也可以运行,如果大家想使用barefoot也是可以的)

amillb/pgMapMatch: map-matching of GPS traces (github.com)

这个是pgMapMatch,语言是python。其实在进行地图匹配的时候,我首选是这个(因为我对python熟悉些),但是它的使用步骤比较麻烦。需要“使用 osm2po 将 OpenStreetMap 数据加载到 PostgreSQL 中”,如果使用其他的导入工具,可能会出现问题:在config.py中的街道名称和数据中的街道名称不一致,如果不一致,还需要自己改正。我在网上搜索osm2po的使用方法也没有搜索到,所以我也就放弃使用pgMapMatch了。

https://github.com/graphhopper/map-matching

这个就是我使用的开源包,graphhopper中的子项目map-matching,在使用过程中出现了一些问题,在此分享给大家

一、使用步骤

1、生成github tokens,并在maven的settings中添加github的tokens

这一步在graphhopper的GitHub的readme中没有介绍,但是这一步非常关键!!!

(在这里说一句题外话,因为我没有弄这个,然后在打jar包的时候,使用maven下载很多jar包都下载不了,我就一直找方法,找了很多方法都没有用,最后还是去graphhopper的社区里面找到了方法,哎,真的很痛苦,就是因为这个点,我卡了很久)下面我会具体说明怎么生成github tokens,并且怎么在setting中添加github的tokens

(1)生成github tokens

github 配置使用 personal access token 认证_惜鸟的博客-CSDN博客_personalaccesstoken

(2)在maven中配置settings

找到你maven的安装的位置,因为我是安装在D盘的,所以我的settings的位置是:D:\Maven\apache-maven-3.8.6\conf\settings.xml

并在settings中添加下面的东西

  <servers>                                                                                                                                                                                                                                                                   
    <!-- github packages needs a personal access token from *any* account even to read public packages... -->                                                                                                                                                                 
    <server>                                                                                                                                                                                                                                                                  
      <id>github</id>                                                                                                                                                                                                                                                         
      <username>你的github的用户名</username>                                                                                                                                                                                                                                             
      <password>GitHub tokens</password>                                                                                                                                                                                                           
    </server>                                                                                                                                                                                                                                                                 
  </servers>                                                                                                                                                                                                                                                                  
</settings>

注意:username是填写你的GitHub的用户名不是在申请GitHub tokens的时候填写的名字,GitHub tokens就是申请的时候系统生成的那一大串的字母数字(不要填错了!!!)

下面分享一下我的maven中的settings

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      http://maven.apache.org/xsd/settings-1.0.0.xsd">

  <activeProfiles>
    <activeProfile>github</activeProfile>
  </activeProfiles>

  <profiles>
    <profile>
      <id>github</id>
      <repositories>
        <repository>
          <id>central</id>
          <url>https://repo1.maven.org/maven2</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
        <repository>
          <id>github</id>
          <name>GitHub GraphHopper Apache Maven Packages</name>
          <url>https://maven.pkg.github.com/graphhopper/graphhopper</url>
        </repository>
      </repositories>
    </profile>
  </profiles>                                                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                                                              
  <servers>                                                                                                                                                                                                                                                                   
    <!-- github packages needs a personal access token from *any* account even to read public packages... -->                                                                                                                                                                 
    <server>                                                                                                                                                                                                                                                                  
      <id>github</id>                                                                                                                                                                                                                                                         
      <username>your username</username>                                                                                                                                                                                                                                             
      <password>your github tokens</password>                                                                                                                                                                                                           
    </server>                                                                                                                                                                                                                                                                 
  </servers>                                                                                                                                                                                                                                                                  
</settings>  

2、clone map-matching(下载map-matching包)

在cmd中输入(进入cmd是win+r)

git clone https://github.com/graphhopper/map-matching.git

3、打包

进入你下载包的位置,比如我下载到了D:\Workspace\GraphHopper\map-matching,那就输入

cd D:\Workspace\GraphHopper\map-matching

然后打包(输入下面的指令)

mvn package -DskipTests

4、生成 graph-cache

在网址:Index of /extracts/asia/china中下载你需要的.osm.pbf文件,然后输入下面的指令(注意改成你下载的文件的名称)

java -jar matching-web/target/graphhopper-map-matching-web-3.0-SNAPSHOT.jar import map-data/leipzig_germany.osm.pbf

 (import后面的就是需要改变的)

5、匹配

java -jar matching-web/target/graphhopper-map-matching-web-3.0-SNAPSHOT.jar match matching-web/src/test/resources/test1.gpx

 匹配完成之后会出现下面的输出

loading graph from cache
    matching-web\src\test\resources\test1.gpx
    matches: 138, gps entries:264
    gpx length: 9551.638 vs 9536.442
    export results to:D:\Workspace\GraphHopper\map-matching\matching-web\src\test\resources\test1.gpx.res.gpx
    gps import took:0.105556495s, match took: 0.36684602

输出的意思是匹配的结果输出在D:\Workspace\GraphHopper\map-matching\matching-web\src\test\resources\test1.gpx.res.gpx,然后你去查看就OK啦

二、在使用过程中可能的报错(下面的错误都是在打包的时候出现的)

1、

[ERROR] Failed to execute goal on project graphhopper-map-matching-core: Could n
ot resolve dependencies for project com.graphhopper:graphhopper-map-matching-cor
e:jar:2.0-SNAPSHOT: Failed to collect dependencies at com.graphhopper:graphhoppe
r-reader-osm:jar:4da82d9226e1ff9c5525fa3936204c7effc2fc8a: Failed to read artifa
ct descriptor for com.graphhopper:graphhopper-reader-osm:jar:4da82d9226e1ff9c552
5fa3936204c7effc2fc8a: Could not transfer artifact com.graphhopper:graphhopper-r
eader-osm:pom:4da82d9226e1ff9c5525fa3936204c7effc2fc8a from/to github (https://m 1
aven.pkg.github.com/graphhopper/graphhopper 1): Authentication failed for https://
maven.pkg.github.com/graphhopper/graphhopper/com/graphhopper/graphhopper-reader- 2
osm/4da82d9226e1ff9c5525fa3936204c7effc2fc8a/graphhopper-reader-osm-4da82d9226e1
ff9c5525fa3936204c7effc2fc8a.pom 401 Unauthorized -> [Help 1]

这个报错的出现就表明你的settings没有配置好,具体的解决方案,参见:

Recent Core Build Fails - Open Source Routing Engine / Map Matching - GraphHopper Forum

 2、

[WARNING] The POM for com.graphhopper:graphhopper-reader-osm:jar:0.9-SNAPSHOT is missing, no dependency information available

 出现这个报错的一般都是网络状态不好的,换成5G网络就可以解决,但是也可能是其他的问题,可以参见:

Error: Unable to access jarfile action=import - Open Source Routing Engine / Map Matching - GraphHopper Forum

3、

PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

出现这个错误我是没有想到的,我在网上搜索了很久,也使用了很多方法,都不行,搞了一天都没有把这个报错给解决,结果第二天再试的时候,电脑不知道怎么了,就直接不报错了。哎,真的是搞不懂,可能这个看运气?搞不懂

4、在打包的时候尽量不要使用阿里镜像,我使用阿里镜像的时候就一直报一个错误(忘了记录了),我不知道是我电脑的问题还是其他的问题,所以如果你们如果遇见报错中有提到阿里镜像的,可以尝试不使用阿里镜像,再来打包

三、祝福、分享

好了,以上就是我分享的全部内容了,希望大家能够顺利的完成地图匹配,下面分享一下我在搜索过程中遇见的比较好的一些地图匹配的博客

研究生work——地图匹配 · Mr.li's Blog (nymrli.top)

(GraphHopper)-MapMatching - 土博姜山山 - 博客园 (cnblogs.com)

地图匹配小结_第2梦的博客-CSDN博客_地图匹配

  • 8
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值