Топ-100
 
RDBMS Type: MySQL
Topic

ST_Area({poly|mpoly})

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() handles its arguments as described in the
introduction to this section, with these exceptions:

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

o 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.

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

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

o 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.

o 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.

o 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.

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

o If a longitude argument 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-referen
ce.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-referen
ce.html#error_er_longitude_out_of_range) prior to MySQL 8.0.12).

o If a latitude argument 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-referen
ce.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-referen
ce.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() handles its arguments as described in
the introduction to this section, with these exceptions:

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

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

o 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.

o 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.

URL: https://dev.mysql.com/doc/refman/8.0/en/gis-polygon-property-functions.html

Example

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 |
+----------------------------------+