Skip to main content

ST_AREA_SQUARE_METERS

Description​

Calculates the area of a closed region on the Earth's surface in square meters. The input parameter is a geometric object representing a region on the Earth's surface (such as polygons, circles, polyhedrons, etc.).

For non-closed geometric objects (such as points, line segments), their area is 0; for invalid geometric objects (such as self-intersecting polygons), returns NULL.

Sytax​

ST_AREA_SQUARE_METERS( <geo>)

Parameters​

ParameterDescription
<geo>A geometric object on the Earth's surface, supporting closed region types such as GeoPolygon, GeoCircle, and GeoMultiPolygon.

Return value​

Returns the area of the region in square meters, of type DOUBLE.

ST_AREA_SQUARE_METERS has the following edge cases:

  • If the input parameter is NULL, returns NULL.
  • If the input is a non-closed geometric object (such as point GeoPoint, line segment GeoLineString), returns 0.
  • If the input geometric object is invalid (such as self-intersecting polygon, unclosed polygon), returns NULL.
  • If the input coordinates exceed the longitude/latitude range (longitude [-180, 180], latitude [-90, 90]), returns NULL.

Example​

Circular region (circle with a radius of 1 degree)

SELECT ST_Area_Square_Meters(ST_Circle(0, 0, 1));
+-------------------------------------------------+
| st_area_square_meters(st_circle(0.0, 0.0, 1.0)) |
+-------------------------------------------------+
| 3.1415926535897869 |
+-------------------------------------------------+

Point object (no area)

SELECT ST_Area_Square_Meters(ST_Point(0, 1));
+-------------------------------------------+
| st_area_square_meters(st_point(0.0, 1.0)) |
+-------------------------------------------+
| 0 |
+-------------------------------------------+

Line segment object (no area)

SELECT ST_Area_Square_Meters(ST_LineFromText("LINESTRING (1 1, 2 2)"));
+-----------------------------------------------------------------+
| st_area_square_meters(st_linefromtext('LINESTRING (1 1, 2 2)')) |
+-----------------------------------------------------------------+
| 0 |
+-----------------------------------------------------------------+

Simple square region (small longitude/latitude range)


mysql> SELECT ST_Area_Square_Meters(ST_Polygon("POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))"));
+--------------------------------------------------------------------------+
| ST_Area_Square_Meters(ST_Polygon("POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))")) |
+--------------------------------------------------------------------------+
| 12364036567.076408 |
+--------------------------------------------------------------------------+

Complex polygon region

mysql> SELECT ST_Area_Square_Meters(ST_Polygon("POLYGON ((0 0, 5 1, 10 0, 5 -1, 0 0))"));
+----------------------------------------------------------------------------+
| ST_Area_Square_Meters(ST_Polygon("POLYGON ((0 0, 5 1, 10 0, 5 -1, 0 0))")) |
+----------------------------------------------------------------------------+
| 123725166420.83101 |
+----------------------------------------------------------------------------+

Rectangular region crossing 180Β° longitude


mysql> SELECT ST_Area_Square_Meters(ST_Polygon("POLYGON ((179 0, 180 0, 180 1, 179 1, 179 0))"));
+------------------------------------------------------------------------------------+
| ST_Area_Square_Meters(ST_Polygon("POLYGON ((179 0, 180 0, 180 1, 179 1, 179 0))")) |
+------------------------------------------------------------------------------------+
| 12364036567.07628 |
+------------------------------------------------------------------------------------+

Circular region in the Southern Hemisphere

mysql> SELECT ST_Area_Square_Meters(ST_Circle(0, -30, 2));
+---------------------------------------------+
| ST_Area_Square_Meters(ST_Circle(0, -30, 2)) |
+---------------------------------------------+
| 12.566370614359073 |
+---------------------------------------------+

Invalid polygon (self-intersecting)

mysql>  SELECT ST_Area_Square_Meters(ST_Polygon("POLYGON ((0 0, 1 1, 0 1, 1 0, 0 0))"));
+--------------------------------------------------------------------------+
| ST_Area_Square_Meters(ST_Polygon("POLYGON ((0 0, 1 1, 0 1, 1 0, 0 0))")) |
+--------------------------------------------------------------------------+
| NULL |
+--------------------------------------------------------------------------+

Unclosed polygon

mysql> SELECT ST_Area_Square_Meters(ST_Polygon("POLYGON ((0 0, 1 0, 1 1, 0 1))"));
+---------------------------------------------------------------------+
| ST_Area_Square_Meters(ST_Polygon("POLYGON ((0 0, 1 0, 1 1, 0 1))")) |
+---------------------------------------------------------------------+
| NULL |
+---------------------------------------------------------------------+

Coordinates out of range

mysql>  SELECT ST_Area_Square_Meters(ST_Polygon("POLYGON ((0 0, 200 0, 200 1, 0 1, 0 0))"));
+------------------------------------------------------------------------------+
| ST_Area_Square_Meters(ST_Polygon("POLYGON ((0 0, 200 0, 200 1, 0 1, 0 0))")) |
+------------------------------------------------------------------------------+
| NULL |
+------------------------------------------------------------------------------+

Null input

mysql> SELECT ST_Area_Square_Meters(NULL);
+-----------------------------+
| ST_Area_Square_Meters(NULL) |
+-----------------------------+
| NULL |
+-----------------------------+