Name

ST_MakePolygon — Creates a Polygon from a number of LineStrings.

Synopsis

PostgreSQL

geometry ST_MakePolygon(bytea LineString);

geometry ST_MakePolygon(bytea LineString, bytea LineString);

geometry ST_MakePolygon(bytea LineString, bytea[] LineString Array);

H2

geometry ST_MakePolygon(bytea LineString);

geometry ST_MakePolygon(bytea LineString, bytea LineString);

geometry ST_MakePolygonEx(bytea LineString, bytea[] LineString Array);

Alias

MakePolygon

Description

Creates a Polygon from a number of LineStrings. The function has three variants.

The first one, takes a closed linestring.

The second one, takes a closed linestring forming the exterior ring and another closed linestring forming a hole.

The last one,takes a closed linestring forming the exterior ring and a set of closed linestring forming interior holes.

If the incoming geometry is a MultiLineString, the function just takes the first one LineString.

Coordinate Dimensions
2D3DM
Spatial Standards Support
OGC SFS for SQL. 1.1 (1999)OGC SFS for SQL. 1.1.0 (2005)OGC SFS for SQL. 1.2.0 (2006)SQL-MM Part 3
----

Examples

PostgreSQL
--1
SELECT ST_Asewkt(ST_MakePolygon(ST_GeomFromText('LINESTRING (0 0, 0 150, 150 150, 150 0, 0 0)')));
--Result
POLYGON ((0 0, 0 150, 150 150, 150 0, 0 0))

--2
SELECT ST_Asewkt(
  ST_MakePolygon(
       ST_GeomFromText('LINESTRING (0 0, 0 150, 150 150, 150 0, 0 0)'),
       ST_GeomFromText('LINESTRING(20 20, 50 20, 50 50, 20 50, 20 20)')));

--Result
POLYGON ((0 0, 0 150, 150 150, 150 0, 0 0), (20 20, 50 20, 50 50, 20 50, 20 20))
Array
--PostgreSQL
SELECT ST_Asewkt(ST_MakePolygon(
 ST_GeomFromText('LINESTRING (0 0, 0 150, 150 150, 150 0, 0 0)'),
 Array[
       ST_GeomFromText('LINESTRING(20 20, 50 20, 50 50, 20 50, 20 20)'),
       ST_GeomFromText('LINESTRING (90 100, 90 80, 110 80, 110 100, 90 100)')]));

--H2
SELECT ST_AsText(
  ST_MakePolygonEx(
      ST_GeomFromText('LINESTRING (0 0, 0 150, 150 150, 150 0, 0 0)'),
      st_accumagg(geom))) as mypol from (select array_get(
(
st_geomfromtext('LINESTRING(20 20, 50 20, 50 50, 20 50, 20 20)'),
st_geomfromtext('LINESTRING (90 100, 90 80, 110 80, 110 100, 90 100)')
),x)::binary as geom from (select x from system_range(1,3) as foo) as tabla);


--Result
POLYGON ((0 0, 0 150, 150 150, 150 0, 0 0), (20 20, 50 20, 50 50, 20 50, 20 20), (90 100, 90 80, 110 80, 110 100, 90 100))

Related functions

ST_Polygon