All pages
Powered by GitBook
1 of 24

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Geometry Properties

Learn about geometry properties. This section details SQL functions for retrieving attributes of spatial objects, such as area, length, and bounding box, essential for geospatial analysis.

IsClosed

Synonym for ST_ISCLOSED. Checks if a LineString's start and end points are the same (closed).

A synonym for ST_IsClosed.

This page is licensed: CC BY-SA / Gnu FDL

NumGeometries

Synonym for ST_NUMGEOMETRIES. Returns the number of geometries contained in a GeometryCollection.

A synonym for ST_NumGeometries.

This page is licensed: CC BY-SA / Gnu FDL

ST_ISCLOSED

Returns 1 if the LineString is closed (start and end points are the same), 0 if not, and NULL if the argument is NULL.

Syntax

ST_IsClosed(g)
IsClosed(g)

Description

Returns 1 if a given LINESTRING's start and end points are the same, or 0 if they are not the same.

ST_IsClosed() and IsClosed() are synonyms.

Examples

This page is licensed: CC BY-SA / Gnu FDL

SRID

Synonym for ST_SRID. Returns the Spatial Reference Identifier (SRID) integer associated with the geometry.

A synonym for ST_SRID.

This page is licensed: CC BY-SA / Gnu FDL

SET @ls = 'LineString(0 0, 0 4, 4 4, 0 0)';
SELECT ST_ISCLOSED(GEOMFROMTEXT(@ls));
+--------------------------------+
| ST_ISCLOSED(GEOMFROMTEXT(@ls)) |
+--------------------------------+
|                              1 |
+--------------------------------+

SET @ls = 'LineString(0 0, 0 4, 4 4, 0 1)';
SELECT ST_ISCLOSED(GEOMFROMTEXT(@ls));
+--------------------------------+
| ST_ISCLOSED(GEOMFROMTEXT(@ls)) |
+--------------------------------+
|                              0 |
+--------------------------------+

ST_RELATE

Tests if two geometries are spatially related according to a given DE-9IM intersection matrix pattern.

Syntax

ST_Relate(g1, g2, i)

Description

Returns true if Geometry g1 is spatially related to Geometryg2 by testing for intersections between the interior, boundary and exterior of the two geometries as specified by the values in intersection matrix pattern i.

This page is licensed: CC BY-SA / Gnu FDL

BOUNDARY

Synonym for ST_BOUNDARY. Returns a geometry representing the closure of the combinatorial boundary of the geometry value.

A synonym for ST_BOUNDARY.

This page is licensed: CC BY-SA / Gnu FDL

IsRing

Synonym for ST_ISRING. Checks if a LineString is a ring, meaning it is both closed and simple.

A synonym for ST_IsRing.

This page is licensed: CC BY-SA / Gnu FDL

GeometryN

Synonym for ST_GEOMETRYN. Returns the N-th geometry from a GeometryCollection, numbered starting from 1.

A synonym for .

This page is licensed: CC BY-SA / Gnu FDL

IsSimple

Synonym for ST_ISSIMPLE. Checks if a geometry is simple, meaning it has no anomalous geometric points like self-intersections.

A synonym for ST_IsSImple.

This page is licensed: CC BY-SA / Gnu FDL

GeometryType

Synonym for ST_GEOMETRYTYPE. Returns the name of the geometry type (e.g., 'POINT') of the geometry instance.

A synonym for ST_GeometryType.

This page is licensed: CC BY-SA / Gnu FDL

IsEmpty

Synonym for ST_ISEMPTY. Checks if a geometry is empty (contains no point sets). Returns 1 if empty, 0 otherwise.

A synonym for ST_IsEmpty.

This page is licensed: CC BY-SA / Gnu FDL

ST_GeometryN

ST_ISEMPTY

Checks if a geometry is empty. Returns 1 if the geometry contains no points, and 0 otherwise.

Syntax

ST_IsEmpty(g)
IsEmpty(g)

Description

IsEmpty is a function defined by the OpenGIS specification, but is not fully implemented by MariaDB or MySQL.

Since MariaDB and MySQL do not support GIS EMPTY values such as POINT EMPTY, as implemented it simply returns 1 if the geometry value g is invalid, 0 if it is valid, and NULL if the argument is NULL.

ST_IsEmpty() and IsEmpty() are synonyms.

This page is licensed: GPLv2, originally from

ST_GEOMETRYN

Returns the N-th geometry in a GeometryCollection. Geometries are numbered beginning with 1.

Syntax

ST_GeometryN(gc,N)
GeometryN(gc,N)

Description

Returns the N-th geometry in the GeometryCollection gc. Geometries are numbered beginning with 1.

ST_GeometryN() and GeometryN() are synonyms.

Example

This page is licensed: CC BY-SA / Gnu FDL

ST_ENVELOPE

Returns the Minimum Bounding Rectangle (MBR) for the geometry value. The result is returned as a Polygon defined by the corner points.

Syntax

ST_ENVELOPE(g)
ENVELOPE(g)

Description

Returns the Minimum Bounding Rectangle (MBR) for the geometry value g. The result is returned as a Polygon value.

The polygon is defined by the corner points of the bounding box:

ST_ENVELOPE() and ENVELOPE() are synonyms.

Examples

This page is licensed: GPLv2, originally from

ST_IsSimple

Checks if the geometry is simple (no self-intersections or anomalous points). Returns 1 if simple, 0 otherwise.

Syntax

ST_IsSimple(g)
IsSimple(g)

Description

Returns true if the given Geometry has no anomalous geometric points, false if it does, or NULL if given a NULL value.

ST_IsSimple() and IsSimple() are synonyms.

Examples

A POINT is always simple.

This page is licensed: CC BY-SA / Gnu FDL

ST_IsRing

Checks if the LineString is a ring. Returns 1 if the LineString is both closed (start equals end) and simple (no self-intersection).

Syntax

ST_IsRing(g)
IsRing(g)

Description

Returns true if a given LINESTRING is a ring, that is, both ST_IsClosed and ST_IsSimple. A simple curve does not pass through the same point more than once. However, see .

St_IsRing() and IsRing() are synonyms.

This page is licensed: CC BY-SA / Gnu FDL

ENVELOPE

Synonym for ST_ENVELOPE. Returns the Minimum Bounding Rectangle (MBR) for the given geometry as a Polygon.

A synonym for .

This page is licensed: CC BY-SA / Gnu FDL

ST_GEOMETRYTYPE

Returns the name of the geometry type (e.g., 'POINT', 'LINESTRING', 'POLYGON') for the given geometry instance.

Syntax

Description

Returns as a string the name of the geometry type of which the geometry instance g

fill_help_tables.sql
MDEV-7510
ST_ENVELOPE
SET @gc = 'GeometryCollection(Point(1 1),LineString(12 14, 9 11))';

SELECT AsText(GeometryN(GeomFromText(@gc),1));
+----------------------------------------+
| AsText(GeometryN(GeomFromText(@gc),1)) |
+----------------------------------------+
| POINT(1 1)                             |
+----------------------------------------+
POLYGON((MINX MINY, MAXX MINY, MAXX MAXY, MINX MAXY, MINX MINY))
SELECT AsText(ST_ENVELOPE(GeomFromText('LineString(1 1,4 4)')));
+----------------------------------------------------------+
| AsText(ST_ENVELOPE(GeomFromText('LineString(1 1,4 4)'))) |
+----------------------------------------------------------+
| POLYGON((1 1,4 1,4 4,1 4,1 1))                           |
+----------------------------------------------------------+
fill_help_tables.sql
SET @g = 'Point(1 2)';

SELECT ST_ISSIMPLE(GEOMFROMTEXT(@g));
+-------------------------------+
| ST_ISSIMPLE(GEOMFROMTEXT(@g)) |
+-------------------------------+
|                             1 |
+-------------------------------+
is a member. The name corresponds to one of the instantiable Geometry subclasses.

ST_GeometryType() and GeometryType() are synonyms.

Examples

This page is licensed: GPLv2, originally from fill_help_tables.sql

ST_GeometryType(g)
GeometryType(g)
SELECT GeometryType(GeomFromText('POINT(1 1)'));
+------------------------------------------+
| GeometryType(GeomFromText('POINT(1 1)')) |
+------------------------------------------+
| POINT                                    |
+------------------------------------------+

ST_NUMGEOMETRIES

Returns the number of geometries in a GeometryCollection. Returns NULL if the argument is not a GeometryCollection.

Syntax

ST_NumGeometries(gc)
NumGeometries(gc)

Description

Returns the number of geometries in the GeometryCollection gc.

ST_NumGeometries() and NumGeometries() are synonyms.

Example

This page is licensed: CC BY-SA / Gnu FDL

ST_SRID

Returns the Spatial Reference Identifier (SRID) for the geometry. This integer represents the coordinate system used.

Syntax

ST_SRID(g)
SRID(g)

Description

Returns an integer indicating the Spatial Reference System ID for the geometry value g.

In MariaDB, the SRID value is just an integer associated with the geometry value. All calculations are done assuming Euclidean (planar) geometry.

ST_SRID() and SRID() are synonyms.

Examples

This page is licensed: GPLv2, originally from

SET @gc = 'GeometryCollection(Point(1 1),LineString(2 2, 3 3))';

SELECT NUMGEOMETRIES(GeomFromText(@gc));
+----------------------------------+
| NUMGEOMETRIES(GeomFromText(@gc)) |
+----------------------------------+
|                                2 |
+----------------------------------+
SELECT SRID(GeomFromText('LineString(1 1,2 2)',101));
+-----------------------------------------------+
| SRID(GeomFromText('LineString(1 1,2 2)',101)) |
+-----------------------------------------------+
|                                           101 |
+-----------------------------------------------+
fill_help_tables.sql

DIMENSION

Synonym for ST_DIMENSION. Returns the inherent dimension of a geometry object (0 for Point, 1 for LineString, 2 for Polygon).

A synonym for ST_DIMENSION.

This page is licensed: CC BY-SA / Gnu FDL

ST_BOUNDARY

Returns the combinatorial boundary of a geometry. For a Polygon, this is the line string defining the boundary.

Syntax

Description

Returns a geometry that is the closure of the combinatorial boundary of the geometry value

ST_DIMENSION

Returns the inherent dimension of the geometry value. Returns 0 for points, 1 for linear geometries, and 2 for surface geometries.

Syntax

Description

Returns the inherent dimension of the geometry value

g
.

BOUNDARY() is a synonym.

Examples

This page is licensed: GPLv2, originally from fill_help_tables.sql

ST_BOUNDARY(g)
BOUNDARY(g)
g
. The result can be
Dimension
Definition

-1

empty geometry

0

geometry with no length or area

1

geometry with no area but nonzero length

2

geometry with nonzero area

ST_Dimension() and Dimension() are synonyms.

Examples

This page is licensed: GPLv2, originally from fill_help_tables.sql

SELECT ST_AsText(ST_Boundary(ST_GeomFromText('LINESTRING(3 3,0 0, -3 3)')));
+----------------------------------------------------------------------+
| ST_AsText(ST_Boundary(ST_GeomFromText('LINESTRING(3 3,0 0, -3 3)'))) |
+----------------------------------------------------------------------+
| MULTIPOINT(3 3,-3 3)                                                 |
+----------------------------------------------------------------------+

SELECT ST_AsText(ST_Boundary(ST_GeomFromText('POLYGON((3 3,0 0, -3 3, 3 3))')));
+--------------------------------------------------------------------------+
| ST_AsText(ST_Boundary(ST_GeomFromText('POLYGON((3 3,0 0, -3 3, 3 3))'))) |
+--------------------------------------------------------------------------+
| LINESTRING(3 3,0 0,-3 3,3 3)                                             |
+--------------------------------------------------------------------------+
ST_Dimension(g)
Dimension(g)
SELECT Dimension(GeomFromText('LineString(1 1,2 2)'));
+------------------------------------------------+
| Dimension(GeomFromText('LineString(1 1,2 2)')) |
+------------------------------------------------+
|                                              1 |
+------------------------------------------------+