#### 12.17.7.4 Polygon and MultiPolygon Property Functions

 Functions in this section return properties of `Polygon` or `MultiPolygon` values.

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

* If any argument is `NULL` or any geometry argument is an empty geometry, the return value is `NULL`.

* If any geometry argument is not a syntactically well-formed geometry, an [`ER_GIS_INVALID_DATA`](https://dev.mysql.com/doc/mysql-errors/8.0/en/server-error-reference.html#error_er_gis_invalid_data) error occurs.

* If any geometry argument is a syntactically well-formed geometry in an undefined spatial reference system (SRS), an [`ER_SRS_NOT_FOUND`](https://dev.mysql.com/doc/mysql-errors/8.0/en/server-error-reference.html#error_er_srs_not_found) error occurs.

* For functions that take multiple geometry arguments, if those arguments are not in the same SRS, an [`ER_GIS_DIFFERENT_SRIDS`](https://dev.mysql.com/doc/mysql-errors/8.0/en/server-error-reference.html#error_er_gis_different_srids) error occurs.

* Otherwise, the return value is non-`NULL`.

 These functions are available for obtaining polygon properties:

* []()

  [`ST_Area({*`poly`*|*`mpoly`*})`](gis-polygon-property-functions.html#function_st-area)

  []()

   Returns a double-precision number indicating the area of the `Polygon` or `MultiPolygon` argument, as measured in its spatial reference system.

   As of MySQL 8.0.13, [`ST_Area()`](gis-polygon-property-functions.html#function_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 a `Polygon` or `MultiPolygon` object, an [`ER_UNEXPECTED_GEOMETRY_TYPE`](https://dev.mysql.com/doc/mysql-errors/8.0/en/server-error-reference.html#error_er_unexpected_geometry_type) error occurs.

  * If the geometry is a valid `Polygon` in a Cartesian SRS, the result is the Cartesian area of the polygon.

  * If the geometry is a valid `MultiPolygon` in a Cartesian SRS, the result is the sum of the Cartesian area of the polygons.

  * If the geometry is a valid `Polygon` in a geographic SRS, the result is the geodetic area of the polygon in that SRS, in square meters.

  * If the geometry is a valid `MultiPolygon` 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`, an [`ER_DATA_OUT_OF_RANGE`](https://dev.mysql.com/doc/mysql-errors/8.0/en/server-error-reference.html#error_er_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:

    * If a longitude value is not in the range (−180, 180], an [`ER_GEOMETRY_PARAM_LONGITUDE_OUT_OF_RANGE`](https://dev.mysql.com/doc/mysql-errors/8.0/en/server-error-reference.html#error_er_geometry_param_longitude_out_of_range) error occurs ([`ER_LONGITUDE_OUT_OF_RANGE`](https://dev.mysql.com/doc/mysql-errors/8.0/en/server-error-reference.html#error_er_longitude_out_of_range) prior to MySQL 8.0.12).

    * If a latitude value is not in the range [−90, 90], an [`ER_GEOMETRY_PARAM_LATITUDE_OUT_OF_RANGE`](https://dev.mysql.com/doc/mysql-errors/8.0/en/server-error-reference.html#error_er_geometry_param_latitude_out_of_range) error occurs ([`ER_LATITUDE_OUT_OF_RANGE`](https://dev.mysql.com/doc/mysql-errors/8.0/en/server-error-reference.html#error_er_latitude_out_of_range) prior to MySQL 8.0.12).

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

   Prior to MySQL 8.0.13, [`ST_Area()`](gis-polygon-property-functions.html#function_st-area) handles its arguments as described in the introduction to this section, with these exceptions:

  * For arguments of dimension 0 or 1, the result is 0.

  * If a geometry is empty, the return value is 0 rather than `NULL`.

  * For a geometry collection, the result is the sum of the area values of all components. If the geometry collection is empty, its area is returned as 0.

  * If the geometry has an SRID value for a geographic spatial reference system (SRS), an [`ER_NOT_IMPLEMENTED_FOR_GEOGRAPHIC_SRS`](https://dev.mysql.com/doc/mysql-errors/8.0/en/server-error-reference.html#error_er_not_implemented_for_geographic_srs) error occurs.

  ```
  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`*})`](gis-polygon-property-functions.html#function_st-centroid)

  []()

   Returns the mathematical centroid for the `Polygon` or `MultiPolygon` argument as a `Point`. The result is not guaranteed to be on the `MultiPolygon`.

   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 single `MultiPolygon`, `MultiLineString`, or `MultiPoint` for centroid computation.

  [`ST_Centroid()`](gis-polygon-property-functions.html#function_st-centroid) handles its arguments as described in the introduction to this section, with these exceptions:

  * The return value is `NULL` 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), an [`ER_NOT_IMPLEMENTED_FOR_GEOGRAPHIC_SRS`](https://dev.mysql.com/doc/mysql-errors/8.0/en/server-error-reference.html#error_er_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`*)`](gis-polygon-property-functions.html#function_st-exteriorring)

  []()

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

  [`ST_ExteriorRing()`](gis-polygon-property-functions.html#function_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`*)`](gis-polygon-property-functions.html#function_st-interiorringn)

  []()

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

  [`ST_InteriorRingN()`](gis-polygon-property-functions.html#function_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`*)`](gis-polygon-property-functions.html#function_st-numinteriorrings), [`ST_NumInteriorRings(*`poly`*)`](gis-polygon-property-functions.html#function_st-numinteriorrings)

  []()[]()

   Returns the number of interior rings in the `Polygon` value *`poly`*.

  [`ST_NumInteriorRing()`](gis-polygon-property-functions.html#function_st-numinteriorrings) and [`ST_NuminteriorRings()`](gis-polygon-property-functions.html#function_st-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 |
  +---------------------------------------------+
  ```

