These functions support working with trajectories.
A trajectory is a linear geometry with a measure (M value) on each coordinate.
The measure values must increase along the line.
Spatio-temporal data can be modelled by using relative times (such as the epoch)
as the measure values.
Trajectory Functions
ST_IsValidTrajectory
Returns true if the geometry is a valid trajectory.
boolean ST_IsValidTrajectory
geometry line
Description
Tests if a geometry encodes a valid trajectory.
A valid trajectory is represented as a LINESTRING
with measures (M values).
The measure values must increase from each vertex to the next.
Valid trajectories are expected as input to spatio-temporal functions
like
Availability: 2.2.0
&Z_support;
Examples
-- A valid trajectory
SELECT ST_IsValidTrajectory(ST_MakeLine(
ST_MakePointM(0,0,1),
ST_MakePointM(0,1,2))
);
t
-- An invalid trajectory
SELECT ST_IsValidTrajectory(ST_MakeLine(ST_MakePointM(0,0,1), ST_MakePointM(0,1,0)));
NOTICE: Measure of vertex 1 (0) not bigger than measure of vertex 0 (1)
st_isvalidtrajectory
----------------------
f
See Also
ST_ClosestPointOfApproach
Returns the measure at which points interpolated along two trajectories are closest.
float8 ST_ClosestPointOfApproach
geometry track1
geometry track2
Description
Returns the smallest measure at which points interpolated along the given
trajectories are at the smallest distance.
Inputs must be valid trajectories as
checked by . Null is returned if
the trajectories do not overlap in their M ranges.
See for getting the actual points at
the given measure.
Availability: 2.2.0
&Z_support;
Examples
-- Return the time in which two objects moving between 10:00 and 11:00
-- are closest to each other and their distance at that point
WITH inp AS ( SELECT
ST_AddMeasure('LINESTRING Z (0 0 0, 10 0 5)'::geometry,
extract(epoch from '2015-05-26 10:00'::timestamptz),
extract(epoch from '2015-05-26 11:00'::timestamptz)
) a,
ST_AddMeasure('LINESTRING Z (0 2 10, 12 1 2)'::geometry,
extract(epoch from '2015-05-26 10:00'::timestamptz),
extract(epoch from '2015-05-26 11:00'::timestamptz)
) b
), cpa AS (
SELECT ST_ClosestPointOfApproach(a,b) m FROM inp
), points AS (
SELECT ST_Force3DZ(ST_GeometryN(ST_LocateAlong(a,m),1)) pa,
ST_Force3DZ(ST_GeometryN(ST_LocateAlong(b,m),1)) pb
FROM inp, cpa
)
SELECT to_timestamp(m) t,
ST_Distance(pa,pb) distance
FROM points, cpa;
t | distance
-------------------------------+------------------
2015-05-26 10:45:31.034483+02 | 1.96036833151395
See Also
,
,
,
ST_DistanceCPA
Returns the distance between the closest point of approach of two trajectories.
float8 ST_DistanceCPA
geometry track1
geometry track2
Description
Returns the minimum distance two moving objects have ever been each other.
Inputs must be valid trajectories as checked by
.
Null is returned if the trajectories do not overlap in their M ranges.
Availability: 2.2.0
&Z_support;
Examples
-- Return the minimum distance of two objects moving between 10:00 and 11:00
WITH inp AS ( SELECT
ST_AddMeasure('LINESTRING Z (0 0 0, 10 0 5)'::geometry,
extract(epoch from '2015-05-26 10:00'::timestamptz),
extract(epoch from '2015-05-26 11:00'::timestamptz)
) a,
ST_AddMeasure('LINESTRING Z (0 2 10, 12 1 2)'::geometry,
extract(epoch from '2015-05-26 10:00'::timestamptz),
extract(epoch from '2015-05-26 11:00'::timestamptz)
) b
)
SELECT ST_DistanceCPA(a,b) distance FROM inp;
distance
------------------
1.96036833151395
See Also
,
,
,
ST_CPAWithin
Returns true if the closest point of approach of two trajectories
is within the specified distance.
float8 ST_CPAWithin
geometry track1
geometry track2
float8 maxdist
Description
Checks whether two moving objects have ever been within the
specified maximum distance.
Inputs must be valid trajectories as checked by
.
False is returned if the trajectories do not overlap in their M ranges.
Availability: 2.2.0
&Z_support;
Examples
WITH inp AS ( SELECT
ST_AddMeasure('LINESTRING Z (0 0 0, 10 0 5)'::geometry,
extract(epoch from '2015-05-26 10:00'::timestamptz),
extract(epoch from '2015-05-26 11:00'::timestamptz)
) a,
ST_AddMeasure('LINESTRING Z (0 2 10, 12 1 2)'::geometry,
extract(epoch from '2015-05-26 10:00'::timestamptz),
extract(epoch from '2015-05-26 11:00'::timestamptz)
) b
)
SELECT ST_CPAWithin(a,b,2), ST_DistanceCPA(a,b) distance FROM inp;
st_cpawithin | distance
--------------+------------------
t | 1.96521473776207
See Also
,
,
,