This topic describes the ST_MakePolygon function. This function constructs a polygon object by using shells.

Syntax

geometry  ST_MakePolygon(geometry  linestring);
geometry  ST_MakePolygon(geometry  outerlinestring , geometry[]  interiorlinestrings);

Parameters

Parameter Description
linestring The LineString object that represents the shell.
outerlinestring The LineString object that represents the outer shell.
interiorlinestrings The LineString object that represents the inner shell.

Description

You can specify only a closed LineString.

Examples

  • Construct a polygon object by using the default parameter settings.
    SELECT ST_AsText(ST_MakePolygon(ST_GeomFromText('LINESTRING(1 2,3 4,5 6,1 2)')));
             st_astext
    ----------------------------
     POLYGON((1 2,3 4,5 6,1 2))
    (1 row)
    
  • Construct a polygon object that has an inner shell.
    SELECT ST_AsText(ST_MakePolygon(ST_GeomFromText('LINESTRING(0 0,0 1,1 1,0 0)'),ARRAY[ST_GeomFromText('LINESTRING(-1 -1,-1 2,2 2,-1 -1)')]));
                         st_astext
    ---------------------------------------------------
     POLYGON((0 0,0 1,1 1,0 0),(-1 -1,-1 2,2 2,-1 -1))
    (1 row)