在指定的工作空间中根据路网数据对输入几何对象进行匹配,输出匹配的道路几何对象。
语法
geometry ST_MapMatching(text wsname, geometry geom, text options);
geometry ST_MapMatching(text wsname, trajectory traj, text options);
参数
参数名称 | 描述 |
wsname | 工作空间名称。 |
geom | 需要匹配的几何对象。 |
traj | 需要匹配的轨迹对象。 |
options | 基于JSON类型匹配参数。 |
返回值
返回与轨迹匹配的道路几何对象。
描述
支持输入几何线对象或者轨迹对象进行匹配。
如果输入的是轨迹对象,会对轨迹对象中的几何对象进行匹配,并输出新的几何对象,轨迹附带的属性信息将不会输出。
输出的结果是新的几何对象,该几何对象由与输入几何对象匹配的路段序列组成。
示例
准备路网数据并构建路网拓扑。
CREATE TABLE network (fid bigint, -- 路段的唯一标识 source bigint, -- 路段的开始节点标识 target bigint, -- 路段的结束节点标识 cost double precision, -- 道路权重值(目前未使用) geom public.geometry(LineString,4326) --路段的几何对象 ); INSERT INTO network(fid, source, target, cost, geom) VALUES(1, 1, 2,1, st_geomfromtext('LINESTRING(2 1,2 0)')); INSERT INTO network(fid, source, target, cost, geom) VALUES(2, 2, 1,1, st_geomfromtext('LINESTRING(2 0,2 1)')); INSERT INTO network(fid, source, target, cost, geom) VALUES(3, 3, 1,1, st_geomfromtext('LINESTRING(3 1,2 1)')); INSERT INTO network(fid, source, target, cost, geom) VALUES(4, 4, 3,1, st_geomfromtext('LINESTRING(4 1,3 1)')); INSERT INTO network(fid, source, target, cost, geom) VALUES(5, 1, 5,1, st_geomfromtext('LINESTRING(2 1,2 2)')); INSERT INTO network(fid, source, target, cost, geom) VALUES(6, 5, 1,1, st_geomfromtext('LINESTRING(2 2,2 1)')); INSERT INTO network(fid, source, target, cost, geom) VALUES(7, 3, 6,1, st_geomfromtext('LINESTRING(3 1,3 2)')); INSERT INTO network(fid, source, target, cost, geom) VALUES(8, 7, 8,1, st_geomfromtext('LINESTRING(0 2,1 2)')); INSERT INTO network(fid, source, target, cost, geom) VALUES(9, 8, 7,1, st_geomfromtext('LINESTRING(1 2,0 2)')); INSERT INTO network(fid, source, target, cost, geom) VALUES(10,5, 8,3, st_geomfromtext('LINESTRING(2 2,1 2)')); INSERT INTO network(fid, source, target, cost, geom) VALUES(11,8, 5,3, st_geomfromtext('LINESTRING(1 2,2 2)')); INSERT INTO network(fid, source, target, cost, geom) VALUES(12,6, 5,1, st_geomfromtext('LINESTRING(3 2,2 2)')); INSERT INTO network(fid, source, target, cost, geom) VALUES(13,5, 6,1, st_geomfromtext('LINESTRING(2 2,3 2)')); INSERT INTO network(fid, source, target, cost, geom) VALUES(14,6, 9,1, st_geomfromtext('LINESTRING(3 2,4 2)')); INSERT INTO network(fid, source, target, cost, geom) VALUES(15,9, 6,1, st_geomfromtext('LINESTRING(4 2,3 2)')); INSERT INTO network(fid, source, target, cost, geom) VALUES(16,10,5,1, st_geomfromtext('LINESTRING(2 3,2 2)')); INSERT INTO network(fid, source, target, cost, geom) VALUES(17,5, 10,1, st_geomfromtext('LINESTRING(2 2,2 3)')); INSERT INTO network(fid, source, target, cost, geom) VALUES(18,6, 11,1, st_geomfromtext('LINESTRING(3 2,3 3)')); INSERT INTO network(fid, source, target, cost, geom) VALUES(19,10,11,1, st_geomfromtext('LINESTRING(2 3,3 3)')); INSERT INTO network(fid, source, target, cost, geom) VALUES(20,11,12,1, st_geomfromtext('LINESTRING(3 3,4 3)')); INSERT INTO network(fid, source, target, cost, geom) VALUES(21,13,10,1, st_geomfromtext('LINESTRING(2 4,2 3)')); INSERT INTO network(fid, source, target, cost, geom) VALUES(22,10,13,1, st_geomfromtext('LINESTRING(2 3,2 4)')); INSERT INTO network(fid, source, target, cost, geom) VALUES(23,9, 12,1, st_geomfromtext('LINESTRING(4 2,4 3)')); INSERT INTO network(fid, source, target, cost, geom) VALUES(24,12,9,1, st_geomfromtext('LINESTRING(4 3,4 2)')); INSERT INTO network(fid, source, target, cost, geom) VALUES(25,9, 4,1, st_geomfromtext('LINESTRING(4 2,4 1)')); INSERT INTO network(fid, source, target, cost, geom) VALUES(26,4, 9,1, st_geomfromtext('LINESTRING(4 1,4 2)')); INSERT INTO network(fid, source, target, cost, geom) VALUES(27,14,15,1, st_geomfromtext('LINESTRING(0.5 3.5,2 3.5)')); INSERT INTO network(fid, source, target, cost, geom) VALUES(28,15,14,1, st_geomfromtext('LINESTRING(2 3.5,0.5 3.5)')); INSERT INTO network(fid, source, target, cost, geom) VALUES(29,16,17,1, st_geomfromtext('LINESTRING(3.5 4,3.5 2.3)')); INSERT INTO network(fid, source, target, cost, geom) VALUES(30,17,16,1, st_geomfromtext('LINESTRING(3.5 2.3,3.5 4)')); SELECT st_createworkspace('mm_ws_test1', 'select fid, source, target, geom from network'); CREATE TABLE traj(id int, geom geometry(linestring, 4326)); INSERT INTO traj(id, geom) VALUES(1,st_geomfromtext('LINESTRING(4.15 1.6,3.47 0.92,2.4 0.92,2.14 1.53,2.14 2.57,2.49 2.98)'));
执行道路匹配。
SELECT ST_AsText(ST_MapMatching('mm_ws_test', ST_GeomFromText('LINESTRING(4.15 1.6,3.47 0.92,2.4 0.92,2.14 1.53,2.14 2.57,2.49 2.98)'), '{"algorithm":"stmatch","k":4,"r":0.25,"e":0.5}'::text));
返回结果如下:
geom ---------------------------------------------- LINESTRING(4 1.6,4 1,3 1,2 1,2 2,2 3,2.49 3) (1 row)
文档内容是否对您有帮助?