How the DISJOINT() function works in Mariadb?
The ST_DISJOINT()
function in MariaDB is used to determine whether two spatial objects are disjoint or not.
The ST_DISJOINT()
function in MariaDB is used to determine whether two spatial objects are disjoint or not. Two spatial objects are considered disjoint if they do not intersect or touch each other in any way.
Syntax
The syntax for the MariaDB ST_DISJOINT()
function is as follows:
ST_DISJOINT(g1, g2)
g1
: A geometry value representing the first spatial object.g2
: A geometry value representing the second spatial object.
The function returns:
- 1 if the spatial objects are disjoint (do not intersect or touch each other).
- 0 if the spatial objects are not disjoint (intersect or touch each other).
NULL
if either of the input values isNULL
.
Examples
Example 1: Disjoint Polygons
This example demonstrates two disjoint polygons.
SET @poly1 = ST_GeomFromText('POLYGON((0 0, 0 2, 2 2, 2 0, 0 0))');
SET @poly2 = ST_GeomFromText('POLYGON((3 3, 3 5, 5 5, 5 3, 3 3))');
SELECT ST_DISJOINT(@poly1, @poly2);
Output:
+-----------------------------+
| ST_DISJOINT(@poly1, @poly2) |
+-----------------------------+
| 1 |
+-----------------------------+
The output 1
indicates that the two polygons are disjoint and do not intersect or touch each other.
Example 2: Non-disjoint Polygons
This example shows two polygons that are not disjoint.
SET @poly1 = ST_GeomFromText('POLYGON((0 0, 0 2, 2 2, 2 0, 0 0))');
SET @poly2 = ST_GeomFromText('POLYGON((1 1, 1 3, 3 3, 3 1, 1 1))');
SELECT ST_DISJOINT(@poly1, @poly2);
Output:
+-----------------------------+
| ST_DISJOINT(@poly1, @poly2) |
+-----------------------------+
| 0 |
+-----------------------------+
The output 0
indicates that the two polygons are not disjoint and intersect or touch each other.
Example 3: Disjoint Line and Polygon
This example demonstrates a disjoint line and polygon.
SET @line = ST_GeomFromText('LINESTRING(0 0, 0 2)');
SET @poly = ST_GeomFromText('POLYGON((3 3, 3 5, 5 5, 5 3, 3 3))');
SELECT ST_DISJOINT(@line, @poly);
Output:
+---------------------------+
| ST_DISJOINT(@line, @poly) |
+---------------------------+
| 1 |
+---------------------------+
The output 1
indicates that the line and polygon are disjoint and do not intersect or touch each other.
Example 4: Non-disjoint Line and Polygon
This example shows a line and polygon that are not disjoint.
SET @line = ST_GeomFromText('LINESTRING(0 0, 4 4)');
SET @poly = ST_GeomFromText('POLYGON((2 2, 2 4, 4 4, 4 2, 2 2))');
SELECT ST_DISJOINT(@line, @poly);
Output:
+---------------------------+
| ST_DISJOINT(@line, @poly) |
+---------------------------+
| 0 |
+---------------------------+
The output 0
indicates that the line and polygon are not disjoint and intersect or touch each other.
Example 5: Disjoint Geometries from a Table
This example demonstrates disjoint geometries stored in a table.
DROP TABLE IF EXISTS geometries;
CREATE TABLE geometries (id INT PRIMARY KEY, geom1 GEOMETRY, geom2 GEOMETRY);
INSERT INTO geometries (id, geom1, geom2) VALUES
(1, ST_GeomFromText('POINT(0 0)'), ST_GeomFromText('POINT(3 3)')),
(2, ST_GeomFromText('LINESTRING(0 0, 2 2)'), ST_GeomFromText('LINESTRING(3 3, 5 5)')),
(3, ST_GeomFromText('POLYGON((0 0, 0 2, 2 2, 2 0, 0 0))'), ST_GeomFromText('POLYGON((3 3, 3 5, 5 5, 5 3, 3 3))'));
SELECT id, ST_DISJOINT(geom1, geom2) AS disjoint
FROM geometries;
Output:
+----+----------+
| id | disjoint |
+----+----------+
| 1 | 1 |
| 2 | 1 |
| 3 | 1 |
+----+----------+
The output 1
for each row indicates that the geometries stored in the table are disjoint and do not intersect or touch each other.
Related Functions
The following are some functions related to MariaDB ST_DISJOINT()
:
- MariaDB
ST_INTERSECTS()
function is used to determine whether two spatial objects intersect each other. - MariaDB
ST_TOUCHES()
function is used to determine whether two spatial objects touch each other. - MariaDB
ST_CROSSES()
function is used to determine whether two spatial objects cross each other. - MariaDB
ST_WITHIN()
function is used to determine whether a spatial object is entirely within another spatial object.
Conclusion
The ST_DISJOINT()
function in MariaDB is a valuable tool for spatial analysis, allowing you to determine whether two spatial objects are disjoint or not. By identifying disjoint geometries, you can perform various operations and analyses on your spatial data, such as filtering or separating non-intersecting objects. This function is particularly useful when working with complex spatial datasets and performing spatial queries or calculations.