All Products
Search
Document Center

Lindorm:Functions for spatial relationships

Last Updated:Oct 18, 2024

This topic describes the functions that are supported by Lindorm GanosBase to determine the spatial relationships between geometry objects.

Applicable engines and versions

Functions for spatial relationships described in this topic are applicable only to LindormTable. These functions are supported by all versions of LindormTable.

Functions

The following table describes the functions for spatial relationships supported by Lindorm GanosBase.

Function

Description

ST_Contains

You can call the ST_Contains function to determine whether the first geometry object that you specify contains the second geometry object that you specify. If the first geometry object contains the second geometry object, this function returns true.

ST_DWithin

You can call the ST_DWithin function to determine whether the 2D distance between two geometry objects is within the specified range. If the 2D distance between the objects is within the specified range, this function returns true.

ST_DWithinSphere

You can call the ST_DWithinSphere function to determine whether the spherical distance between two geometry objects is within the specified range. If the spherical distance between the objects is within the specified range, this function returns true.

ST_Intersects

You can call the ST_Intersects function to determine whether two geometry objects intersect. If the two geometry objects have any shared spatial space, ST_Intersects determines that the two objects intersect and returns true.

ST_Overlaps

You can call the ST_Overlaps object to determine whether two geometry objects spatially overlap but one is not included in the other. If the two geometry objects spatially overlap but one is not included in the other, this function returns true.

ST_Within

You can call the ST_Within function to determine whether the second geometry object that you specify completely lies in the first geometry object that you specify. If the second geometry object completely lies in the first geometry object, this function returns true.

ST_Contains

You can call the ST_Contains function to determine whether the first geometry object that you specify contains the second geometry object that you specify. If the first geometry object contains the second geometry object, this function returns true.

Syntax

  • Determine whether a geometry object contains another geometry object.

    boolean ST_Contains(geometry geomA,geometry geomB)
  • Determine whether a geometry object contains the specified point object.

    boolean ST_Contains(geometry geom,double x,double y)

Parameters

Parameter

Description

geomA

The first geometry object that you want to specify.

geomB

The second geometry object that you want to specify.

geom

The geometry object that you want to specify.

x

The longitude of the point object.

y

The latitude of the point object.

Note
  • If all points of geomB are contained in the interior or on the boundary of geomA, geomA contains geomB.

  • ST_Contains is the inverse function of ST_Within. The returned results of ST_Contains(A,B) and ST_Within(B,A) are the same.

Examples

  • Example 1:

    SELECT ST_Contains(ST_GeomFromText('POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))'), ST_GeomFromText('POINT(5 5)')) AS iscontain;

    The following result is returned:

    +-----------+
    | iscontain |
    +-----------+
    | true      |
    +-----------+
  • Example 2:

    SELECT ST_Contains(ST_GeomFromText('POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))'),5,5) AS iscontain;

    The following result is returned:

    +-----------+
    | iscontain |
    +-----------+
    | true      |
    +-----------+
  • Example 3:

    SELECT ST_Contains(ST_GeomFromText('POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))'), ST_GeomFromText('POINT(180 23)')) AS iscontain;

    The following result is returned:

    +-----------+
    | iscontain |
    +-----------+
    | false     |
    +-----------+
  • Example 4:

    SELECT ST_Contains(ST_GeomFromText('POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))'),180,23) AS iscontain;

    The following result is returned:

    +-----------+
    | iscontain |
    +-----------+
    | false     |
    +-----------+

ST_DWithin

You can call the ST_DWithin function to determine whether the 2D distance between two geometry objects is within the specified range. If the 2D distance between the objects is within the specified range, this function returns true.

Syntax

  • Determine whether the 2D distance between two geometry objects is within the specified range.

    boolean ST_DWithin(geometry geomA, geometry geomB, double distanceOfSrid)
  • Determine whether the 2D distance between a geometry object and the specified point object is within the specified range.

    boolean ST_DWithin(geometry geom, double x, double y, double distanceOfSrid)

Parameters

Parameter

Description

geomA

The first geometry object that you want to specify.

geomB

The second geometry object that you want to specify.

distanceOfSrid

The distance in Spatial Reference System Identifier (SRID) 4326. Unit: degree.

geom

The geometry object that you want to specify.

x

The longitude of the point object.

y

The latitude of the point object.

Note

You can specify a geometry object of the following types: Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon, and GeometryCollection.

Examples

  • Example 1:

    SELECT ST_DWithin(ST_GeomFromText('POINT(5 5)'), ST_GeomFromText('POINT(6 6)'), 10) AS iswithin;

    The following result is returned:

    +----------+
    | iswithin |
    +----------+
    | true     |
    +----------+
  • Example 2:

    SELECT ST_DWithin(ST_GeomFromText('POINT(5 5)'),6,6,10) AS iswithin;

    The following result is returned:

    +----------+
    | iswithin |
    +----------+
    | true     |
    +----------+

ST_DWithinSphere

You can call the ST_DWithinSphere function to determine whether the spherical distance between two geometry objects is within the specified range. If the spherical distance between the objects is within the specified range, this function returns true.

Syntax

  • Determine whether the spherical distance between two geometry objects is within the specified range.

    boolean ST_DWithinSphere(geometry geomA, geometry geomB, double distance)
  • Determine whether the spherical distance between a geometry object and the specified point object is within the specified range.

    boolean ST_DWithinSPhere(geometry geom, double x, double y, double distance)

Parameters

Parameter

Description

geomA

The first geometry object that you want to specify.

geomB

The second geometry object that you want to specify.

distance

The distance that you want to specify. Unit: meters. The function may have an error of centimeters when it determines the spherical distance.

geom

The geometry object that you want to specify.

x

The longitude of the point object.

y

The latitude of the point object.

Note

You can specify a geometry object of the following types: Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon, and GeometryCollection.

Examples

  • Example 1:

    SELECT ST_DWithinSphere(ST_GeomFromText('POINT(120 36)'), ST_GeomFromText('POINT(116 40)'), 570000) AS iswithin;

    In this example, the spherical distance between the point (120,36) and the point (116,40) is 566034.7930717631 meter, which falls within the specified range. Therefore, the ST_DWithinSphere function returns true, as shown in the following result:

    +----------+
    | iswithin |
    +----------+
    | true     |
    +----------+
  • Example 2:

    SELECT ST_DWithinSphere(ST_GeomFromText('POINT(120 36)'),116,40,570000) AS iswithin;

    The following result is returned:

    +----------+
    | iswithin |
    +----------+
    | true     |
    +----------+

ST_Intersects

You can call the ST_Intersects function to determine whether two geometry objects intersect. If the two geometry objects have any shared spatial space, ST_Intersects determines that the two objects intersect and returns true.

Syntax

  • Determine whether two geometry objects intersect.

    boolean ST_ Intersects(geometry geomA, geometry geomB)
  • Determine whether a geometry object and the specified point object intersect.

    boolean ST_ Intersects(geometry geom, double x, double y)

Parameters

Parameter

Description

geomA

The first geometry object that you want to specify.

geomB

The second geometry object that you want to specify.

geom

The geometry object that you want to specify.

x

The longitude of the point object.

y

The latitude of the point object.

Note

You can specify a geometry object of the following types: Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon, and GeometryCollection.

Examples

  • Example 1:

    SELECT ST_Intersects(ST_GeomFromText('POINT(0 0)'), ST_GeomFromText('LINESTRING ( 2 0, 0 2 )')) AS isinter;

    The following result is returned:

    +---------+
    | isinter |
    +---------+
    | false   |
    +---------+
  • Example 2:

    SELECT ST_Intersects(ST_GeomFromText('LINESTRING ( 2 0, 0 2 )'), 0, 0) AS isinter;

    The following result is returned:

    +---------+
    | isinter |
    +---------+
    | false   |
    +---------+
  • Example 3:

    SELECT ST_Intersects(ST_GeomFromText('POINT(0 0)'), ST_GeomFromText('LINESTRING ( 0 0, 0 2 )')) AS isinter;

    The following result is returned:

    +---------+
    | isinter |
    +---------+
    | true    |
    +---------+
  • Example 4:

    SELECT ST_Intersects(ST_GeomFromText('LINESTRING ( 0 0, 0 2 )'), 0, 0) AS isinter;

    The following result is returned:

    +---------+
    | isinter |
    +---------+
    | true    |
    +---------+

ST_Overlaps

You can call the ST_Overlaps object to determine whether two geometry objects spatially overlap but one is not included in the other. If the two geometry objects spatially overlap but one is not included in the other, this function returns true.

Syntax

  • Determine whether two geometry objects spatially overlap.

    boolean ST_Overlaps(geometry geomA, geometry geomB)
  • Determine whether a geometry object and the specified point object overlap.

    boolean ST_Overlaps(geometry geom, double x, double y)

Parameters

Parameter

Description

geomA

The first geometry object that you want to specify.

geomB

The second geometry object that you want to specify.

geom

The geometry object that you want to specify.

x

The longitude of the point object.

y

The latitude of the point object.

Note

You can specify a geometry object of the following types: Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon, and GeometryCollection.

Examples

  • Example 1:

    SELECT ST_Overlaps(ST_GeomFromText('LINESTRING(0 0,0 2)'),ST_GeomFromText('LINESTRING(0 1,0 3)')) as overlaps;

    The following result is returned:

    +----------+
    | overlaps |
    +----------+
    | true     |
    +----------+
  • Example 2:

    SELECT ST_Overlaps(ST_GeomFromText('LINESTRING(0 0,0 2)'),ST_GeomFromText('POINT(0 1)')) as overlaps;

    The following result is returned:

    +----------+
    | overlaps |
    +----------+
    | false    |
    +----------+
  • Example 3:

    SELECT ST_Overlaps(ST_GeomFromText('LINESTRING(0 0,0 2)'), 0, 1) as overlaps;

    The following result is returned:

    +----------+
    | overlaps |
    +----------+
    | false    |
    +----------+

ST_Within

You can call the ST_Within function to determine whether the second geometry object that you specify completely lies in the first geometry object that you specify. If the second geometry object completely lies in the first geometry object, this function returns true.

Syntax

  • Determine whether a geometry object completely lies in another geometry object.

    boolean ST_Within(geometry geomA, geometry geomB)
  • Determine whether the specified point object lies in a geometry object .

    bboolean ST_Within(double x, double y, geometry geom)

Parameters

Parameter

Description

geomA

The first geometry object that you want to specify.

geomB

The second geometry object that you want to specify.

geom

The geometry object that you want to specify.

x

The longitude of the point object.

y

The latitude of the point object.

Note
  • You can specify a geometry object of the following types: Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon, and GeometryCollection.

  • If true is returned by both ST_Within(A,B) and ST_Within(B,A), A and B are geometry objects that are spatially equal.

Examples

  • Example 1:

    SELECT ST_Within(ST_GeomFromText('POINT(5 5)'), ST_GeomFromText('POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))')) AS iswithin;

    The following result is returned:

    +----------+
    | iswithin |
    +----------+
    | true     |
    +----------+
  • Example 2:

    SELECT ST_Within(5, 5, ST_GeomFromText('POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))')) AS iswithin;

    The following result is returned:

    +----------+
    | iswithin |
    +----------+
    | true     |
    +----------+