All pages
Powered by GitBook
1 of 11

Polygon Properties

Learn about POLYGON properties in MariaDB Server. This section details SQL functions for retrieving attributes of polygonal spatial objects, such as area, perimeter, and the number of rings.

CENTROID

A synonym for ST_CENTROID.

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

AREA

A synonym for ST_AREA.

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

ExteriorRing

A synonym for ST_ExteriorRing.

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

InteriorRingN

A synonym for ST_InteriorRingN.

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

NumInteriorRings

A synonym for ST_NumInteriorRings.

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

ST_AREA

Syntax

ST_Area(poly)
Area(poly)

Description

Returns as a double-precision number the area of the Polygon value poly, as measured in its spatial reference system.

ST_Area() and Area() are synonyms.

Examples

SET @poly = 'Polygon((0 0,0 3,3 0,0 0),(1 1,1 2,2 1,1 1))';

SELECT Area(GeomFromText(@poly));
+---------------------------+
| Area(GeomFromText(@poly)) |
+---------------------------+
|                         4 |
+---------------------------+

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

ST_CENTROID

Syntax

ST_Centroid(mpoly)
Centroid(mpoly)

Description

Returns a point reflecting the mathematical centroid (geometric center) for the MultiPolygon mpoly. The resulting point will not necessarily be on the MultiPolygon.

ST_Centroid() and Centroid() are synonyms.

Examples

SET @poly = ST_GeomFromText('POLYGON((0 0,20 0,20 20,0 20,0 0))');
SELECT ST_AsText(ST_Centroid(@poly)) AS center;
+--------------+
| center       |
+--------------+
| POINT(10 10) |
+--------------+

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

ST_ExteriorRing

Syntax

ST_ExteriorRing(poly)
ExteriorRing(poly)

Description

Returns the exterior ring of the Polygon value poly as a LineString.

ST_ExteriorRing() and ExteriorRing() are synonyms.

Examples

SET @poly = 'Polygon((0 0,0 3,3 3,3 0,0 0),(1 1,1 2,2 2,2 1,1 1))';

SELECT AsText(ExteriorRing(GeomFromText(@poly)));
+-------------------------------------------+
| AsText(ExteriorRing(GeomFromText(@poly))) |
+-------------------------------------------+
| LINESTRING(0 0,0 3,3 3,3 0,0 0)           |
+-------------------------------------------+

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

ST_InteriorRingN

Syntax

ST_InteriorRingN(poly,N)
InteriorRingN(poly,N)

Description

Returns the N-th interior ring for the Polygon value poly as a LineString. Rings are numbered beginning with 1.

ST_InteriorRingN() and InteriorRingN() are synonyms.

Examples

SET @poly = 'Polygon((0 0,0 3,3 3,3 0,0 0),(1 1,1 2,2 2,2 1,1 1))';

SELECT AsText(InteriorRingN(GeomFromText(@poly),1));
+----------------------------------------------+
| AsText(InteriorRingN(GeomFromText(@poly),1)) |
+----------------------------------------------+
| LINESTRING(1 1,1 2,2 2,2 1,1 1)              |
+----------------------------------------------+

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

ST_NumInteriorRings

Syntax

ST_NumInteriorRings(poly)
NumInteriorRings(poly)

Description

Returns an integer containing the number of interior rings in the Polygon value poly.

Note that according the OpenGIS standard, a POLYGON should have exactly one ExteriorRing and all other rings should lie within that ExteriorRing and thus be the InteriorRings. Practically, however, some systems, including MariaDB's, permit polygons to have several 'ExteriorRings'. In the case of there being multiple, non-overlapping exterior rings ST_NumInteriorRings() will return 1.

ST_NumInteriorRings() and NumInteriorRings() are synonyms.

Examples

SET @poly = 'Polygon((0 0,0 3,3 3,3 0,0 0),(1 1,1 2,2 2,2 1,1 1))';

SELECT NumInteriorRings(GeomFromText(@poly));
+---------------------------------------+
| NumInteriorRings(GeomFromText(@poly)) |
+---------------------------------------+
|                                     1 |
+---------------------------------------+

Non-overlapping 'polygon':

SELECT ST_NumInteriorRings(ST_PolyFromText('POLYGON((0 0,10 0,10 10,0 10,0 0),
  (-1 -1,-5 -1,-5 -5,-1 -5,-1 -1))')) AS NumInteriorRings;
+------------------+
| NumInteriorRings |
+------------------+
|                1 |
+------------------+

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