How the ST_BOUNDARY() function works in Mariadb?
The ST_Boundary()
function in MariaDB is used to return the boundary of a given geometry value, allowing for efficient analysis and manipulation of spatial data.
The ST_Boundary()
function in MariaDB is used to return the boundary of a given geometry value. The boundary of a geometry is a geometry representing the closure of the complement of the interior of the input geometry. In simpler terms, it returns a geometry that represents the edges or boundaries of the input geometry.
Syntax
The syntax for the MariaDB ST_Boundary()
function is as follows:
ST_Boundary(geom)
geom
: The geometry value for which the boundary needs to be calculated.
The function returns the boundary of the input geometry as a new geometry value. If the input geometry is empty, the function returns an empty geometry collection.
Examples
Example 1: Get the boundary of a Point geometry
This example demonstrates that for a Point geometry, the ST_Boundary()
function returns an empty geometry collection.
SET @point = ST_GeomFromText('POINT(1 1)');
SELECT ST_AsText(ST_Boundary(@point));
The following is the output:
GEOMETRYCOLLECTION EMPTY
Since a Point geometry has no boundary, the function returns an empty geometry collection.
Example 2: Get the boundary of a LineString geometry
This example shows how to get the boundary of a LineString geometry.
SET @line = ST_GeomFromText('LINESTRING(0 0, 1 1, 2 2)');
SELECT ST_AsText(ST_Boundary(@line));
The following is the output:
MULTIPOINT(0 0, 2 2)
The boundary of a LineString geometry is a MultiPoint geometry containing the start and end points of the LineString.
Example 3: Get the boundary of a Polygon geometry
This example demonstrates how to get the boundary of a Polygon geometry.
SET @poly = ST_GeomFromText('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))');
SELECT ST_AsText(ST_Boundary(@poly));
The following is the output:
LINESTRING(0 0, 10 0, 10 10, 0 10, 0 0)
The boundary of a Polygon geometry is a LineString representing the outer ring of the polygon.
Example 4: Get the boundary of a MultiPolygon geometry
This example shows how to get the boundary of a MultiPolygon geometry.
SET @multipoly = ST_GeomFromText('MULTIPOLYGON(((0 0, 10 0, 10 10, 0 10, 0 0)), ((20 20, 30 20, 30 30, 20 30, 20 20)))');
SELECT ST_AsText(ST_Boundary(@multipoly));
The following is the output:
MULTILINESTRING((0 0, 10 0, 10 10, 0 10, 0 0), (20 20, 30 20, 30 30, 20 30, 20 20))
The boundary of a MultiPolygon geometry is a MultiLineString representing the outer rings of all the polygons in the MultiPolygon.
Example 5: Get the boundary of a geometry from a table
This example demonstrates how to get the boundary of a geometry stored in a table.
DROP TABLE IF EXISTS polygons;
CREATE TABLE polygons (id INT PRIMARY KEY, poly GEOMETRY);
INSERT INTO polygons (id, poly) VALUES
(1, ST_GeomFromText('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))'));
SELECT id, ST_AsText(ST_Boundary(poly)) AS boundary FROM polygons;
The following is the output:
+----+------------------------------------------+
| id | boundary |
+----+------------------------------------------+
| 1 | LINESTRING(0 0, 10 0, 10 10, 0 10, 0 0) |
+----+------------------------------------------+
In this example, a table named polygons
is created with an id
column and a poly
column of type GEOMETRY
. A polygon geometry is inserted into the table, and then the ST_Boundary()
function is used to get the boundary of the stored geometry for each row in the table.
Related Functions
The following are some functions related to the MariaDB ST_Boundary()
function:
- The MariaDB
ST_Exterior()
function is used to return the outer ring of a Polygon geometry. - The MariaDB
ST_Interior()
function is used to return the interior of a geometry. - The MariaDB
ST_Dimension()
function is used to return the dimension of a geometry. - The MariaDB
ST_GeometryType()
function is used to return the type of a geometry.
Conclusion
The ST_Boundary()
function in MariaDB is a useful spatial function for retrieving the boundary of a given geometry. It allows you to extract the edges or boundaries of geometries, which can be valuable in various applications, such as spatial analysis, visualization, and data processing. By understanding the behavior of this function for different geometry types, you can effectively work with spatial data and perform necessary operations on the boundaries of geometries.