GPS地图生成02之经典算法体验
经典的利用轨迹生成地图的算法与数据集可寻找于:Mapconstruction by pfoser
Mapconstruction by pfoser数据集中,雅典数据集投影坐标系为(UTM, GGRS87),EPSG为2100,芝加哥数据集投影坐标系为(NAD83 / UTM zone 16N),EPSG为26916,柏林数据集投影坐标系为(ETRS89 / UTM zone 33N),EPSG为25833
此处笔者介绍Ahmed、Karagiorgou与Biagioni的算法
1. Ahmed算法
此算法基于增量合并的方式,不断加入新的轨迹进行匹配,得到新的路网
代码可下载自:GitHub - pfoser/mapconstruction: Map Construction Algorithms
代码基于Java构建和shell脚本,最好是在安装有Java环境的Linux或者Mac平台上运行
切换到Ahmed
目录下,编辑script_to_run.sh
文件:
#To Compile: CODE_PATH="MapConstruction/" #path to the MapConstruction folder. cd $CODE_PATH javac -d bin/ src/mapconstruction2/*.java #To Run: INPUT_PATH="" #path to the folder that constains all input tracks OUTPUT_PATH="" #path to the folder where output will be written EPS=150.0 #epsilon in meters HAS_ALTITUDE=false #if input file has altitude information ALT_EPS=4.0 #minimum altitude difference in meters between two streets java -cp bin/ mapconstruction2.MapConstruction $INPUT_PATH $OUTPUT_PATH $EPS $HAS_ALTITUDE $ALT_EPS
设置好路径与参数,运行script_to_run.sh脚本,等待程序结束
2. Karagiorgou算法
此算法基于交叉口连接,找出道路中的交叉口进行连接,得到路网
代码可下载自:GitHub - pfoser/mapconstruction: Map Construction Algorithms
代码基于Matlab构建
代码运行步骤在代码的README.txt
中已经详细说明
1) Add the two directories /source and /libraries to the current working path of the MATLAB 2) The source code is in the /source directory 3) The trajectory files should be in the form of: <x y timestamp> 4) You should firstly run the intersection_nodes_extraction.m file This file loads trajectories and generates intersection nodes 5) You should then run the tracebundle.m file This file loads trajectories and intersection nodes and generates road network vertices and edges. It generates two files tracebundle_vertices.txt, tracebundle_edges.txt.
路网可视化
Ahmed、Karagiorgou算法生成的都是节点文件与边的文件,这里笔者提供一个转化为GeoJSON从而可视化的代码片段
vertices_dict = {} with open('./data/resultvertices.txt','r') as vertices: for line in vertices: tmp = line.split(',') vertices_dict[int(tmp[0])] = [float(tmp[1]),float(tmp[2][:-1])] edge_arr = [] with open('./data/resultedges.txt','r') as edges: for line in edges: tmp = line.split(',') edge_arr.append([vertices_dict[int(tmp[1])],vertices_dict[int(tmp[2])]]) import os import json def save_trajs(data, path, type_style): res = { "type": "FeatureCollection", "features": [] } for i, traj in enumerate(data): t = { "type": "Feature", "geometry": { "type": "LineString", "coordinates": traj }, "properties": { "id": i } } res["features"].append(t) if os.path.exists(path): os.remove(path) with open(path, "w") as f: if type_style == "LineString": json.dump(res, f) save_trajs(edge_arr, "./final_map.json", "LineString")
生成的GeoJSON文件可直接拖入QGIS软件进行可视化
3. Biagioni算法
此算法基于KDE,利用核密度估计图像生成路网
代码和数据下载地址:Bits - Software (uic.edu)
代码基于Python 2 构建
环境搭建过程可见:Map Inference in the Face of Noise and Disparity代码环境搭建 - 当时明月在曾照彩云归 - 博客园 (cnblogs.com)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律