Documentation Home
MySQL 9.0 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 40.0Mb
PDF (A4) - 40.1Mb
Man Pages (TGZ) - 259.0Kb
Man Pages (Zip) - 366.2Kb
Info (Gzip) - 4.0Mb
Info (Zip) - 4.0Mb


MySQL 9.0 Reference Manual  / ...  / Functions and Operators  / Spatial Analysis Functions  / Geometry Property Functions  /  Polygon and MultiPolygon Property Functions

14.16.7.4 Polygon and MultiPolygon Property Functions

Functions in this section return properties ofPolygon orMultiPolygon values.

Unless otherwise specified, functions in this section handle their geometry arguments as follows:

  • If any argument isNULL or any geometry argument is an empty geometry, the return value isNULL.

  • If any geometry argument is not a syntactically well-formed geometry, anER_GIS_INVALID_DATA error occurs.

  • If any geometry argument is a syntactically well-formed geometry in an undefined spatial reference system (SRS), anER_SRS_NOT_FOUND error occurs.

  • For functions that take multiple geometry arguments, if those arguments are not in the same SRS, anER_GIS_DIFFERENT_SRIDS error occurs.

  • Otherwise, the return value is non-NULL.

These functions are available for obtaining polygon properties:

  • ST_Area({poly|mpoly})

    Returns a double-precision number indicating the area of thePolygon orMultiPolygon argument, as measured in its spatial reference system.

    ST_Area() handles its arguments as described in the introduction to this section, with these exceptions:

    • If the geometry is geometrically invalid, either the result is an undefined area (that is, it can be any number), or an error occurs.

    • If the geometry is valid but is not aPolygon orMultiPolygon object, anER_UNEXPECTED_GEOMETRY_TYPE error occurs.

    • If the geometry is a validPolygon in a Cartesian SRS, the result is the Cartesian area of the polygon.

    • If the geometry is a validMultiPolygon in a Cartesian SRS, the result is the sum of the Cartesian area of the polygons.

    • If the geometry is a validPolygon in a geographic SRS, the result is the geodetic area of the polygon in that SRS, in square meters.

    • If the geometry is a validMultiPolygon in a geographic SRS, the result is the sum of geodetic area of the polygons in that SRS, in square meters.

    • If an area computation results in+inf, anER_DATA_OUT_OF_RANGE error occurs.

    • If the geometry has a geographic SRS with a longitude or latitude that is out of range, an error occurs:

      Ranges shown are in degrees. The exact range limits deviate slightly due to floating-point arithmetic.

    mysql> SET @poly =       'Polygon((0 0,0 3,3 0,0 0),(1 1,1 2,2 1,1 1))';mysql> SELECT ST_Area(ST_GeomFromText(@poly));+---------------------------------+| ST_Area(ST_GeomFromText(@poly)) |+---------------------------------+|                               4 |+---------------------------------+mysql> SET @mpoly =       'MultiPolygon(((0 0,0 3,3 3,3 0,0 0),(1 1,1 2,2 2,2 1,1 1)))';mysql> SELECT ST_Area(ST_GeomFromText(@mpoly));+----------------------------------+| ST_Area(ST_GeomFromText(@mpoly)) |+----------------------------------+|                                8 |+----------------------------------+
  • ST_Centroid({poly|mpoly})

    Returns the mathematical centroid for thePolygon orMultiPolygon argument as aPoint. The result is not guaranteed to be on theMultiPolygon.

    This function processes geometry collections by computing the centroid point for components of highest dimension in the collection. Such components are extracted and made into a singleMultiPolygon,MultiLineString, orMultiPoint for centroid computation.

    ST_Centroid() handles its arguments as described in the introduction to this section, with these exceptions:

    • The return value isNULL for the additional condition that the argument is an empty geometry collection.

    • If the geometry has an SRID value for a geographic spatial reference system (SRS), anER_NOT_IMPLEMENTED_FOR_GEOGRAPHIC_SRS error occurs.

    mysql> SET @poly =       ST_GeomFromText('POLYGON((0 0,10 0,10 10,0 10,0 0),(5 5,7 5,7 7,5 7,5 5))');mysql> SELECT ST_GeometryType(@poly),ST_AsText(ST_Centroid(@poly));+------------------------+--------------------------------------------+| ST_GeometryType(@poly) | ST_AsText(ST_Centroid(@poly))              |+------------------------+--------------------------------------------+| POLYGON                | POINT(4.958333333333333 4.958333333333333) |+------------------------+--------------------------------------------+
  • ST_ExteriorRing(poly)

    Returns the exterior ring of thePolygon valuepoly as aLineString.

    ST_ExteriorRing() handles its arguments as described in the introduction to this section.

    mysql> SET @poly =       'Polygon((0 0,0 3,3 3,3 0,0 0),(1 1,1 2,2 2,2 1,1 1))';mysql> SELECT ST_AsText(ST_ExteriorRing(ST_GeomFromText(@poly)));+----------------------------------------------------+| ST_AsText(ST_ExteriorRing(ST_GeomFromText(@poly))) |+----------------------------------------------------+| LINESTRING(0 0,0 3,3 3,3 0,0 0)                    |+----------------------------------------------------+
  • ST_InteriorRingN(poly,N)

    Returns theN-th interior ring for thePolygon valuepoly as aLineString. Rings are numbered beginning with 1.

    ST_InteriorRingN() handles its arguments as described in the introduction to this section.

    mysql> SET @poly =       'Polygon((0 0,0 3,3 3,3 0,0 0),(1 1,1 2,2 2,2 1,1 1))';mysql> SELECT ST_AsText(ST_InteriorRingN(ST_GeomFromText(@poly),1));+-------------------------------------------------------+| ST_AsText(ST_InteriorRingN(ST_GeomFromText(@poly),1)) |+-------------------------------------------------------+| LINESTRING(1 1,1 2,2 2,2 1,1 1)                       |+-------------------------------------------------------+
  • ST_NumInteriorRing(poly),ST_NumInteriorRings(poly)

    Returns the number of interior rings in thePolygon valuepoly.

    ST_NumInteriorRing() andST_NuminteriorRings() handle their arguments as described in the introduction to this section.

    mysql> SET @poly =       'Polygon((0 0,0 3,3 3,3 0,0 0),(1 1,1 2,2 2,2 1,1 1))';mysql> SELECT ST_NumInteriorRings(ST_GeomFromText(@poly));+---------------------------------------------+| ST_NumInteriorRings(ST_GeomFromText(@poly)) |+---------------------------------------------+|                                           1 |+---------------------------------------------+