Categories:

Geospatial Functions

ST_MAKEPOLYGON , ST_POLYGON

Constructs a GEOGRAPHY value that contains a polygon without holes, using the specified linestring as the outer loop.

See also:

TO_GEOGRAPHY

Syntax

ST_MAKEPOLYGON( <geography_1> )

Arguments

geography_1

A GEOGRAPHY object that represents a LineString in which the last point is the same as the first (i.e. a loop).

Returns

The function returns a value of type GEOGRAPHY.

Usage Notes

  • The lines of the polygon must form a loop. Therefore, the last point in the sequence of points defining the linestring must be the same point as the first point in the sequence.

  • ST_POLYGON is an alias for ST_MAKEPOLYGON.

Examples

This shows a simple use of the ST_MAKEPOLYGON function. The sequence of points below defines a geodesic rectangular area 1 degree wide and 2 degrees high, with the lower left corner of the polygon starting at the equator (latitude) and Greenwich (longitude). The last point in the sequence is the same as the first point, which completes the loop.

SELECT ST_MAKEPOLYGON(
   TO_GEOGRAPHY('LINESTRING(0.0 0.0, 1.0 0.0, 1.0 2.0, 0.0 2.0, 0.0 0.0)')
   ) AS polygon1;
+--------------------------------+
| POLYGON1                       |
|--------------------------------|
| POLYGON((0 0,1 0,1 2,0 2,0 0)) |
+--------------------------------+