Categories:

Geospatial Functions

ST_MAKEPOLYGON , ST_POLYGON

Constructs a GEOGRAPHY or GEOGRAPHY object that represents a polygon without holes. The function uses the specified LineString as the outer loop.

See also:

TO_GEOGRAPHY , TO_GEOMETRY

Syntax

ST_MAKEPOLYGON( <geography_or_geometry_expression> )

Arguments

geography_or_geometry_expression

A GEOGRAPHY or GEOMETRY 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 or GEOMETRY.

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.

  • For GEOMETRY objects, the returned GEOMETRY object has the same SRID as the input.

Examples

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

GEOMETRY Examples

This shows a simple use of the ST_MAKEPOLYGON function.

SELECT ST_MAKEPOLYGON(
  TO_GEOMETRY('LINESTRING(0.0 0.0, 1.0 0.0, 1.0 2.0, 0.0 2.0, 0.0 0.0)')
  ) AS polygon;
+--------------------------------+
| POLYGON                        |
|--------------------------------|
| POLYGON((0 0,1 0,1 2,0 2,0 0)) |
+--------------------------------+
Back to top