Each relationship of this section also has an array form, whose name ends in Pairs, as the ever and always relationships of the section called “Ever and Always Relationships” do. It compares every element of an array of temporal geometries with every element of another and returns, one row per pair whose temporal relationship is ever true, the one-based indexes i and j of the pair and the periods periods during which the relationship is true.
Temporal contains
tContains(geometry,tgeom) → tbool
tContains(tgeometry,{geometry,tgeometry}) → tbool
tContainsPairs(tgeometry[],tgeometry[]) → setof(i integer,j integer,periods tstzspanset)
SELECT tContains(geometry 'Linestring(1 1,3 3)',
tgeompoint '[Point(4 2)@2001-01-01, Point(2 4)@2001-01-02]');
-- {[f@2001-01-01, f@2001-01-02]}
SELECT tContains(geometry 'Linestring(1 1,3 3,1 1)',
tgeompoint '[Point(4 2)@2001-01-01, Point(2 4)@2001-01-03]');
-- {[f@2001-01-01, t@2001-01-02], (f@2001-01-02, f@2001-01-03]}
SELECT tContains(geometry 'Polygon((1 1,1 3,3 3,3 1,1 1))',
tgeompoint '[Point(0 1)@2001-01-01, Point(4 1)@2001-01-02]');
-- {[f@2001-01-01, f@2001-01-02]}
SELECT tContains(geometry 'Polygon((1 1,1 3,3 3,3 1,1 1))',
tgeompoint '[Point(1 4)@2001-01-01, Point(4 1)@2001-01-04]');
-- {[f@2001-01-01, f@2001-01-02], (t@2001-01-02, f@2001-01-03, f@2001-01-04]}
The array form returns the pairs whose first element contains the second at some instant, with the periods during which it contains it.
SELECT i, j, periods FROM tContainsPairs(
ARRAY[tgeometry '[Polygon((0 0,4 0,4 4,0 4,0 0))@2001-01-01,
Polygon((0 0,4 0,4 4,0 4,0 0))@2001-01-03]'],
ARRAY[tgeometry '[Point(1 1)@2001-01-01, Point(5 5)@2001-01-02,
Point(5 5)@2001-01-03]',
tgeometry '[Point(6 6)@2001-01-01, Point(6 6)@2001-01-03]']);
-- 1 | 1 | {[2001-01-01, 2001-01-02)}
Temporal covers
tCovers(geometry,tgeom) → tbool
tCovers(tgeometry,{geometry,tgeometry}) → tbool
tCoversPairs(tgeometry[],tgeometry[]) → setof(i integer,j integer,periods tstzspanset)
A geometry covers a moving point when the point lies in the geometry or on its boundary, which is the temporal intersects of the two. Please refer to the documentation of the ST_Covers function in PostGIS for the difference between covers and contains.
SELECT tCovers(geometry 'Polygon((1 1,1 3,3 3,3 1,1 1))',
tgeompoint '[Point(0 1)@2001-01-01, Point(4 1)@2001-01-05]');
-- {[f@2001-01-01, t@2001-01-02, t@2001-01-04], (f@2001-01-04, f@2001-01-05]}
SELECT tCovers(geometry 'Polygon((1 1,1 3,3 3,3 1,1 1))',
tgeometry '[Linestring(1 1,2 2)@2001-01-01, Linestring(2 2,4 4)@2001-01-03]');
-- [t@2001-01-01, f@2001-01-03]
The array form returns the pairs whose first element covers the second at some instant, with the periods during which it covers it.
SELECT i, j, periods FROM tCoversPairs(
ARRAY[tgeometry '[Polygon((0 0,4 0,4 4,0 4,0 0))@2001-01-01,
Polygon((0 0,4 0,4 4,0 4,0 0))@2001-01-03]'],
ARRAY[tgeometry '[Point(5 2)@2001-01-01, Point(4 2)@2001-01-02,
Point(4 2)@2001-01-03]']);
-- 1 | 1 | {[2001-01-02, 2001-01-03]}
Temporal disjoint
tDisjoint({geo,tgeo},{geo,tgeo}) → tbool
tDisjointPairs(tgeo[],tgeo[]) → setof(i integer,j integer,periods tstzspanset)
The function is the negation of tIntersects. Geographies are supported as stated in the section called “Planar and Geodetic Computations”.
SELECT tDisjoint(geometry 'Polygon((1 1,1 2,2 2,2 1,1 1))',
tgeompoint '[Point(0 0)@2001-01-01, Point(3 3)@2001-01-04)');
-- {[t@2001-01-01, f@2001-01-02, f@2001-01-03], (t@2001-01-03, t@2001-01-04]}
SELECT tDisjoint(tgeompoint '[Point(0 3)@2001-01-01, Point(3 0)@2001-01-05)',
tgeompoint '[Point(0 0)@2001-01-01, Point(3 3)@2001-01-05)');
-- {[t@2001-01-01, f@2001-01-03], (t@2001-01-03, t@2001-01-05)}
The array form returns the pairs that are disjoint at some instant, with the periods during which they are disjoint.
SELECT i, j, periods FROM tDisjointPairs(
ARRAY[tgeompoint '[Point(0 3)@2001-01-01, Point(3 0)@2001-01-05)'],
ARRAY[tgeompoint '[Point(0 0)@2001-01-01, Point(3 3)@2001-01-05)']);
-- 1 | 1 | {[2001-01-01, 2001-01-03), (2001-01-03, 2001-01-05)}
Temporal distance within
tDwithin({geo,tgeo},{geo,tgeo},float) → tbool
tDwithin({geography,tgeog},{geography,tgeog},float,spheroid boolean=true) → tbool
tDwithinPairs(tgeom[],tgeom[],float) → setof(i integer,j integer,periods tstzspanset)
Geographies are supported as stated in the section called “Planar and Geodetic Computations”. The distance is measured on the WGS 84 spheroid by default. If the last argument is false, it is measured on the sphere. A segment of a temporal geography point moves along a great circle, and the result changes its value at every instant at which the geodetic distance crosses the given distance, which a segment may cross several times.
SELECT tDwithin(geometry 'Point(1 1)',
tgeompoint '[Point(0 0)@2001-01-01, Point(2 2)@2001-01-03)', sqrt(2));
-- {[t@2001-01-01, t@2001-01-03)}
SELECT tDwithin(tgeompoint '[Point(1 0)@2001-01-01, Point(1 4)@2001-01-05]',
tgeompoint 'Interp=Step;[Point(1 2)@2001-01-01, Point(1 3)@2001-01-05]', 1);
-- {[f@2001-01-01, t@2001-01-02, t@2001-01-04], (f@2001-01-04, t@2001-01-05]}
SELECT tDwithin(geography 'Point(1 0.1)',
tgeogpoint '[Point(0 0)@2001-01-01, Point(2 0)@2001-01-03]', 15000);
/* {[f@2001-01-01, t@2001-01-01 21:48:53.195554, t@2001-01-02 02:11:06.804445],
(f@2001-01-02 02:11:06.804445, f@2001-01-03]} */
SELECT tDwithin(tgeogpoint '[Point(0 0)@2001-01-01, Point(2 0)@2001-01-03]',
tgeogpoint '[Point(1 1)@2001-01-01, Point(1 -1)@2001-01-03]', 20000, false);
/* {[f@2001-01-01, t@2001-01-01 20:56:51.37512, t@2001-01-02 03:03:08.624879],
(f@2001-01-02 03:03:08.624879, f@2001-01-03]} */
SELECT tDwithin(tgeography '[Polygon((0 0,2 0,2 2,0 2,0 0))@2001-01-01,
Point(3 3)@2001-01-02, Polygon((2 2,4 2,4 4,2 4,2 2))@2001-01-03]',
geography 'Point(1 1)', 200000);
-- [t@2001-01-01, f@2001-01-02, t@2001-01-03]
The array form returns the pairs that are within the distance at some instant, with the periods during which they are within it.
SELECT i, j, periods FROM tDwithinPairs(
ARRAY[tgeompoint '[Point(0 0)@2001-01-01, Point(0 10)@2001-01-03]',
tgeompoint '[Point(50 50)@2001-01-01, Point(50 60)@2001-01-03]'],
ARRAY[tgeompoint '[Point(1 0)@2001-01-01, Point(1 10)@2001-01-03]',
tgeompoint '[Point(4 0)@2001-01-01, Point(0 10)@2001-01-03]'], 2);
-- 1 | 1 | {[2001-01-01, 2001-01-03]}
-- 1 | 2 | {[2001-01-02, 2001-01-03]}
Temporal intersects
tIntersects({geo,tgeo},{geo,tgeo}) → tbool
tIntersectsPairs(tgeo[],tgeo[]) → setof(i integer,j integer,periods tstzspanset)
Two temporal points intersect at the instants at which they are equal. Two temporal geometries or geographies, whose values are constant between their instants, intersect at the instants at which their values intersect, and two geographies intersect where their distance is zero. Geographies are supported as stated in the section called “Planar and Geodetic Computations”.
SELECT tIntersects(geometry 'MultiPoint(1 1,2 2)',
tgeompoint '[Point(0 0)@2001-01-01, Point(3 3)@2001-01-04)');
/* {[f@2001-01-01, t@2001-01-02], (f@2001-01-02, t@2001-01-03],
(f@2001-01-03, f@2001-01-04]} */
SELECT tIntersects(tgeompoint '[Point(0 3)@2001-01-01, Point(3 0)@2001-01-05)',
tgeompoint '[Point(0 0)@2001-01-01, Point(3 3)@2001-01-05)');
-- {[f@2001-01-01, t@2001-01-03], (f@2001-01-03, f@2001-01-05)}
SELECT tIntersects(tgeometry '[Polygon((0 0,2 0,2 2,0 2,0 0))@2001-01-01,
Point(3 3)@2001-01-02]', tgeometry '[Point(1 1)@2001-01-01, Point(1 1)@2001-01-02]');
-- [t@2001-01-01, f@2001-01-02]
SELECT tIntersects(tgeography '[Polygon((0 0,2 0,2 2,0 2,0 0))@2001-01-01,
Point(3 3)@2001-01-02, Polygon((2 2,4 2,4 4,2 4,2 2))@2001-01-03]',
geography 'Point(1 1)');
-- [t@2001-01-01, f@2001-01-02, f@2001-01-03]
The array form returns the pairs that intersect at some instant, with the periods during which they intersect.
SELECT i, j, periods FROM tIntersectsPairs(
ARRAY[tgeompoint '[Point(0 3)@2001-01-01, Point(3 0)@2001-01-05)'],
ARRAY[tgeompoint '[Point(0 0)@2001-01-01, Point(3 3)@2001-01-05)',
tgeompoint '[Point(0 1)@2001-01-01, Point(3 4)@2001-01-05)']);
-- 1 | 1 | {[2001-01-03, 2001-01-03]}
-- 1 | 2 | {[2001-01-02 08:00:00, 2001-01-02 08:00:00]}
Temporal touches
tTouches({geometry,tgeom},{geometry,tgeom}) → tbool
tTouchesPairs(tgeometry[],tgeometry[]) → setof(i integer,j integer,periods tstzspanset)
SELECT tTouches(geometry 'Polygon((1 0,1 2,2 2,2 0,1 0))',
tgeompoint '[Point(0 0)@2001-01-01, Point(3 0)@2001-01-04)');
-- {[f@2001-01-01, t@2001-01-02, t@2001-01-03], (f@2001-01-03, f@2001-01-04]}
The array form returns the pairs of temporal geometries that touch at some instant, with the periods during which they touch.
SELECT i, j, periods FROM tTouchesPairs(
ARRAY[tgeometry '[Polygon((0 0,2 0,2 2,0 2,0 0))@2001-01-01,
Polygon((0 0,2 0,2 2,0 2,0 0))@2001-01-03]'],
ARRAY[tgeometry '[Polygon((2 0,4 0,4 2,2 2,2 0))@2001-01-01,
Polygon((3 0,5 0,5 2,3 2,3 0))@2001-01-02, Polygon((3 0,5 0,5 2,3 2,3 0))@2001-01-03]']);
-- 1 | 1 | {[2001-01-01, 2001-01-02)}