# Temporal Geometry Types (Part 2)

## Restrictions

- Restrict to (the complement of) a geometry, a Z span, and/or a period &Z_support;

  `atGeometry(tgeom,geometry[,zspan]) → tgeom`

  `minusGeometry(tgeom,geometry[,zspan]) → tgeom`

  The geometry must be in 2D and the computation with respect to it is done in 2D. The result preserves the Z dimension of the temporal point, if it exists.

      SELECT asText(atGeometry(tgeompoint '[Point(0 0)@2001-01-01, Point(3 3)@2001-01-04)',
        geometry 'Polygon((1 1,1 2,2 2,2 1,1 1))'));
      -- {"[POINT(1 1)@2001-01-02, POINT(2 2)@2001-01-03]"}
      SELECT astext(atGeometry(tgeompoint '[Point(0 0 0)@2001-01-01, Point(4 4 4)@2001-01-05]',
        geometry 'Polygon((1 1,1 2,2 2,2 1,1 1))'));
      -- {[POINT Z (1 1 1)@2001-01-02, POINT Z (2 2 2)@2001-01-03]}
      SELECT asText(atGeometry(tgeompoint '[Point(1 1 1)@2001-01-01, Point(3 1 1)@2001-01-03,
        Point(3 1 3)@2001-01-05]', 'Polygon((2 0,2 2,2 4,4 0,2 0))', '[0,2]'));
      -- {[POINT Z (2 1 1)@2001-01-02, POINT Z (3 1 1)@2001-01-03, POINT Z (3 1 2)@2001-01-04]}
      SELECT asText(atGeometry(tgeometry 'Linestring(1 1,10 1)@2001-01-01',
        'Polygon((0 0,0 5,5 5,5 0,0 0))'));
      -- LINESTRING(1 1,5 1)@2001-01-01

      SELECT asText(minusGeometry(tgeompoint '[Point(0 0)@2001-01-01, Point(3 3)@2001-01-04)',
        geometry 'Polygon((1 1,1 2,2 2,2 1,1 1))'));
      /* {[POINT(0 0)@2001-01-01, POINT(1 1)@2001-01-02), (POINT(2 2)@2001-01-03,
         POINT(3 3)@2001-01-04)} */
      SELECT astext(minusGeometry(tgeompoint '[Point(0 0 0)@2001-01-01,
        Point(4 4 4)@2001-01-05]', geometry 'Polygon((1 1,1 2,2 2,2 1,1 1))'));
      /* {[POINT Z (0 0 0)@2001-01-01, POINT Z (1 1 1)@2001-01-02),
         (POINT Z (2 2 2)@2001-01-03, POINT Z (4 4 4)@2001-01-05]} */
      SELECT asText(minusGeometry(tgeompoint '[Point(1 1 1)@2001-01-01, Point(3 1 1)@2001-01-03,
        Point(3 1 3)@2001-01-05]', 'Polygon((2 0,2 2,2 4,4 0,2 0))', '[0,2]'));
      /* {[POINT Z (1 1 1)@2001-01-01, POINT Z (2 1 1)@2001-01-02),
          (POINT Z (3 1 2)@2001-01-04, POINT Z (3 1 3)@2001-01-05]} */
      SELECT asText(minusGeometry(tgeometry 'Linestring(1 1,10 1)@2001-01-01',
        'Polygon((0 0,0 5,5 5,5 0,0 0))'));
      -- LINESTRING(5 1,10 1)@2001-01-01

- Restrict to (the complement of) an `stbox` &Z_support;

  `atStbox(tgeom,stbox,borderInc bool=true) → tgeompoint`

  `minusStbox(tgeom,stbox,borderInc bool=true) → tgeompoint`

  The third optional argument is used for multidimensional tiling (see ttype_tiling) to exclude the upper border of the tiles when a temporal value is split in multiple tiles, so that all fragments of the temporal geometry are exclusive.

      SELECT asText(atStbox(tgeompoint '[Point(0 0)@2001-01-01, Point(3 3)@2001-01-04)',
        stbox 'STBOX XT(((0,0),(2,2)),[2001-01-02, 2001-01-04])'));
      -- {[POINT(1 1)@2001-01-02, POINT(2 2)@2001-01-03]}
      SELECT asText(atStbox(tgeompoint '[Point(1 1 1)@2001-01-01, Point(3 3 3)@2001-01-03,
        Point(3 3 2)@2001-01-04, Point(3 3 7)@2001-01-09]', stbox 'STBOX Z((2,2,2),(3,3,3))'));
      /* {[POINT Z (2 2 2)@2001-01-02, POINT Z (3 3 3)@2001-01-03, POINT Z (3 3 2)@2001-01-04,
        POINT Z (3 3 3)@2001-01-05]} */
      SELECT asText(atStbox(tgeometry '[Point(1 1)@2001-01-01, Linestring(1 1,3 3)@2001-01-03,
        Point(2 2)@2001-01-04, Linestring(3 3,4 4)@2001-01-09]', stbox 'STBOX X((2,2),(3,3))'));
      -- {[LINESTRING(2 2,3 3)@2001-01-03, POINT(2 2)@2001-01-04, POINT(3 3)@2001-01-09]}

      SELECT asText(minusStbox(tgeompoint '[Point(1 1)@2001-01-01, Point(4 4)@2001-01-04)',
        stbox 'STBOX XT(((1,1),(2,2)),[2001-01-03,2001-01-04])'));
      -- {(POINT(2 2)@2001-01-02, POINT(3 3)@2001-01-03)}
      SELECT asText(minusStbox(tgeompoint '[Point(1 1 1)@2001-01-01, Point(3 3 3)@2001-01-03,
        Point(3 3 2)@2001-01-04, Point(3 3 7)@2001-01-09]', stbox 'STBOX Z((2,2,2),(3,3,3))'));
      /* {[POINT Z (1 1 1)@2001-01-01, POINT Z (2 2 2)@2001-01-02),
          (POINT Z (3 3 3)@2001-01-05, POINT Z (3 3 7)@2001-01-09]} */
      SELECT asText(minusStbox(tgeometry '[Point(1 1)@2001-01-01,
        Linestring(1 1,3 3)@2001-01-03, Point(2 2)@2001-01-04,
        Linestring(1 1,4 4)@2001-01-09]', stbox 'STBOX X((2,2),(3,3))'));
      /* {[POINT(1 1)@2001-01-01, LINESTRING(1 1,2 2)@2001-01-03,
         LINESTRING(1 1,2 2)@2001-01-04),[MULTILINESTRING((1 1,2 2),(3 3,4 4))@2001-01-09]} */

## Spatial Reference System

- Return or set the spatial reference identifier &Z_support; &geography_support;

  `SRID(tspatial) → integer`

  `setSRID(tspatial) → tspatial`

      SELECT SRID(tgeompoint 'Point(0 0)@2001-01-01');
      -- 0
      SELECT asEWKT(setSRID(tgeompoint '[Point(0 0)@2001-01-01, Point(1 1)@2001-01-02)', 4326));
      -- SRID=4326;[POINT(0 0)@2001-01-01, POINT(1 1)@2001-01-02)

- Transform to a spatial reference identifier &Z_support; &geography_support;

  `transform(tspatial,integer) → tspatial`

  `transformPipeline(tspatial,pipeline text,to_srid integer,is_forward bool=true) → tspatial`

  The `transform` function specifies the transformation with a target SRID. An error is raised when the input temporal point has an unknown SRID (represented by 0).

  The `transformPipeline` function specifies the transformation with a defined coordinate transformation pipeline represented with the following string format:

  `urn:ogc:def:coordinateOperation:AUTHORITY::CODE`

  The SRID of the input temporal point is ignored, and the SRID of the output temporal point will be set to zero unless a value is provided via the optional `to_srid` parameter. As stated by the last parameter, the pipeline is executed by default in a forward direction; by setting the parameter to false, the pipeline is executed in the inverse direction.

      SELECT asEWKT(transform(tgeompoint 'SRID=4326;Point(4.35 50.85)@2001-01-01', 3812));
      -- SRID=3812;POINT(648679.018035303 671067.055638114)@2001-01-01

      WITH test(tgeo, pipeline) AS (
        SELECT tgeogpoint 'SRID=4326;{Point(4.3525 50.846667 100.0)@2001-01-01,
          Point(-0.1275 51.507222 100.0)@2001-01-02}',
          text 'urn:ogc:def:coordinateOperation:EPSG::16031' )
      SELECT asEWKT(transformPipeline(transformPipeline(tgeo, pipeline, 4326),
        pipeline, 4326, false), 6)
      FROM test;
      /* SRID=4326;{POINT Z (4.3525 50.846667 100)@2001-01-01,
         POINT Z (-0.1275 51.507222 100)@2001-01-02} */

## Bounding Box Operations

- Return the spatiotemporal bounding box expanded in the spatial dimension by a float value &Z_support; &geography_support;

  `expandSpace({spatial,tspatial},float) → stbox`

      SELECT expandSpace(geography 'Linestring(0 0,1 1)', 2);
      -- SRID=4326;GEODSTBOX X((-2,-2),(3,3))
      SELECT expandSpace(tgeompoint 'Point(0 0)@2001-01-01', 2);
      -- STBOX XT(((-2,-2),(2,2)),[2001-01-01,2001-01-01])

## Distance Operations

- Return the smallest distance ever &Z_support; &geography_support;

  `{geo,tgeo} |=| {geo,tgeo} → float`

      SELECT tgeompoint '[Point(0 0)@2001-01-02, Point(1 1)@2001-01-04, Point(0 0)@2001-01-06)'
        |=| geometry 'Linestring(2 2,2 1,3 1)';
      -- 1
      SELECT tgeompoint '[Point(0 0)@2001-01-01, Point(1 1)@2001-01-03, Point(0 0)@2001-01-05)'
        |=| tgeompoint '[Point(2 0)@2001-01-02, Point(1 1)@2001-01-04, Point(2 2)@2001-01-06)';
      -- 0.5
      SELECT tgeompoint '[Point(0 0 0)@2001-01-01, Point(1 1 1)@2001-01-03,
        Point(0 0 0)@2001-01-05)' |=| tgeompoint '[Point(2 0 0)@2001-01-02,
        Point(1 1 1)@2001-01-04, Point(2 2 2)@2001-01-06)';
      -- 0.5
      SELECT tgeometry '(Point(1 1)@2001-01-01, Linestring(3 1,1 1)@2001-01-03]' |=|
        geometry 'Linestring(1 3,2 2,3 3)';
      -- 1

  The operator `|=|` can be used for doing nearest neighbor searches using a GiST or an SP-GiST index (see ttype_indexing). This operator corresponds to the PostGIS function `ST_DistanceCPA`, altough the latter requires both arguments to be a trajectory.

      SELECT ST_DistanceCPA(
        tgeompoint '[Point(0 0 0)@2001-01-01, Point(1 1 1)@2001-01-03,
          Point(0 0 0)@2001-01-05)'::geometry,
        tgeompoint '[Point(2 0 0)@2001-01-02, Point(1 1 1)@2001-01-04,
          Point(2 2 2)@2001-01-06)'::geometry);
      -- 0.5

- Return the instant of the first temporal point at which the two arguments are at the nearest distance &Z_support; &geography_support;

  `nearestApproachInstant({geo,tgeo},{geo,tgeo}) → tgeo`

  The function will only return the first instant that it finds if there are more than one. The resulting instant may be at an exclusive bound.

      SELECT asText(nearestApproachInstant(tgeompoint '(Point(1 1)@2001-01-01,
        Point(3 1)@2001-01-03]', geometry 'Linestring(1 3,2 2,3 3)'));
      -- POINT(2 1)@2001-01-02
      SELECT asText(nearestApproachInstant(tgeompoint 'Interp=Step;(Point(1 1)@2001-01-01,
        Point(3 1)@2001-01-03]', geometry 'Linestring(1 3,2 2,3 3)'));
      -- POINT(1 1)@2001-01-01
      SELECT asText(nearestApproachInstant(tgeompoint '(Point(1 1)@2001-01-01,
        Point(2 2)@2001-01-03]', tgeompoint '(Point(1 1)@2001-01-01, Point(4 1)@2001-01-03]'));
      -- POINT(1 1)@2001-01-01
      SELECT asText(nearestApproachInstant(tgeometry
        '[Linestring(0 0 0,1 1 1)@2001-01-01, Point(0 0 0)@2001-01-03]', tgeometry
        '[Point(2 0 0)@2001-01-02, Point(1 1 1)@2001-01-04, Point(2 2 2)@2001-01-06]'));
      -- LINESTRING Z (0 0 0,1 1 1)@2001-01-02

  Function `nearestApproachInstant` generalizes the PostGIS function `ST_ClosestPointOfApproach`. First, the latter function requires both arguments to be trajectories. Second, function `nearestApproachInstant` returns both the point and the timestamp of the nearest point of approach while the PostGIS function only provides the timestamp as shown next.

      SELECT to_timestamp(ST_ClosestPointOfApproach(
        tgeompoint '[Point(0 0 0)@2001-01-01, Point(1 1 1)@2001-01-03,
          Point(0 0 0)@2001-01-05)'::geometry,
        tgeompoint '[Point(2 0 0)@2001-01-02, Point(1 1 1)@2001-01-04,
          Point(2 2 2)@2001-01-06)'::geometry));
      -- 2001-01-03 12:00:00+00

- Return the line connecting the nearest approach point &Z_support; &geography_support;

  `shortestLine({geo,tgeo},{geo,tgeo}) → geo`

  The function will only return the first line that it finds if there are more than one.

      SELECT ST_AsText(shortestLine(tgeompoint '(Point(1 1)@2001-01-01,
        Point(3 1)@2001-01-03]', geometry 'Linestring(1 3,2 2,3 3)'));
      -- LINESTRING(2 1,2 2)
      SELECT ST_AsText(shortestLine(tgeompoint 'Interp=Step;(Point(1 1)@2001-01-01,
        Point(3 1)@2001-01-03]', geometry 'Linestring(1 3,2 2,3 3)'));
      -- LINESTRING(1 1,2 2)
      SELECT ST_AsText(shortestLine(tgeometry
        '[Linestring(0 0 0,1 1 1)@2001-01-01, Point(0 0 0)@2001-01-03]', tgeometry
        '[Point(2 0 0)@2001-01-02, Point(1 1 1)@2001-01-04, Point(2 2 2)@2001-01-06]'));
      -- LINESTRING Z (0 0 0,2 0 0)

  Function `shortestLine` can be used to obtain the result provided by the PostGIS function `ST_CPAWithin` when both arguments are trajectories as shown next.

      SELECT ST_Length(shortestLine(
        tgeompoint '[Point(0 0 0)@2001-01-01, Point(1 1 1)@2001-01-03,
          Point(0 0 0)@2001-01-05)',
        tgeompoint '[Point(2 0 0)@2001-01-02, Point(1 1 1)@2001-01-04,
          Point(2 2 2)@2001-01-06)')) <= 0.5;
      -- true
      SELECT ST_CPAWithin(
        tgeompoint '[Point(0 0 0)@2001-01-01, Point(1 1 1)@2001-01-03,
          Point(0 0 0)@2001-01-05)'::geometry,
        tgeompoint '[Point(2 0 0)@2001-01-02, Point(1 1 1)@2001-01-04,
          Point(2 2 2)@2001-01-06)'::geometry, 0.5);
      -- true

The temporal distance operator, denoted `<->`, computes the distance at each instant of the intersection of the temporal extents of their arguments and results in a temporal float. Computing temporal distance is useful in many mobility applications. For example, a moving cluster (also known as convoy or flock) is defined as a set of objects that move close to each other for a long time interval. This requires to compute temporal distance between two moving objects.

The temporal distance operator accepts a geometry/geography restricted to a point or a temporal point as arguments. Notice that the temporal types only consider linear interpolation between values, while the distance is a root of a quadratic function. Therefore, the temporal distance operator gives a linear approximation of the actual distance value for temporal sequence points. In this case, the arguments are synchronized in the time dimension, and for each of the composing line segments of the arguments, the spatial distance between the start point, the end point, and the nearest point of approach is computed, as shown in the examples below.

- Return the temporal distance &Z_support; &geography_support;

  `{geo,tgeo} <-> {geo,tgeo} → tfloat`

      SELECT tgeompoint '[Point(0 0)@2001-01-01, Point(1 1)@2001-01-03)' <->
        geometry 'Point(0 1)';
      -- [1@2001-01-01, 0.707106781186548@2001-01-02, 1@2001-01-03)
      SELECT tgeompoint '[Point(0 0)@2001-01-01, Point(1 1)@2001-01-03)' <->
        tgeompoint '[Point(0 1)@2001-01-01, Point(1 0)@2001-01-03)';
      -- [1@2001-01-01, 0@2001-01-02, 1@2001-01-03)
      SELECT tgeompoint '[Point(0 1)@2001-01-01, Point(0 0)@2001-01-03)' <->
        tgeompoint '[Point(0 0)@2001-01-01, Point(1 0)@2001-01-03)';
      -- [1@2001-01-01, 0.707106781186548@2001-01-02, 1@2001-01-03)
      SELECT tgeometry '[Point(0 0)@2001-01-01, Linestring(0 0,1 1)@2001-01-02]' <->
        tgeometry '[Point(0 1)@2001-01-01, Point(1 0)@2001-01-02)';
      -- Interp=Step;[1@2001-01-01, 1@2001-01-02]

## Spatial Relationships

The topological relationships such as `ST_Intersects` and the distance relationships such as `ST_DWithin` can be generalized for temporal geometries. The arguments of these generalized functions are either a temporal geometry (that is, a `tgeometry`, a `tgeography`, a `tgeompoint`, or a `tgeogpoint)` and a base type (that is, a `geometry` or a `geography`) or two temporal geometries. Furthermore, both arguments must be of the same base type or the same temporal type, for example, these functions do not allow to mix a `tgeometry` and a `geography` or a `tgeometry` and a `tgeompoint`.

There are three versions of the relationships:

- The ever relationships determine whether the topological or distance relationship is ever satisfied (see ever_always_comparison) and returns a `boolean`. Examples are the `eIntersects` and `eDwithin` functions.

- The always relationships determine whether the topological or distance relationship is always satisfied (see ever_always_comparison) and returns a `boolean`. Examples are the `aIntersects` and `aDwithin` functions.

- The temporal relationships compute the topological or distance relationship at each instant and results in a `tbool`. Examples are the `tIntersects` and `tDwithin` functions.

For example, the following query

    SELECT eIntersects(geometry 'Polygon((1 1,1 3,3 3,3 1,1 1))',
      tgeompoint '[Point(0 2)@2001-01-01, Point(4 2)@2001-01-05)');
    -- t

tests whether the temporal point ever intersects the geometry. In this case, the query is equivalent to the following one

    SELECT ST_Intersects(geometry 'Polygon((1 1,1 3,3 3,3 1,1 1))',
      geometry 'Linestring(0 2,4 2)');

where the second geometry is obtained by applying the `trajectory` function to the temporal point.

In contrast, the query

    SELECT tIntersects(geometry 'Polygon((1 1,1 3,3 3,3 1,1 1))',
      tgeompoint '[Point(0 2)@2001-01-01, Point(4 2)@2001-01-05)');
    -- {[f@2001-01-01, t@2001-01-02, t@2001-01-04], (f@2001-01-04, f@2001-01-05)}

computes at each instant whether the temporal point intersects the geometry. Similarly, the following query

    SELECT eDwithin(tgeompoint '[Point(3 1)@2001-01-01, Point(5 1)@2001-01-03)',
      tgeompoint '[Point(3 1)@2001-01-01, Point(1 1)@2001-01-03)', 2);
    -- t

tests whether the distance between the temporal points was ever less than or equal to 2, while the following query

    SELECT tDwithin(tgeompoint '[Point(3 1)@2001-01-01, Point(5 1)@2001-01-03)',
      tgeompoint '[Point(3 1)@2001-01-01, Point(1 1)@2001-01-03)', 2);
    -- {[t@2001-01-01, t@2001-01-02], (f@2001-01-02, f@2001-01-03)}

computes at each instant whether the distance between the temporal points is less than or equal to 2.

The ever or always relationships are sometimes used in combination with a spatiotemporal index when computing the temporal relationships. For example, the following query

    SELECT T.TripId, R.RegionId, tIntersects(T.Trip, R.Geom)
    FROM Trips T, Regions R
    WHERE eIntersects(T.Trip, R.Geom)

which verifies whether a trip `T` (which is a temporal point) intersects a region `R` (which is a geometry), will benefit from a spatiotemporal index on the column `T.Trip` since the `eIntersects` function will automatically perform the bounding box comparison `T.Trip && R.Geom`. This is further explained later in this document.

Not all spatial relationships available in PostGIS have been generalized for temporal geometries, only those derived from the following functions: `ST_Contains`, `ST_Covers`, `ST_Disjoint`, `ST_Intersects`, `ST_Touches`, and `ST_DWithin`. These functions only suport 2D geometries and only the functions `ST_Covers`, `ST_Intersects`, and `ST_DWithin` suport geographies. Consequently, the same applies for the MobilityDB functions derived from them, excepted that they support 3D for temporal points, that is, `tgeompoint`, and `tgeogpoint`. As stated above, each of the above PostGIS functions, such as `ST_Contains`, has three generalized versions in MobilityDB, namely `eContains`, `aContains`, and `tContains`. Furthermore, not all combinations of parameters are meaningful for the generalized functions. For example, `tContains(tpoint, geometry)` is meaningful only when the geometry is a single point, and `tContains(tpoint, tpoint)` is equivalent to `tintersects(tpoint, geometry)`.

### Ever and Always Relationships

We present next the ever and always relationships. These relationships automatically include a bounding box comparison that makes use of any spatial indexes that are available on the arguments.

- Ever or always contains

  `eContains({geometry,tgeom},{geometry,tgeom}) → boolean`

  `aContains({geometry,tgeom},{geometry,tgeom}) → boolean`

  This function returns true if the temporal geometry and the geometry ever or always intersect at their interior. 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

- Ever or always covers

  `eCovers({geometry,tgeom},{geometry,tgeom}) → boolean`

  `aCovers({geometry,tgeom},{geometry,tgeom}) → boolean`

  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

- Is ever or always disjoint &Z_support; &geography_support;

  `eDisjoint({geo,tgeo},{geo,tgeo}) → boolean`

  `aDisjoint({geo,tgeo},{geo,tgeo}) → boolean`

      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

- Is ever or always at distance within &Z_support; &geography_support;

  `eDwithin({geo,tgeo},{geo,tgeo},float) → boolean`

  `aDwithin({geometry,tgeom},{geometry,tgeom},float) → boolean`

      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

- Ever or always intersects &Z_support; &geography_support;

  `eIntersects({geo,tgeo},{geo,tgeo}) → boolean`

  `aIntersects({geometry,tgeom},{geometry,tgeom}) → boolean`

      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

- Ever or always touches

  `eTouches({geometry,tgeom},{geometry,tgeom}) → boolean`

  `aTouches({geometry,tgeom},{geometry,tgeom}) → boolean`

      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

### Spatiotemporal Relationships

We present next the spatiotemporal relationships. A common requirement regarding them is to restrict the result of the relationship to the instants when the value of the result is true or false. As an example, the following query computes for each trip the time spent traveling in the Brussels municipality.

    SELECT TripId, duration(atValues(tintersects(T.trip, M.geom), True))
    FROM Trips T, Municipality M
    WHERE M.Name = "Brussels" AND atValues(tintersects(T.trip, M.geom), True) IS NOT NULL;

To simplify query writing, the spatiotemporal relationships have an optional last parameter, which if given applies the `atValue` function (see ttype_restrictions) to the result of the relationship. In this way, the above query can be written as follows.

    SELECT TripId, duration(tintersects(T.trip, M.geom, True))
    FROM Trips T, Municipality M
    WHERE M.Name = "Brussels" AND tintersects(T.trip, M.geom, True) IS NOT NULL;

- Temporal contains

  `tContains(geometry,tgeom,atValue boolean=NULL) → tbool`

      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]}

- Temporal disjoint &Z_support; &geography_support;

  `tDisjoint({geo,tgeo},{geo,tgeo},atValue boolean=NULL) → tbool`

  The function only supports 3D or geographies for two temporal points

      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)}

- Temporal distance within &Z_support;

  `tDwithin({geo,tgeo},{geo,tgeo},float,atValue boolean=NULL) → tbool`

      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]}

- Temporal intersects &Z_support; &geography_support;

  `tIntersects({geo,tgeo},{geo,tgeo},atValue boolean=NULL) → tbool`

  The function only supports 3D or geographies for two temporal points

      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)}

- Temporal touches

  `tTouches({geometry,tgeom},{geometry,tgeom},atValue boolean=NULL) → tbool`

      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]}