Skip to main content

ST_MAKEPOLYGONORIENTED

Introduced or updated: v1.2.911

Creates a Polygon from a LineString input, preserving the vertex order as given. Unlike ST_MAKEPOLYGON, this function does not reorder vertices to enforce a specific winding direction.

Syntax

ST_MAKEPOLYGONORIENTED(<geometry>)

Arguments

ArgumentsDescription
<geometry>A GEOMETRY expression of type LineString. Must have at least 4 points with the first and last point being identical.
note
  • Only LineString input is accepted. Other types produce an error.
  • The LineString must form a valid polygon (no self-intersections).

Return Type

Geometry.

Examples

SELECT ST_ASWKT(
ST_MAKEPOLYGONORIENTED(TO_GEOMETRY('LINESTRING(0 0, 1 0, 1 2, 0 2, 0 0)'))
);

┌──────────────────────────────────┐
│ result │
├──────────────────────────────────┤
POLYGON((0 0,1 0,1 2,0 2,0 0))
└──────────────────────────────────┘

-- Reversed winding order is preserved
SELECT ST_ASWKT(
ST_MAKEPOLYGONORIENTED(TO_GEOMETRY('LINESTRING(0 0, 0 2, 1 2, 1 0, 0 0)'))
);

┌──────────────────────────────────┐
│ result │
├──────────────────────────────────┤
POLYGON((0 0,0 2,1 2,1 0,0 0))
└──────────────────────────────────┘
Try Databend Cloud for FREE

Multimodal, object-storage-native warehouse for BI, vectors, search, and geo.

Snowflake-compatible SQL with automatic scaling.

Sign up and get $200 in credits.

Try it today