# How the BOUNDARY() function works in Mariadb?

The `BOUNDARY()`

function is a spatial function that returns the boundary of a geometry value. The boundary of a geometry is the set of geometries of one lower dimension that make up its border.

The `BOUNDARY()`

function is a spatial function that returns the boundary of a geometry value. The boundary of a geometry is the set of geometries of one lower dimension that make up its border. For example, the boundary of a polygon is a collection of line strings that form its edges, and the boundary of a point is an empty geometry.

## Syntax

The syntax of the `BOUNDARY()`

function is as follows:

```
BOUNDARY(g)
```

Where `g`

is a geometry value.

The return type of the function is a geometry value of the same spatial reference system as the input.

## Examples

### Example 1: Boundary of a point

In this example, we use the `BOUNDARY()`

function to get the boundary of a point. A point has no boundary, so the function returns an empty geometry.

```
SELECT BOUNDARY(ST_GeomFromText('POINT(1 2)')) AS boundary;
```

The output is:

```
+----------+
| boundary |
+----------+
| |
+----------+
```

### Example 2: Boundary of a line string

In this example, we use the `BOUNDARY()`

function to get the boundary of a line string. A line string has two end points as its boundary, so the function returns a multipoint geometry.

```
SELECT BOUNDARY(ST_GeomFromText('LINESTRING(1 1, 2 2, 3 3)')) AS boundary;
```

The output is:

```
+------------------------------------+
| boundary |
+------------------------------------+
| MULTIPOINT(1 1,3 3) |
+------------------------------------+
```

### Example 3: Boundary of a polygon

In this example, we use the `BOUNDARY()`

function to get the boundary of a polygon. A polygon has one or more rings (closed line strings) as its boundary, so the function returns a multilinestring geometry.

```
SELECT BOUNDARY(ST_GeomFromText('POLYGON((0 0, 0 3, 3 3, 3 0, 0 0), (1 1, 2 1, 2 2, 1 2, 1 1))')) AS boundary;
```

The output is:

```
+------------------------------------------------------------------------+
| boundary |
+------------------------------------------------------------------------+
| MULTILINESTRING((0 0,0 3,3 3,3 0,0 0),(1 1,2 1,2 2,1 2,1 1)) |
+------------------------------------------------------------------------+
```

## Related Functions

Some other spatial functions that are related to the `BOUNDARY()`

function are:

`DIMENSION()`

: Returns the dimension of a geometry value. The dimension is the topological dimension of the geometry, which is 0 for points, 1 for lines, and 2 for polygons.`ISCLOSED()`

: Returns 1 if a geometry is a closed line string or a linear ring, 0 otherwise.`ISEMPTY()`

: Returns 1 if a geometry is an empty geometry, 0 otherwise.`ISSIMPLE()`

: Returns 1 if a geometry has no anomalous geometric points, such as self-intersection or self-tangency, 0 otherwise.

## Conclusion

The `BOUNDARY()`

function is a useful function to get the border of a geometry value. It can be applied to different types of geometries, such as points, line strings, and polygons. The function returns a geometry value of the same spatial reference system as the input, and the dimension of the output is one lower than the input. The function can be combined with other spatial functions to perform various spatial operations and analyses.