Most functions for temporal types described in the previous chapters 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
tnpointInst(tnpoint) → tnpointInst
tnpointSeq(tnpoint) → tnpointSeq
tnpointSeqSet(tnpoint) → tnpointSeqSet
SELECT tnpointSeq(tnpoint 'NPoint(1, 0.5)@2001-01-01', 'discrete'); -- {NPoint(1,0.5)@2001-01-01} SELECT tnpointSeq(tnpoint 'NPoint(1, 0.5)@2001-01-01'); -- [NPoint(1,0.5)@2001-01-01] SELECT tnpointSeqSet(tnpoint 'NPoint(1, 0.5)@2001-01-01'); -- {[NPoint(1,0.5)@2001-01-01]}
Transform a temporal network point to another interpolation
setInterp(tnpoint, interp) → tnpoint
SELECT setInterp(tnpoint 'NPoint(1,0.2)@2001-01-01','linear'); -- [NPoint(1,0.2)@2001-01-01] SELECT setInterp(tnpoint '{[NPoint(1,0.1)@2001-01-01], [NPoint(1,0.2)@2001-01-02]}', 'discrete'); -- {NPoint(1,0.1)@2001-01-01, NPoint(1,0.2)@2001-01-02}
Round the fraction of the temporal network point to the number of decimal places
round(tnpoint,integer) → tnpoint
SELECT round(tnpoint '{[NPoint(1,0.123456789)@2001-01-01, NPoint(1,0.5)@2001-01-02)}', 6); -- {[NPoint(1,0.123457)@2001-01-01 00:00:00+01, NPoint(1,0.5)@2001-01-02 00:00:00+01)}
Return the values
getValues(tnpoint) → npoint[]
SELECT getValues(tnpoint '{[NPoint(1, 0.3)@2001-01-01, NPoint(1, 0.5)@2001-01-02)}'); -- {"NPoint(1,0.3)","NPoint(1,0.5)"} SELECT getValues(tnpoint '{[NPoint(1, 0.3)@2001-01-01, NPoint(1, 0.3)@2001-01-02)}'); -- {"NPoint(1,0.3)"}
Return the road identifiers
routes(tnpoint) → bigintset
SELECT routes(tnpoint '{NPoint(3, 0.3)@2001-01-01, NPoint(1, 0.5)@2001-01-02}'); -- {1, 3}
Return the value at a timestamp
valueAtTimestamp(tnpoint,timestamptz) → npoint
SELECT valueAtTimestamp(tnpoint '[NPoint(1, 0.3)@2001-01-01, NPoint(1, 0.5)@2001-01-03)', '2001-01-02'); -- NPoint(1,0.4)
Return the length traversed by the temporal network point
length(tnpoint) → float
SELECT length(tnpoint '[NPoint(1, 0.3)@2001-01-01, NPoint(1, 0.5)@2001-01-02]'); -- 54.3757408468784
Return the cumulative length traversed by the temporal network point
cumulativeLength(tnpoint) → tfloat
SELECT cumulativeLength(tnpoint '{[NPoint(1, 0.3)@2001-01-01, NPoint(1, 0.5)@2001-01-02, NPoint(1, 0.5)@2001-01-03], [NPoint(1, 0.6)@2001-01-04, NPoint(1, 0.7)@2001-01-05]}'); /* {[0@2001-01-01, 54.3757408468784@2001-01-02, 54.3757408468784@2001-01-03], [54.3757408468784@2001-01-04, 81.5636112703177@2001-01-05]} */
Return the speed of the temporal network point in units per second
speed({tnpointSeq, tnpointSeqSet}) → tfloatSeqSet
SELECT speed(tnpoint '[NPoint(1, 0.1)@2001-01-01, NPoint(1, 0.4)@2001-01-02, NPoint(1, 0.6)@2001-01-03]') * 3600 * 24; /* Interp=Step;[21.4016800272077@2001-01-01, 14.2677866848051@2001-01-02, 14.2677866848051@2001-01-03] */
Construct the bounding box from a npoint and, optionally, a timestamp or a period
stbox(npoint) → stbox
stbox(npoint,{timestamptz,tstzspan}) → stbox
SELECT stbox(npoint 'NPoint(1,0.3)'); -- STBOX X((48.711754,20.92568),(48.711758,20.925682)) SELECT stbox(npoint 'NPoint(1,0.3)', timestamptz '2001-01-01'); -- STBOX XT(((62.786633,80.143555),(62.786636,80.143562)),[2001-01-01,2001-01-01]) SELECT stbox(npoint 'NPoint(1,0.3)', tstzspan '[2001-01-01,2001-01-02]'); -- STBOX XT(((62.786633,80.143555),(62.786636,80.143562)),[2001-01-01,2001-01-02])
Return the time-weighted centroid
twCentroid(tnpoint) → geometry(Point)
SELECT st_astext(twCentroid(tnpoint '{[NPoint(1, 0.3)@2001-01-01, NPoint(1, 0.5)@2001-01-02, NPoint(1, 0.5)@2001-01-03, NPoint(1, 0.7)@2001-01-04)}')); -- POINT(79.9787466444847 46.2385558051041)
Return the temporal azimuth
azimuth(tnpoint) → tfloat
SELECT azimuth(tnpoint '[NPoint(2, 0.3)@2001-01-01, NPoint(2, 0.7)@2001-01-02]'); /* {[0.974681063778863@2001-01-01 00:00:00+01, 0.974681063778863@2001-01-01 23:54:36.721091+01), [3.68970843029227@2001-01-01 23:54:36.721091+01, 3.68970843029227@2001-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.
Return 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)@2001-01-01, NPoint(2, 0.7)@2001-01-02]', geometry 'Linestring(50 50,55 55)'); -- NPoint(2,0.349928)@2001-01-01 02:59:44.402905+01 SELECT nearestApproachInstant(tnpoint '[NPoint(2, 0.3)@2001-01-01, NPoint(2, 0.7)@2001-01-02]', npoint 'NPoint(1, 0.5)'); -- NPoint(2,0.592181)@2001-01-01 17:31:51.080405+01
Return the smallest distance ever between the two arguments
nearestApproachDistance({geo,npoint,tpoint},{geo,npoint,tpoint}) → float
SELECT nearestApproachDistance(tnpoint '[NPoint(2, 0.3)@2001-01-01, NPoint(2, 0.7)@2001-01-02]', geometry 'Linestring(50 50,55 55)'); -- 1.41793220500979 SELECT nearestApproachDistance(tnpoint '[NPoint(2, 0.3)@2001-01-01, NPoint(2, 0.7)@2001-01-02]', npoint 'NPoint(1, 0.5)'); -- NPoint(2,0.592181)@2001-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 the section called “Indexing”).
Return 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)@2001-01-01, NPoint(2, 0.7)@2001-01-02]', geometry 'Linestring(50 50,55 55)')); -- LINESTRING(50.7960725266492 48.8266286733015,50 50) SELECT st_astext(shortestLine(tnpoint '[NPoint(2, 0.3)@2001-01-01, NPoint(2, 0.7)@2001-01-02]', npoint 'NPoint(1, 0.5)')); -- LINESTRING(77.0902838115125 66.6659083092593,90.8134936900394 46.4385792121146)
Restrict to (the complement of) a value
atValue(tnpoint,base) → tnpoint
minusValue(tnpoint,base) → tnpoint
SELECT atValue(tnpoint '[NPoint(2, 0.3)@2001-01-01, NPoint(2, 0.7)@2001-01-03]', 'NPoint(2, 0.5)'); -- {[NPoint(2,0.5)@2001-01-02]} SELECT minusValue(tnpoint '[NPoint(2, 0.3)@2001-01-01, NPoint(2, 0.7)@2001-01-03]', 'NPoint(2, 0.5)'); /* {[NPoint(2,0.3)@2001-01-01, NPoint(2,0.5)@2001-01-02), (NPoint(2,0.5)@2001-01-02, NPoint(2,0.7)@2001-01-03]} */
Restrict to a geometry
atGeometry(tnpoint,geometry) → tnpoint
minusGeometry(tnpoint,geometry) → tnpoint
SELECT atGeometry(tnpoint '[NPoint(2, 0.3)@2001-01-01, NPoint(2, 0.7)@2001-01-03]', 'Polygon((40 40,40 50,50 50,50 40,40 40))'); SELECT minusGeometry(tnpoint '[NPoint(2, 0.3)@2001-01-01, NPoint(2, 0.7)@2001-01-03]', 'Polygon((40 40,40 50,50 50,50 40,40 40))'); /* {(NPoint(2,0.342593)@2001-01-01 05:06:40.364673+01, NPoint(2,0.7)@2001-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)@2001-01-01, NPoint(1, 0.4)@2001-01-03)' #= npoint 'NPoint(1, 0.3)'; -- {[f@2001-01-01, t@2001-01-02], (f@2001-01-02, f@2001-01-03)} SELECT tnpoint '[NPoint(1, 0.2)@2001-01-01, NPoint(1, 0.8)@2001-01-03)' #<> tnpoint '[NPoint(1, 0.3)@2001-01-01, NPoint(1, 0.7)@2001-01-03)'; -- {[t@2001-01-01, f@2001-01-02], (t@2001-01-02, t@2001-01-03)}
Ever and always equal operators
tnpoint ?= tnpoint → boolean
tnpoint %= tnpoint → boolean
SELECT tnpoint '[Npoint(1, 0.2)@2001-01-01, Npoint(1, 0.4)@2001-01-04)' ?= Npoint(1, 0.3); -- true SELECT tnpoint '[Npoint(1, 0.2)@2001-01-01, Npoint(1, 0.2)@2001-01-04)' &= Npoint(1, 0.2); -- true
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)@2001-01-01, NPoint(1, 0.5)@2001-01-02]' << npoint 'NPoint(1, 0.2)' -- false SELECT tnpoint '[NPoint(1, 0.3)@2001-01-01, NPoint(1, 0.5)@2001-01-02]' <<| stbox(npoint 'NPoint(1, 0.5)') -- false SELECT tnpoint '[NPoint(1, 0.3)@2001-01-01, NPoint(1, 0.5)@2001-01-02]' &> npoint 'NPoint(1, 0.3)'::geometry -- true SELECT tnpoint '[NPoint(1, 0.3)@2001-01-01, NPoint(1, 0.5)@2001-01-02]' >># tnpoint '[NPoint(1, 0.3)@2001-01-03, NPoint(1, 0.5)@2001-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)@2001-01-01, NPoint(1, 0.5)@2001-01-02]' && npoint 'NPoint(1, 0.5)' -- true SELECT tnpoint '[NPoint(1, 0.3)@2001-01-01, NPoint(1, 0.5)@2001-01-02]' @> stbox(npoint 'NPoint(1, 0.5)') -- true SELECT npoint 'NPoint(1, 0.5)'::geometry <@ tnpoint '[NPoint(1, 0.3)@2001-01-01, NPoint(1, 0.5)@2001-01-02]' -- true SELECT tnpoint '[NPoint(1, 0.3)@2001-01-01, NPoint(1, 0.5)@2001-01-03]' ~= tnpoint '[NPoint(1, 0.3)@2001-01-01, NPoint(1, 0.35)@2001-01-02, NPoint(1, 0.5)@2001-01-03]' -- true
Return the smallest distance ever between the two arguments
tgeompoint |=| tnpoint → float
SELECT tnpoint '[NPoint(1, 0.3)@2001-01-01, NPoint(1, 0.5)@2001-01-03]' |=| npoint 'NPoint(1, 0.2)'; -- 2.34988300875063 SELECT tnpoint '[NPoint(1, 0.3)@2001-01-01, NPoint(1, 0.5)@2001-01-03]' |=| geometry 'Linestring(2 2,2 1,3 1)'; -- 82.2059262761477
Return the temporal distance
tgeompoint <-> tnpoint → tfloat
SELECT tnpoint '[NPoint(1, 0.3)@2001-01-01, NPoint(1, 0.5)@2001-01-03]' <-> npoint 'NPoint(1, 0.2)'; -- [2.34988300875063@2001-01-02 00:00:00+01, 2.34988300875063@2001-01-03 00:00:00+01] SELECT tnpoint '[NPoint(1, 0.3)@2001-01-01, NPoint(1, 0.5)@2001-01-03]' <-> geometry 'Point(50 50)'; -- [25.0496666945044@2001-01-01 00:00:00+01, 26.4085688426232@2001-01-03 00:00:00+01] SELECT tnpoint '[NPoint(1, 0.3)@2001-01-01, NPoint(1, 0.5)@2001-01-03]' <-> tnpoint '[NPoint(1, 0.3)@2001-01-02, NPoint(1, 0.5)@2001-01-04]' -- [2.34988300875063@2001-01-02 00:00:00+01, 2.34988300875063@2001-01-03 00:00:00+01]
Ever and always spatial relationships
eContains(geometry,tnpoint) → boolean
aContains(geometry,tnpoint) → boolean
eDisjoint({geometry,npoint,tnpoint},{geometry,npoint,tnpoint}) → boolean
aDisjoint({geometry,npoint,tnpoint},{geometry,npoint,tnpoint}) → boolean
eIntersects({geometry,npoint,tnpoint},{geometry,npoint,tnpoint}) → boolean
aIntersects({geometry,npoint,tnpoint},{geometry,npoint,tnpoint}) → boolean
eTouches({geometry,npoint,tnpoint},{geometry,npoint,tnpoint}) → boolean
aTouches({geometry,npoint,tnpoint},{geometry,npoint,tnpoint}) → boolean
eDwithin({geometry,npoint,tnpoint},{geometry,npoint,tnpoint},float) → boolean
aDwithin({geometry,npoint,tnpoint},{geometry,npoint,tnpoint},float) → boolean
SELECT eContains(geometry 'Polygon((0 0,0 50,50 50,50 0,0 0))', tnpoint '[NPoint(1, 0.1)@2001-01-01, NPoint(1, 0.3)@2001-01-03)'); -- false SELECT eDisjoint(npoint 'NPoint(2, 0.0)', tnpoint '[NPoint(1, 0.1)@2001-01-01, NPoint(1, 0.3)@2001-01-03)'); -- true SELECT eIntersects(tnpoint '[NPoint(1, 0.1)@2001-01-01, NPoint(1, 0.3)@2001-01-03)', tnpoint '[NPoint(2, 0.0)@2001-01-01, NPoint(2, 1)@2001-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)@2001-01-01, NPoint(1, 0.3)@2001-01-03)'); -- {[t@2001-01-01 00:00:00+01, t@2001-01-03 00:00:00+01)} SELECT tDwithin(tnpoint '[NPoint(1, 0.3)@2001-01-01, NPoint(1, 0.5)@2001-01-03)', tnpoint '[NPoint(1, 0.5)@2001-01-01, NPoint(1, 0.3)@2001-01-03)', 1); /* {[t@2001-01-01 00:00:00+01, t@2001-01-01 22:35:55.379053+01], (f@2001-01-01 22:35:55.379053+01, t@2001-01-02 01:24:04.620946+01, t@2001-01-03 00:00:00+01)} */