Identifies curves in a trajectory and returns the curvature radius and boundary positions of each detected curve.
Syntax
Syntax 1
SETOF trpeak ST_CurveRecognize (trajectory traj, float8 radius_threshold, float8 angle_threshold, float8 angle_compress_threshold default 0);Syntax 2
SETOF trpeak ST_CurveRecognize (trajectory traj, float8 radius_threshold, float8 angle_threshold, float8 expansion_radius1, float8 expansion_radius2, float8 angle_compress_threshold default 0);
Parameters
| Parameter | Description |
|---|---|
traj | The source trajectory. |
radius_threshold | The curvature radius threshold for detecting curve center points. The function groups consecutive points whose curvature radius is below this threshold and selects the point with the smallest curvature radius as the center point of the curve. |
angle_threshold | The minimum rotation angle for a curve boundary point. Boundary points with a rotation angle below this value are removed, splitting the curve at those points. After removal, every point on each resulting curve segment has a rotation angle greater than this threshold. |
expansion_radius1 | The maximum curvature radius allowed at each point adjacent to a curve center. Used to expand the curve boundary outward from the center point. Available in Syntax 2 only. Default value when using Syntax 1: radius_threshold * 2. |
expansion_radius2 | The maximum average curvature radius from an adjacent point to the curve center. Used together with expansion_radius1 to control boundary expansion. Available in Syntax 2 only. Default value when using Syntax 1: radius_threshold * 4. |
angle_compress_threshold | The minimum rotation angle required to sample a point. Points with a rotation angle below this value are skipped, reducing sampling density and preventing over-sampling from obscuring curve boundaries. Default value: 0. |
Response parameters:
| Parameter | Description |
|---|---|
loc | The serial number of the turning point on the trajectory that serves as the curve center. If loc equals n, the center point is the (n+1)th turning point of the trajectory. |
height | The curvature radius at the curve center point. A positive value indicates a clockwise curve; a negative value indicates a counterclockwise curve. |
startloc | The start point of the curve. |
endloc | The end point of the curve. |
Description
ST_CurveRecognize detects curves in a trajectory through three steps:
Center point selection: The function finds all consecutive trajectory points whose curvature radius is smaller than
radius_threshold, then selects the point with the smallest curvature radius from that group as the curve center point.Boundary expansion: Starting from each center point, the function expands the curve boundary to include adjacent points that meet both of the following conditions:
The curvature radius at the point is smaller than
expansion_radius1.The average curvature radius from that point to the center point is smaller than
expansion_radius2.
NoteWhen using Syntax 1,
expansion_radius1andexpansion_radius2default toradius_threshold * 2andradius_threshold * 4, respectively.Boundary adjustment: The function adjusts each curve boundary based on
angle_threshold:If the rotation angle at the original boundary point exceeds
angle_threshold, the boundary expands outward.If the rotation angle at the original boundary point is below
angle_threshold, the boundary point is removed and the boundary shrinks inward.
Examples
SELECT (ST_CurveRecognize('{"trajectory":{"version":1,"type":"STPOINT","leafcount":16,"start_time":"2000-01-01 00:00:00","end_time":"2000-01-16 00:00:00","spatial":"LINESTRING(0 0,1 1,2 2,4 3,3 4,5 7,8 8,7 4,0 0,1 1,2 2,4 3,3 4,5 7,8 8,7 4)","timeline":["2000-01-01 00:00:00","2000-01-02 00:00:00","2000-01-03 00:00:00","2000-01-04 00:00:00","2000-01-05 00:00:00","2000-01-06 00:00:00","2000-01-07 00:00:00","2000-01-08 00:00:00","2000-01-09 00:00:00","2000-01-10 00:00:00","2000-01-11 00:00:00","2000-01-12 00:00:00","2000-01-13 00:00:00","2000-01-14 00:00:00","2000-01-15 00:00:00","2000-01-16 00:00:00"]}}', 15, 1)).*;The query uses radius_threshold=15 and angle_threshold=1. The expected output is:
loc | height | startloc | endloc
-----+-------------------+----------+--------
2 | 5.70087712549569 | 2 | 2
4 | 2.10237960416286 | 4 | 8
10 | 5.70087712549569 | 10 | 10
12 | 2.10237960416286 | 12 | 15
3 | -1.17851130197758 | 3 | 3
11 | -1.17851130197758 | 11 | 11
(6 rows)