Relational functions
This topic describes the relational functions in spatiotemporal functions.
Engine and version
Relational functions apply only to LindormTable. No specific version is required.
Function list
The following table lists the relational functions that Lindorm Ganos supports.
Function | Description |
The | |
The | |
The | |
The | |
The | |
The |
ST_Contains
The ST_Contains function returns true if a Geometry object A contains a Geometry object B.
Syntax
Checks whether object geomA contains object geomB.
boolean ST_Contains(geometry geomA,geometry geomB)Checks whether object geom contains the point coordinate (x,y).
boolean ST_Contains(geometry geom,double x,double y)
Parameters
Parameter | Description |
geomA | The first Geometry object. |
geomB | The second Geometry object. |
geom | The Geometry object. |
x | The longitude value x of the coordinate. |
y | The latitude value y of the coordinate. |
A Geometry object geomA contains a Geometry object geomB if all points of geomB are inside or on the border of geomA.
The
ST_Containsfunction is the inverse of theST_Withinfunction. This means that ST_Contains(A,B) is equivalent toST_Within(B,A).
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;Result:
+-----------+ | iscontain | +-----------+ | true | +-----------+Example 2
SELECT ST_Contains(ST_GeomFromText('POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))'),5,5) AS iscontain;Result:
+-----------+ | 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;Result:
+-----------+ | iscontain | +-----------+ | false | +-----------+Example 4
SELECT ST_Contains(ST_GeomFromText('POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))'),180,23) AS iscontain;Result:
+-----------+ | iscontain | +-----------+ | false | +-----------+
ST_DWithin
The ST_DWithin function returns true if the 2D planar distance between two Geometry objects is within a specified distance.
Syntax
Checks whether the 2D planar distance between object geomA and object geomB is within a specified distance.
boolean ST_DWithin(geometry geomA, geometry geomB, double distanceOfSrid)Checks whether the 2D planar distance between object geom and the point coordinate (x,y) is within a specified distance.
boolean ST_DWithin(geometry geom, double x, double y, double distanceOfSrid)
Parameters
Parameter | Description |
geomA | The first Geometry object. |
geomB | The second Geometry object. |
distanceOfSrid | The distance in SRID 4326. The unit is degrees. |
geom | The Geometry object. |
x | The longitude value x of the coordinate. |
y | The latitude value y of the coordinate. |
Geometry objects support 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;Result:
+----------+ | iswithin | +----------+ | true | +----------+Example 2
SELECT ST_DWithin(ST_GeomFromText('POINT(5 5)'),6,6,10) AS iswithin;Result
+----------+ | iswithin | +----------+ | true | +----------+
ST_DWithinSphere
The ST_DWithinSphere function returns true if the spherical distance between two Geometry objects is within a specified distance.
Syntax
Checks whether the spherical distance between object geomA and object geomB is within a specified distance.
boolean ST_DWithinSphere(geometry geomA, geometry geomB, double distance)Checks whether the spherical distance between object geom and the point coordinate (x,y) is within a specified distance.
boolean ST_DWithinSPhere(geometry geom, double x, double y, double distance)
Parameters
Parameter | Description |
geomA | The first Geometry object. |
geomB | The second Geometry object. |
distance | The spherical distance in meters. The check for spherical distance has a margin of error at the centimeter level. |
geom | The Geometry object. |
x | The longitude value x of the coordinate. |
y | The latitude value y of the coordinate. |
Geometry objects support the following types: Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon, and GeometryCollection.
Examples
Example 1: The spherical distance between POINT(120 36) and POINT(116 40) is 566,034.7930717631 meters. This distance is within the specified range, so the
ST_DWithinSpherefunction returns true.SELECT ST_DWithinSphere(ST_GeomFromText('POINT(120 36)'), ST_GeomFromText('POINT(116 40)'), 570000) AS iswithin;Result:
+----------+ | iswithin | +----------+ | true | +----------+Example 2
SELECT ST_DWithinSphere(ST_GeomFromText('POINT(120 36)'),116,40,570000) AS iswithin;Result:
+----------+ | iswithin | +----------+ | true | +----------+
ST_Intersects
The ST_Intersects function returns true if two Geometry objects intersect. Two objects intersect if they share any part of their space.
Syntax
Checks whether object geomA and object geomB intersect.
boolean ST_Intersects(geometry geomA, geometry geomB)Checks whether object geom and the point coordinate (x,y) intersect.
boolean ST_Intersects(geometry geom, double x, double y)
Parameters
Parameter | Description |
geomA | The first Geometry object. |
geomB | The second Geometry object. |
geom | The Geometry object. |
x | The longitude value x of the coordinate. |
y | The latitude value y of the coordinate. |
Geometry objects support 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;Result:
+---------+ | isinter | +---------+ | false | +---------+Example 2
SELECT ST_Intersects(ST_GeomFromText('LINESTRING ( 2 0, 0 2 )'), 0, 0) AS isinter;Result:
+---------+ | isinter | +---------+ | false | +---------+Example 3
SELECT ST_Intersects(ST_GeomFromText('POINT(0 0)'), ST_GeomFromText('LINESTRING ( 0 0, 0 2 )')) AS isinter;Result:
+---------+ | isinter | +---------+ | true | +---------+Example 4
SELECT ST_Intersects(ST_GeomFromText('LINESTRING ( 0 0, 0 2 )'), 0, 0) AS isinter;Result:
+---------+ | isinter | +---------+ | true | +---------+
ST_Overlaps
The ST_Overlaps function returns true if two Geometry objects overlap, but neither one completely contains the other.
Syntax
Checks whether object geomA and object geomB overlap.
boolean ST_Overlaps(geometry geomA, geometry geomB)Checks whether object geom and the point coordinate (x,y) overlap.
boolean ST_Overlaps(geometry geom, double x, double y)
Parameters
Parameter | Description |
geomA | The first Geometry object. |
geomB | The second Geometry object. |
geom | The Geometry object. |
x | The longitude value x of the coordinate. |
y | The latitude value y of the coordinate. |
Geometry objects support 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;Result:
+----------+ | overlaps | +----------+ | true | +----------+Example 2
SELECT ST_Overlaps(ST_GeomFromText('LINESTRING(0 0,0 2)'),ST_GeomFromText('POINT(0 1)')) as overlaps;Result:
+----------+ | overlaps | +----------+ | false | +----------+Example 3
SELECT ST_Overlaps(ST_GeomFromText('LINESTRING(0 0,0 2)'), 0, 1) as overlaps;Result:
+----------+ | overlaps | +----------+ | false | +----------+
ST_Within
The ST_Within function returns true if a Geometry object A is completely within a Geometry object B.
Syntax
Checks whether object geomA is within object geomB.
boolean ST_Within(geometry geomA, geometry geomB)Checks whether the point coordinate (x,y) is within object geom.
bboolean ST_Within(double x, double y, geometry geom)
Parameters
Parameter | Description |
geomA | The first Geometry object. |
geomB | The second Geometry object. |
geom | The Geometry object. |
x | The longitude value x of the coordinate. |
y | The latitude value y of the coordinate. |
Geometry objects support the following types: Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon, and GeometryCollection.
If both
ST_Within(A,B)andST_Within(B,A)return true, Geometry object A and Geometry object B are considered spatially identical.
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;Result:
+----------+ | iswithin | +----------+ | true | +----------+Example 2
SELECT ST_Within(5, 5, ST_GeomFromText('POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))')) AS iswithin;Result:
+----------+ | iswithin | +----------+ | true | +----------+