STS_GetFirstTimeByRegion function

The STS_GetFirstTimeByRegion function returns the first time within a time range when an object is near the specified position.

Syntax

STS_GetFirstTimeByRegion(
                        ts            TimeSeries,
                        begin_time    DATETIME YEAR TO FRACTION(5),
                        end_time      DATETIME YEAR TO FRACTION(5),
                        geometry      ST_Geometry)
returns DATETIME YEAR TO FRACTION(5)
ts
The time series value.
begin_time
The start of the time range. Can be NULL to indicate the first element in the time series.
end_time
The end of the time range. Can be NULL to indicate the last element in the time series.
geometry
The region of interest. Can be an ST_Point, ST_MultiPoint, ST_LineString, ST_MultiLineString, ST_Polygon, or ST_MultiPolygon. Must use the SRID 4326.

Usage

Run the STS_GetFirstTimeByRegion function to find when an object first passed within the specified region during the specified time range. If you do not specify a time range, the function returns the first time that an object passed close enough to the position. If the object was too far away from the position during the time range, the STS_GetFirstTimeByRegion function returns NULL.

Returns

A time stamp = When the object first moved into the region.

NULL = The trajectory of the object during the time range was always farther than the maximum distance from the region.

Example

The following query returns the first time that vehicle 1002 passed by the specified region between the times of 2015-06-14 12:00:00 and 2015-06-14 12:45:00:

SELECT STS_GetFirstTimeByRegion(ts_track, 
        '2015-06-14 12:00:00', '2015-06-14 12:45:00',       
        ST_Buffer(ST_Point(-78.704708,43.919647, 4326), 30, 'meter')) 
        FROM t_vehicle 
        WHERE modid = 1002; 

(expression) 
     2015-06-14 12:34:25.00000 
1 row(s) retrieved.