Operands of different dimensions read the dimensions both of them have, see the section called “Operands of Different Dimensions”.
Each relationship of this section has two forms. The scalar form compares two values, a geometry or a temporal geometry on each side, and returns whether the relationship holds at some instant (prefix e, ever) or at every instant (prefix a, always) of the time they share. The array form, whose name ends in Pairs, compares every element of an array of temporal geometries with every element of another and returns, one row per pair, the one-based indexes i and j of the pairs for which the scalar form returns true. A pair sharing no instant, for which the scalar form returns null, is not returned. The array form states in a single call the spatial join of two sets of moving objects, which the scalar form states by comparing every pair of their cross product: the spatiotemporal box of each element settles the pairs whose boxes alone decide the relationship, and the relationship is computed exactly on the others. The indexes are positions in the arrays, and an array_agg of the identifiers in the order of the array of values maps them back to the objects. The array form is defined for temporal points and temporal geometries, planar and geodetic, where the scalar form is, except touches, contains and covers, whose array forms take temporal geometries. In the array form of contains and covers, the element of the first array is the one that contains or covers the element of the second.
The following example returns, for each pair of ships, whether they ever come within a distance of 2 of each other, first with the scalar form on two of them, then with the array form on all of them, mapping the indexes back to the identifiers.
SELECT eDwithin(tgeompoint '[Point(0 0)@2001-01-01, Point(0 10)@2001-01-02]',
tgeompoint '[Point(1 0)@2001-01-01, Point(1 10)@2001-01-02]', 2);
-- true
WITH ships(id, trip) AS (VALUES
('A', tgeompoint '[Point(0 0)@2001-01-01, Point(0 10)@2001-01-02]'),
('B', tgeompoint '[Point(50 50)@2001-01-01, Point(50 60)@2001-01-02]'),
('C', tgeompoint '[Point(1 0)@2001-01-01, Point(1 10)@2001-01-02]')),
fleet AS (SELECT array_agg(id ORDER BY id) AS ids,
array_agg(trip ORDER BY id) AS trips FROM ships)
SELECT ids[i] AS ship1, ids[j] AS ship2
FROM fleet, eDwithinPairs(trips, trips, 2)
WHERE i < j;
-- A | C
Ever or always contains
eContains({geometry,tgeom},{geometry,tgeom}) → boolean
aContains({geometry,tgeom},{geometry,tgeom}) → boolean
eContainsPairs(tgeometry[],tgeometry[]) → setof(i integer,j integer)
aContainsPairs(tgeometry[],tgeometry[]) → setof(i integer,j integer)
This function returns true if the first argument contains the second at some instant (ever) or at every instant (always) of the time they share, reading the value each argument takes at that instant. A temporal point moves continuously, so a geometry contains it at some instant if its trajectory meets the interior of the geometry, and at every instant if its trajectory lies in that interior; a point contains a geometry only where the geometry is that point. Recall that a geometry does not contain things in its boundary and thus, polygons and lines do not contain lines and points lying in their boundary. Please refer to the documentation of the ST_Contains function in PostGIS.
SELECT eContains(geometry 'Linestring(1 1,3 3)', tgeompoint '[Point(4 2)@2001-01-01, Point(2 4)@2001-01-02]'); -- false SELECT eContains(geometry 'Linestring(1 1,3 3,1 1)', tgeompoint '[Point(4 2)@2001-01-01, Point(2 4)@2001-01-03]'); -- true SELECT eContains(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]'); -- false SELECT eContains(geometry 'Polygon((1 1,1 3,3 3,3 1,1 1))', tgeometry '[Linestring(1 1,4 4)@2001-01-01, Point(3 3)@2001-01-04]'); -- true
The array form returns the pairs whose first element ever or always contains the second. In the following examples, the first point of the second array leaves the square on 2001-01-02, and the third one is never inside it.
SELECT i, j FROM eContainsPairs(
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(2 2)@2001-01-01, Point(2 2)@2001-01-03]',
tgeometry '[Point(6 6)@2001-01-01, Point(6 6)@2001-01-03]']);
-- 1 | 1
-- 1 | 2
SELECT i, j FROM aContainsPairs(
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(2 2)@2001-01-01, Point(2 2)@2001-01-03]',
tgeometry '[Point(6 6)@2001-01-01, Point(6 6)@2001-01-03]']);
-- 1 | 2
Ever or always covers
eCovers({geometry,tgeom},{geometry,tgeom}) → boolean
aCovers({geometry,tgeom},{geometry,tgeom}) → boolean
eCoversPairs(tgeometry[],tgeometry[]) → setof(i integer,j integer)
aCoversPairs(tgeometry[],tgeometry[]) → setof(i integer,j integer)
This function returns true if the first argument covers the second at some instant (ever) or at every instant (always) of the time they share, reading the value each argument takes at that instant. A temporal point moves continuously, so a geometry covers it at every instant if it covers its trajectory. Please refer to the documentation of the ST_Contains and the ST_Covers function in PostGIS for detailed explanations about the difference between the two functions.
SELECT eCovers(geometry 'Linestring(1 1,3 3)', tgeompoint '[Point(4 2)@2001-01-01, Point(2 4)@2001-01-02]'); -- false SELECT eCovers(geometry 'Linestring(1 1,3 3,1 1)', tgeompoint '[Point(4 2)@2001-01-01, Point(2 4)@2001-01-03]'); -- true SELECT eCovers(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]'); -- false SELECT eCovers(geometry 'Polygon((1 1,1 3,3 3,3 1,1 1))', tgeometry '[Linestring(1 1,4 4)@2001-01-01, Point(3 3)@2001-01-04]'); -- true
The array form returns the pairs whose first element ever or always covers the second. In the following examples, the first point of the second array lies on the boundary of the square, which covers it without containing it.
SELECT i, j FROM eCoversPairs(
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(4 2)@2001-01-01, Point(4 2)@2001-01-03]',
tgeometry '[Point(5 2)@2001-01-01, Point(2 2)@2001-01-02,
Point(2 2)@2001-01-03]']);
-- 1 | 1
-- 1 | 2
SELECT i, j FROM aCoversPairs(
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(4 2)@2001-01-01, Point(4 2)@2001-01-03]',
tgeometry '[Point(5 2)@2001-01-01, Point(2 2)@2001-01-02,
Point(2 2)@2001-01-03]']);
-- 1 | 1
Is ever or always disjoint
eDisjoint({geo,tgeo},{geo,tgeo}) → boolean
aDisjoint({geo,tgeo},{geo,tgeo}) → boolean
eDisjointPairs(tgeo[],tgeo[]) → setof(i integer,j integer)
aDisjointPairs(tgeo[],tgeo[]) → setof(i integer,j integer)
SELECT eDisjoint(geometry 'Polygon((0 0,0 1,1 1,1 0,0 0))', tgeompoint '[Point(0 0)@2001-01-01, Point(1 1)@2001-01-03)'); -- false SELECT eDisjoint(geometry 'Polygon((0 0 0,0 1 1,1 1 1,1 0 0,0 0 0))', tgeometry '[Linestring(1 1 1,2 2 2)@2001-01-01, Point(2 2 2)@2001-01-03]'); -- true
The array form returns the pairs that are ever or always disjoint. In the following examples, the first trip of the second array crosses the trip of the first array, which is ever but not always disjoint from it.
SELECT i, j FROM eDisjointPairs(
ARRAY[tgeompoint '[Point(0 0)@2001-01-01, Point(0 10)@2001-01-02]'],
ARRAY[tgeompoint '[Point(5 0)@2001-01-01, Point(-5 10)@2001-01-02]',
tgeompoint '[Point(0 0)@2001-01-01, Point(0 10)@2001-01-02]']);
-- 1 | 1
SELECT i, j FROM aDisjointPairs(
ARRAY[tgeompoint '[Point(0 0)@2001-01-01, Point(0 10)@2001-01-02]'],
ARRAY[tgeompoint '[Point(5 0)@2001-01-01, Point(-5 10)@2001-01-02]',
tgeompoint '[Point(5 0)@2001-01-01, Point(5 10)@2001-01-02]']);
-- 1 | 2
Is ever or always at distance within
eDwithin({geo,tgeo},{geo,tgeo},float) → boolean
aDwithin({geometry,tgeom},{geometry,tgeom},float) → boolean
eDwithin({geography,tgeog},{geography,tgeog},float,spheroid boolean=true) → boolean
aDwithin({geography,tgeog},{geography,tgeog},float,spheroid boolean=true) → boolean
eDwithinPairs(tgeom[],tgeom[],float) → setof(i integer,j integer)
aDwithinPairs(tgeom[],tgeom[],float) → setof(i integer,j integer)
eDwithinPairs(tgeog[],tgeog[],float,spheroid boolean=true) → setof(i integer,j integer)
aDwithinPairs(tgeog[],tgeog[],float,spheroid boolean=true) → setof(i integer,j integer)
For geographies, the computation is done on the WGS 84 spheroid by default. If the last argument is false, a faster spherical calculation is used. Geographies are supported as stated in the section called “Planar and Geodetic Computations”.
SELECT eDwithin(geometry 'Point(1 1 1)', tgeompoint '[Point(0 0 0)@2001-01-01, Point(1 1 0)@2001-01-02]', 1); -- true SELECT eDwithin(geometry 'Polygon((0 0 0,0 1 1,1 1 1,1 0 0,0 0 0))', tgeompoint '[Point(0 2 2)@2001-01-01,Point(2 2 2)@2001-01-02]', 1); -- false SELECT eDwithin(tgeogpoint '[Point(0 1)@2001-01-01, Point(0 2)@2001-01-02]', geography 'Point(0 0)', 110800); -- true SELECT eDwithin(tgeogpoint '[Point(0 1)@2001-01-01, Point(0 2)@2001-01-02]', geography 'Point(0 0)', 110800, false); -- false SELECT aDwithin(tgeogpoint 'Interp=Step;[Point(0.5 2.5)@2001-01-01, Point(2.5 2.5)@2001-01-02]', geography 'Polygon((0 0,3 0,3 3,2 3,2 1,1 1,1 3,0 3,0 0))', 50000); -- true
The array form returns the pairs that are ever or always within the distance. For geographies, as for the scalar form, the distance is measured on the WGS 84 spheroid by default and on the sphere if the last argument is false.
SELECT i, j FROM aDwithinPairs(
ARRAY[tgeompoint '[Point(0 0)@2001-01-01, Point(0 10)@2001-01-02]'],
ARRAY[tgeompoint '[Point(1 0)@2001-01-01, Point(1 10)@2001-01-02]',
tgeompoint '[Point(1 0)@2001-01-01, Point(5 10)@2001-01-02]'], 2);
-- 1 | 1
SELECT i, j FROM eDwithinPairs(
ARRAY[tgeogpoint '[Point(0 1)@2001-01-01, Point(0 2)@2001-01-02]'],
ARRAY[tgeogpoint '[Point(0 0)@2001-01-01, Point(0 0)@2001-01-02]'], 110800);
-- 1 | 1
SELECT count(*) FROM eDwithinPairs(
ARRAY[tgeogpoint '[Point(0 1)@2001-01-01, Point(0 2)@2001-01-02]'],
ARRAY[tgeogpoint '[Point(0 0)@2001-01-01, Point(0 0)@2001-01-02]'], 110800, false);
-- 0
Ever or always intersects
eIntersects({geo,tgeo},{geo,tgeo}) → boolean
aIntersects({geometry,tgeom},{geometry,tgeom}) → boolean
eIntersectsPairs(tgeo[],tgeo[]) → setof(i integer,j integer)
aIntersectsPairs(tgeo[],tgeo[]) → setof(i integer,j integer)
SELECT eIntersects(geometry 'Polygon((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0))', tgeompoint '[Point(0 0 1)@2001-01-01, Point(1 1 1)@2001-01-03)'); -- false SELECT eIntersects(geometry 'Polygon((0 0 0,0 1 1,1 1 1,1 0 0,0 0 0))', tgeompoint '[Point(0 0 1)@2001-01-01, Point(1 1 1)@2001-01-03)'); -- true
The array form returns the pairs that ever or always intersect. Two temporal points always intersect when they are equal at every instant they share.
SELECT i, j FROM eIntersectsPairs(
ARRAY[tgeompoint '[Point(0 0)@2001-01-01, Point(2 2)@2001-01-03]'],
ARRAY[tgeompoint '[Point(0 0)@2001-01-01, Point(2 2)@2001-01-03]',
tgeompoint '[Point(0 2)@2001-01-01, Point(2 0)@2001-01-03]',
tgeompoint '[Point(5 5)@2001-01-01, Point(6 6)@2001-01-03]']);
-- 1 | 1
-- 1 | 2
SELECT i, j FROM aIntersectsPairs(
ARRAY[tgeompoint '[Point(0 0)@2001-01-01, Point(2 2)@2001-01-03]'],
ARRAY[tgeompoint '[Point(0 0)@2001-01-01, Point(2 2)@2001-01-03]',
tgeompoint '[Point(0 2)@2001-01-01, Point(2 0)@2001-01-03]',
tgeompoint '[Point(5 5)@2001-01-01, Point(6 6)@2001-01-03]']);
-- 1 | 1
Ever or always touches
eTouches({geometry,tgeom},{geometry,tgeom}) → boolean
aTouches({geometry,tgeom},{geometry,tgeom}) → boolean
eTouchesPairs(tgeometry[],tgeometry[]) → setof(i integer,j integer)
aTouchesPairs(tgeometry[],tgeometry[]) → setof(i integer,j integer)
SELECT eTouches(geometry 'Polygon((0 0,0 1,1 1,1 0,0 0))', tgeompoint '[Point(0 0)@2001-01-01, Point(0 1)@2001-01-03)'); -- true
The array form returns the pairs of temporal geometries that ever or always touch. In the following examples, the first geometry of the second array touches the geometry of the first array until it moves away on 2001-01-02.
SELECT i, j FROM eTouchesPairs(
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]',
tgeometry '[Polygon((3 0,5 0,5 2,3 2,3 0))@2001-01-01,
Polygon((3 0,5 0,5 2,3 2,3 0))@2001-01-03]']);
-- 1 | 1
SELECT i, j FROM aTouchesPairs(
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((2 0,4 0,4 2,2 2,2 0))@2001-01-03]',
tgeometry '[Polygon((3 0,5 0,5 2,3 2,3 0))@2001-01-01,
Polygon((3 0,5 0,5 2,3 2,3 0))@2001-01-03]']);
-- 1 | 1