All functions for temporal types described in Chapter 5 can be applied for temporal network point types. Therefore, in the signatures of the functions, the notation base
also represents an npoint
and the notations ttype
, tpoint
, and tgeompoint
also represent a tnpoint
. Furthermore, the functions that have an argument of type geometry
accept in addition an argument of type npoint
. To avoid redundancy, we only present next some examples of these functions and operators for temporal network points.
Transform a temporal network point to another subtype
tnpoint_inst(tnpoint): tnpoint_inst
tnpoint_instset(tnpoint): tnpoint_instset
tnpoint_seq(tnpoint): tnpoint_seq
tnpoint_seqset(tnpoint): tnpoint_seqset
SELECT tnpoint_seqset(tnpoint 'NPoint(1, 0.5)@2001-01-01'); -- {[NPoint(1,0.5)@2001-01-01]}
Set the precision of the fraction of the temporal network point to the number of decimal places
setPrecision(tnpoint,integer): tnpoint
SELECT setPrecision(tnpoint '{[NPoint(1, 0.123456789)@2012-01-01, NPoint(1, 0.5)@2012-01-02)}', 6); -- {[NPoint(1,0.123457)@2012-01-01 00:00:00+01, NPoint(1,0.5)@2012-01-02 00:00:00+01)}
Get the values
getValues(tnpoint): npoint[]
SELECT getValues(tnpoint '{[NPoint(1, 0.3)@2012-01-01, NPoint(1, 0.5)@2012-01-02)}'); -- {"NPoint(1,0.3)","NPoint(1,0.5)"} SELECT getValues(tnpoint '{[NPoint(1, 0.3)@2012-01-01, NPoint(1, 0.3)@2012-01-02)}'); -- {"NPoint(1,0.3)"}
Get the value at a timestamp
valueAtTimestamp(tnpoint,timestamptz): npoint
SELECT valueAtTimestamp(tnpoint '[NPoint(1, 0.3)@2012-01-01, NPoint(1, 0.5)@2012-01-03)', '2012-01-02'); -- NPoint(1,0.4)
Get the length traversed by the temporal network point
length(tnpoint): float
SELECT length(tnpoint '[NPoint(1, 0.3)@2000-01-01, NPoint(1, 0.5)@2000-01-02]'); -- 54.3757408468784
Get the cumulative length traversed by the temporal network point
cumulativeLength(tnpoint): tfloat
SELECT cumulativeLength(tnpoint '{[NPoint(1, 0.3)@2000-01-01, NPoint(1, 0.5)@2000-01-02, NPoint(1, 0.5)@2000-01-03], [NPoint(1, 0.6)@2000-01-04, NPoint(1, 0.7)@2000-01-05]}'); -- {[0@2000-01-01, 54.3757408468784@2000-01-02, 54.3757408468784@2000-01-03], [54.3757408468784@2000-01-04, 81.5636112703177@2000-01-05]}
Get the speed of the temporal network point in units per second
speed({tnpoint_seq, tpoint_seqset}): tfloat_seqset
SELECT speed(tnpoint '[NPoint(1, 0.1)@2000-01-01, NPoint(1, 0.4)@2000-01-02, NPoint(1, 0.6)@2000-01-03]') * 3600 * 24; -- Interp=Stepwise;[21.4016800272077@2000-01-01, 14.2677866848051@2000-01-02, 14.2677866848051@2000-01-03]
Construct the bounding box from a npoint and, optionally, a timestamp or a period
stbox(npoint): stbox
stbox(npoint,{timestamptz,period}): stbox
SELECT stbox(npoint 'NPoint(1,0.3)'); -- STBOX((48.711754,20.92568),(48.711758,20.925682)) SELECT stbox(npoint 'NPoint(1,0.3)', timestamptz '2000-01-01'); -- STBOX T((62.786633,80.143555,2000-01-01),(62.786636,80.143562,2000-01-01)) SELECT stbox(npoint 'NPoint(1,0.3)', period '[2000-01-01,2000-01-02]'); -- STBOX T((62.786633,80.143555,2000-01-01),(62.786636,80.143562,2000-01-02))
Get the time-weighted centroid
twCentroid(tnpoint): geometry(Point)
SELECT st_astext(twCentroid(tnpoint '{[NPoint(1, 0.3)@2012-01-01, NPoint(1, 0.5)@2012-01-02, NPoint(1, 0.5)@2012-01-03, NPoint(1, 0.7)@2012-01-04)}')); -- POINT(79.9787466444847 46.2385558051041)
Get the temporal azimuth
azimuth(tnpoint): tfloat
SELECT azimuth(tnpoint '[NPoint(2, 0.3)@2012-01-01, NPoint(2, 0.7)@2012-01-02]'); -- {[0.974681063778863@2012-01-01 00:00:00+01, 0.974681063778863@2012-01-01 23:54:36.721091+01), [3.68970843029227@2012-01-01 23:54:36.721091+01, 3.68970843029227@2012-01-02 00:00:00+01)}
Since the underlying geometry associated to a route may have several vertices, the azimuth value may change between instants of the input temporal network point, as shown in the example above.
Get the instant of the first temporal network point at which the two arguments are at the nearest distance
nearestApproachInstant({geo,npoint,tpoint},{geo,npoint,tpoint}): tpoint
SELECT nearestApproachInstant(tnpoint '[NPoint(2, 0.3)@2012-01-01, NPoint(2, 0.7)@2012-01-02]', geometry 'Linestring(50 50,55 55)'); -- NPoint(2,0.349928)@2012-01-01 02:59:44.402905+01 SELECT nearestApproachInstant(tnpoint '[NPoint(2, 0.3)@2012-01-01, NPoint(2, 0.7)@2012-01-02]', npoint 'NPoint(1, 0.5)'); -- NPoint(2,0.592181)@2012-01-01 17:31:51.080405+01
Get the smallest distance ever between the two arguments
nearestApproachDistance({geo,npoint,tpoint},{geo,npoint,tpoint}): float
SELECT nearestApproachDistance(tnpoint '[NPoint(2, 0.3)@2012-01-01, NPoint(2, 0.7)@2012-01-02]', geometry 'Linestring(50 50,55 55)'); -- 1.41793220500979 SELECT nearestApproachDistance(tnpoint '[NPoint(2, 0.3)@2012-01-01, NPoint(2, 0.7)@2012-01-02]', npoint 'NPoint(1, 0.5)'); -- NPoint(2,0.592181)@2012-01-01 17:31:51.080405+01
Function nearestApproachDistance
has an associated operator |=|
that can be used for doing nearest neightbor searches using a GiST index (see Section 5.17).
Get the line connecting the nearest approach point between the two arguments
shortestLine({geo,npoint,tpoint},{geo,npoint,tpoint}): geometry
The function will only return the first line that it finds if there are more than one
SELECT st_astext(shortestLine(tnpoint '[NPoint(2, 0.3)@2012-01-01, NPoint(2, 0.7)@2012-01-02]', geometry 'Linestring(50 50,55 55)')); -- LINESTRING(50.7960725266492 48.8266286733015,50 50) SELECT st_astext(shortestLine(tnpoint '[NPoint(2, 0.3)@2012-01-01, NPoint(2, 0.7)@2012-01-02]', npoint 'NPoint(1, 0.5)')); -- LINESTRING(77.0902838115125 66.6659083092593,90.8134936900394 46.4385792121146)
Restrict to a value
atValue(tnpoint,base): tnpoint
SELECT atValue(tnpoint '[NPoint(2, 0.3)@2012-01-01, NPoint(2, 0.7)@2012-01-03]', 'NPoint(2, 0.5)'); -- {[NPoint(2,0.5)@2012-01-02]}
Restrict to a geometry
atGeometry(tnpoint,geometry): tnpoint
SELECT atGeometry(tnpoint '[NPoint(2, 0.3)@2012-01-01, NPoint(2, 0.7)@2012-01-03]', 'Polygon((40 40,40 50,50 50,50 40,40 40))');
Difference with a value
minusValue(tnpoint,base): tnpoint
SELECT minusValue(tnpoint '[NPoint(2, 0.3)@2012-01-01, NPoint(2, 0.7)@2012-01-03]', 'NPoint(2, 0.5)'); -- {[NPoint(2,0.3)@2012-01-01, NPoint(2,0.5)@2012-01-02), (NPoint(2,0.5)@2012-01-02, NPoint(2,0.7)@2012-01-03]}
Difference with a geometry
minusGeometry(tnpoint,geometry): tnpoint
SELECT minusGeometry(tnpoint '[NPoint(2, 0.3)@2012-01-01, NPoint(2, 0.7)@2012-01-03]', 'Polygon((40 40,40 50,50 50,50 40,40 40))'); -- {(NPoint(2,0.342593)@2012-01-01 05:06:40.364673+01, NPoint(2,0.7)@2012-01-03 00:00:00+01]}
Traditional comparison operators
tnpoint = tnpoint: boolean
tnpoint <> tnpoint: boolean
tnpoint < tnpoint: boolean
tnpoint > tnpoint: boolean
tnpoint <= tnpoint: boolean
tnpoint >= tnpoint: boolean
SELECT tnpoint '{[NPoint(1, 0.1)@2001-01-01, NPoint(1, 0.3)@2001-01-02), [NPoint(1, 0.3)@2001-01-02, NPoint(1, 0.5)@2001-01-03]}' = tnpoint '[NPoint(1, 0.1)@2001-01-01, NPoint(1, 0.5)@2001-01-03]'; -- true SELECT tnpoint '{[NPoint(1, 0.1)@2001-01-01, NPoint(1, 0.5)@2001-01-03]}' <> tnpoint '[NPoint(1, 0.1)@2001-01-01, NPoint(1, 0.5)@2001-01-03]'; -- false SELECT tnpoint '[NPoint(1, 0.1)@2001-01-01, NPoint(1, 0.5)@2001-01-03]' < tnpoint '[NPoint(1, 0.1)@2001-01-01, NPoint(1, 0.6)@2001-01-03]'; -- true
Temporal comparison operators
tnpoint #= tnpoint: tbool
tnpoint #<> tnpoint: tbool
SELECT tnpoint '[NPoint(1, 0.2)@2012-01-01, NPoint(1, 0.4)@2012-01-03)' #= npoint 'NPoint(1, 0.3)'; -- {[f@2012-01-01, t@2012-01-02], (f@2012-01-02, f@2012-01-03)} SELECT tnpoint '[NPoint(1, 0.2)@2012-01-01, NPoint(1, 0.8)@2012-01-03)' #<> tnpoint '[NPoint(1, 0.3)@2012-01-01, NPoint(1, 0.7)@2012-01-03)'; -- {[t@2012-01-01, f@2012-01-02], (t@2012-01-02, t@2012-01-03)}
Ever and always equal operators
tnpoint ?= tnpoint: boolean
tnpoint &= tnpoint: boolean
SELECT tnpoint '[Npoint(1, 0.2)@2012-01-01, Npoint(1, 0.4)@2012-01-04)' ?= Npoint(1, 0.3); -- true SELECT tnpoint '[Npoint(1, 0.2)@2012-01-01, Npoint(1, 0.2)@2012-01-04)' &= Npoint(1, 0.2); -- true
Relative position operators
tnpoint << tnpoint: boolean
tnpoint &< tnpoint: boolean
tnpoint >> tnpoint: boolean
tnpoint &> tnpoint: boolean
tnpoint <<| tnpoint: boolean
tnpoint &<| tnpoint: boolean
tnpoint |>> tnpoint: boolean
tnpoint |&> tnpoint: boolean
tnpoint <<# tnpoint: boolean
tnpoint &<# tnpoint: boolean
tnpoint #>> tnpoint: boolean
tnpoint |&> tnpoint: boolean
SELECT tnpoint '[NPoint(1, 0.3)@2000-01-01, NPoint(1, 0.5)@2000-01-02]' << npoint 'NPoint(1, 0.2)' -- false SELECT tnpoint '[NPoint(1, 0.3)@2000-01-01, NPoint(1, 0.5)@2000-01-02]' <<| stbox(npoint 'NPoint(1, 0.5)') -- false SELECT tnpoint '[NPoint(1, 0.3)@2000-01-01, NPoint(1, 0.5)@2000-01-02]' &> npoint 'NPoint(1, 0.3)'::geometry -- true SELECT tnpoint '[NPoint(1, 0.3)@2000-01-01, NPoint(1, 0.5)@2000-01-02]' >># tnpoint '[NPoint(1, 0.3)@2000-01-03, NPoint(1, 0.5)@2000-01-05]' -- true
Topological operators
tnpoint && tnpoint: boolean
tnpoint <@ tnpoint: boolean
tnpoint @> tnpoint: boolean
tnpoint ~= tnpoint: boolean
tnpoint -|- tnpoint: boolean
SELECT tnpoint '[NPoint(1, 0.3)@2000-01-01, NPoint(1, 0.5)@2000-01-02]' && npoint 'NPoint(1, 0.5)' -- true SELECT tnpoint '[NPoint(1, 0.3)@2000-01-01, NPoint(1, 0.5)@2000-01-02]' @> stbox(npoint 'NPoint(1, 0.5)') -- true SELECT npoint 'NPoint(1, 0.5)'::geometry <@ tnpoint '[NPoint(1, 0.3)@2000-01-01, NPoint(1, 0.5)@2000-01-02]' -- true SELECT tnpoint '[NPoint(1, 0.3)@2000-01-01, NPoint(1, 0.5)@2000-01-03]' ~= tnpoint '[NPoint(1, 0.3)@2000-01-01, NPoint(1, 0.35)@2000-01-02, NPoint(1, 0.5)@2000-01-03]' -- true
Get the smallest distance ever between the two arguments
tgeompoint |=| tnpoint: float
SELECT tnpoint '[NPoint(1, 0.3)@2000-01-01, NPoint(1, 0.5)@2000-01-03]' |=| npoint 'NPoint(1, 0.2)'; -- 2.34988300875063 SELECT tnpoint '[NPoint(1, 0.3)@2000-01-01, NPoint(1, 0.5)@2000-01-03]' |=| geometry 'Linestring(2 2,2 1,3 1)'; -- 82.2059262761477
Get the temporal distance
tgeompoint <-> tnpoint: tfloat
SELECT tnpoint '[NPoint(1, 0.3)@2000-01-01, NPoint(1, 0.5)@2000-01-03]' <-> npoint 'NPoint(1, 0.2)'; -- [2.34988300875063@2000-01-02 00:00:00+01, 2.34988300875063@2000-01-03 00:00:00+01] SELECT tnpoint '[NPoint(1, 0.3)@2000-01-01, NPoint(1, 0.5)@2000-01-03]' <-> geometry 'Point(50 50)'; -- [25.0496666945044@2000-01-01 00:00:00+01, 26.4085688426232@2000-01-03 00:00:00+01] SELECT tnpoint '[NPoint(1, 0.3)@2000-01-01, NPoint(1, 0.5)@2000-01-03]' <-> tnpoint '[NPoint(1, 0.3)@2000-01-02, NPoint(1, 0.5)@2000-01-04]' -- [2.34988300875063@2000-01-02 00:00:00+01, 2.34988300875063@2000-01-03 00:00:00+01]
Possible spatial relationships
contains(geometry,tnpoint): boolean
disjoint({geometry,npoint,tnpoint},{geometry,npoint,tnpoint}): boolean
intersects({geometry,npoint,tnpoint},{geometry,npoint,tnpoint}): boolean
touches({geometry,npoint,tnpoint},{geometry,npoint,tnpoint}): boolean
dwithin({geometry,npoint,tnpoint},{geometry,npoint,tnpoint},float): boolean
SELECT contains(geometry 'Polygon((0 0,0 50,50 50,50 0,0 0))', tnpoint '[NPoint(1, 0.1)@2012-01-01, NPoint(1, 0.3)@2012-01-03)'); -- false SELECT disjoint(npoint 'NPoint(2, 0.0)', tnpoint '[NPoint(1, 0.1)@2012-01-01, NPoint(1, 0.3)@2012-01-03)'); -- true SELECT intersects(tnpoint '[NPoint(1, 0.1)@2012-01-01, NPoint(1, 0.3)@2012-01-03)', tnpoint '[NPoint(2, 0.0)@2012-01-01, NPoint(2, 1)@2012-01-03)'); -- false
Temporal spatial relationships
tcontains(geometry,tnpoint): boolean
tdisjoint({geometry,npoint,tnpoint},{geometry,npoint,tnpoint}): boolean
tintersects({geometry,npoint,tnpoint},{geometry,npoint,tnpoint}): boolean
ttouches({geometry,npoint,tnpoint},{geometry,npoint,tnpoint}): boolean
tdwithin({geometry,npoint,tnpoint},{geometry,npoint,tnpoint},float): boolean
SELECT tdisjoint(geometry 'Polygon((0 0,0 50,50 50,50 0,0 0))', tnpoint '[NPoint(1, 0.1)@2012-01-01, NPoint(1, 0.3)@2012-01-03)'); -- {[t@2012-01-01 00:00:00+01, t@2012-01-03 00:00:00+01)} SELECT tdwithin(tnpoint '[NPoint(1, 0.3)@2012-01-01, NPoint(1, 0.5)@2012-01-03)', tnpoint '[NPoint(1, 0.5)@2012-01-01, NPoint(1, 0.3)@2012-01-03)', 1); -- {[t@2012-01-01 00:00:00+01, t@2012-01-01 22:35:55.379053+01], (f@2012-01-01 22:35:55.379053+01, t@2012-01-02 01:24:04.620946+01, t@2012-01-03 00:00:00+01)}