Lindorm GanosBase provides functions to determine the spatial relationships between geometry objects, such as containment, intersection, overlap, and proximity.
Applicable engines and versions
These functions apply only to LindormTable and are supported by all versions of LindormTable.
Functions
| Function | Description |
|---|---|
ST_Contains | Returns true if geomA contains geomB. |
ST_DWithin | Returns true if the 2D distance between two geometry objects is within the specified range. The distance is measured in degrees (SRID 4326). |
ST_DWithinSphere | Returns true if the spherical distance between two geometry objects is within the specified range. The distance is measured in meters. |
ST_Intersects | Returns true if two geometry objects share any spatial space. |
ST_Overlaps | Returns true if two geometry objects spatially overlap but one is not included in the other. |
ST_Within | Returns true if geomA completely lies within geomB. |
ST_Contains
Returns true if geomA contains geomB — that is, all points of geomB lie in the interior or on the boundary of geomA.
ST_Contains is the inverse of ST_Within: ST_Contains(A, B) returns the same result as ST_Within(B, A).
Syntax
-- Check whether geomA contains geomB
boolean ST_Contains(geometry geomA, geometry geomB)
-- Check whether geom contains the point (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 of the point. |
y | The latitude of the point. |
Supported geometry types: Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon, and GeometryCollection.
Examples
Check whether a polygon contains a point object:
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 |
+-----------+Check whether a polygon contains the point (5, 5) specified by coordinates:
SELECT ST_Contains(ST_GeomFromText('POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))'), 5, 5) AS iscontain;Result:
+-----------+
| iscontain |
+-----------+
| true |
+-----------+Check whether a polygon contains a point outside its boundary:
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 |
+-----------+Same check using coordinates:
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
Returns true if the 2D (planar) distance between two geometry objects is within the specified range. The distance is measured in degrees under Spatial Reference System Identifier (SRID) 4326.
UseST_DWithinfor planar distance comparisons in SRID 4326 degree units. To measure real-world distances in meters on a sphere, useST_DWithinSphereinstead.
Syntax
-- Check whether the 2D distance between geomA and geomB is within the range
boolean ST_DWithin(geometry geomA, geometry geomB, double distanceOfSrid)
-- Check whether the 2D distance between geom and the point (x, y) is within the range
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 maximum distance threshold in SRID 4326. Unit: degree. |
geom | The geometry object. |
x | The longitude of the point. |
y | The latitude of the point. |
Supported geometry types: Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon, and GeometryCollection.
Examples
Check whether two points are within 10 degrees of each other:
SELECT ST_DWithin(ST_GeomFromText('POINT(5 5)'), ST_GeomFromText('POINT(6 6)'), 10) AS iswithin;Result:
+----------+
| iswithin |
+----------+
| true |
+----------+Same check using coordinates for the second point:
SELECT ST_DWithin(ST_GeomFromText('POINT(5 5)'), 6, 6, 10) AS iswithin;Result:
+----------+
| iswithin |
+----------+
| true |
+----------+ST_DWithinSphere
Returns true if the spherical distance between two geometry objects is within the specified range. The distance is measured in meters on a sphere.
Use ST_DWithinSphere when you need to measure real-world distances in meters. Results may have an error of centimeters due to the spherical approximation.Syntax
-- Check whether the spherical distance between geomA and geomB is within the range
boolean ST_DWithinSphere(geometry geomA, geometry geomB, double distance)
-- Check whether the spherical distance between geom and the point (x, y) is within the range
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 maximum distance threshold. Unit: meter. Results may have an error of centimeters. |
geom | The geometry object. |
x | The longitude of the point. |
y | The latitude of the point. |
Supported geometry types: Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon, and GeometryCollection.
Examples
Check whether two geographic points are within 570,000 meters of each other:
The spherical distance between (120, 36) and (116, 40) is approximately 566,034.79 meters, which is within 570,000 meters.
SELECT ST_DWithinSphere(ST_GeomFromText('POINT(120 36)'), ST_GeomFromText('POINT(116 40)'), 570000) AS iswithin;Result:
+----------+
| iswithin |
+----------+
| true |
+----------+Same check using coordinates for the second point:
SELECT ST_DWithinSphere(ST_GeomFromText('POINT(120 36)'), 116, 40, 570000) AS iswithin;Result:
+----------+
| iswithin |
+----------+
| true |
+----------+ST_Intersects
Returns true if two geometry objects share any spatial space.
Syntax
-- Check whether geomA and geomB intersect
boolean ST_Intersects(geometry geomA, geometry geomB)
-- Check whether geom intersects the point (x, y)
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 of the point. |
y | The latitude of the point. |
Supported geometry types: Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon, and GeometryCollection.
Examples
Check whether a point and a line that do not touch each other intersect:
SELECT ST_Intersects(ST_GeomFromText('POINT(0 0)'), ST_GeomFromText('LINESTRING ( 2 0, 0 2 )')) AS isinter;Result:
+---------+
| isinter |
+---------+
| false |
+---------+Same check using coordinates for the point:
SELECT ST_Intersects(ST_GeomFromText('LINESTRING ( 2 0, 0 2 )'), 0, 0) AS isinter;Result:
+---------+
| isinter |
+---------+
| false |
+---------+Check whether a point and a line that share an endpoint intersect:
SELECT ST_Intersects(ST_GeomFromText('POINT(0 0)'), ST_GeomFromText('LINESTRING ( 0 0, 0 2 )')) AS isinter;Result:
+---------+
| isinter |
+---------+
| true |
+---------+Same check using coordinates for the point:
SELECT ST_Intersects(ST_GeomFromText('LINESTRING ( 0 0, 0 2 )'), 0, 0) AS isinter;Result:
+---------+
| isinter |
+---------+
| true |
+---------+ST_Overlaps
Returns true if two geometry objects spatially overlap but one is not included in the other.
Syntax
-- Check whether geomA and geomB overlap
boolean ST_Overlaps(geometry geomA, geometry geomB)
-- Check whether geom overlaps the point (x, y)
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 of the point. |
y | The latitude of the point. |
Supported geometry types: Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon, and GeometryCollection.
Examples
Check whether two partially overlapping line segments overlap:
SELECT ST_Overlaps(ST_GeomFromText('LINESTRING(0 0,0 2)'), ST_GeomFromText('LINESTRING(0 1,0 3)')) AS overlaps;Result:
+----------+
| overlaps |
+----------+
| true |
+----------+Check whether a line and a point on that line overlap:
SELECT ST_Overlaps(ST_GeomFromText('LINESTRING(0 0,0 2)'), ST_GeomFromText('POINT(0 1)')) AS overlaps;Result:
+----------+
| overlaps |
+----------+
| false |
+----------+Same check using coordinates for the point:
SELECT ST_Overlaps(ST_GeomFromText('LINESTRING(0 0,0 2)'), 0, 1) AS overlaps;Result:
+----------+
| overlaps |
+----------+
| false |
+----------+ST_Within
Returns true if geomA completely lies within geomB.
ST_Within is the inverse of ST_Contains: ST_Within(A, B) returns the same result as ST_Contains(B, A).
If bothST_Within(A, B)andST_Within(B, A)return true, A and B are spatially equal.
Syntax
-- Check whether geomA completely lies within geomB
boolean ST_Within(geometry geomA, geometry geomB)
-- Check whether the point (x, y) lies within geom
boolean 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 of the point. |
y | The latitude of the point. |
Supported geometry types: Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon, and GeometryCollection.
Examples
Check whether a point lies within a polygon:
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 |
+----------+Same check using coordinates for the point:
SELECT ST_Within(5, 5, ST_GeomFromText('POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))')) AS iswithin;Result:
+----------+
| iswithin |
+----------+
| true |
+----------+