All Products
Search
Document Center

PolarDB:ST_MapMatching

Last Updated:Nov 13, 2024

Matches input geometric objects against road network data within a specific workspace and returns matched road geometric objects.

Syntax

geometry ST_MapMatching(text wsname, geometry geom, text options);
geometry ST_MapMatching(text wsname, trajectory traj, text options);

Parameters

Parameter

Description

wsname

The name of the workspace.

geom

The geometric object that you want to match against the road network data in the workspace.

traj

The trajectory that you want to match against the road network data in the workspace.

options

JSON-type matching parameters.

Return values

Returns the road geometric objects that corresponds to input geometric objects or trajectories.

Description

  • You can enter geometric line objects or trajectory objects for matching.

  • If you specify a trajectory object, the geometry objects in the trajectory object are matched and new matched geometry objects are returned. However, the attribute information of the trajectory objects is not returned.

  • The function returns new geometric objects that consist of a sequence of segments that corresponds to the input geometric objects.

Examples

  1. Prepare road network data and build the road network topology.

    CREATE TABLE network (fid bigint, -- The unique identifier of the road segment.
                             source bigint, -- The start node identifier of the road segment.
                             target bigint, -- The end node identifier of the road segment.
                             cost double precision, - The road weight value (not currently used).
                             geom public.geometry(LineString,4326) -- The geometric objects of the road segment.
    );
    
    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)'));
  2. Perform road matching.

    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));

    Sample result:

                         geom                     
    ----------------------------------------------
     LINESTRING(4 1.6,4 1,3 1,2 1,2 2,2 3,2.49 3)
    (1 row)

    image