SQL Reference
Geospatial Functions
Polygon Constructors
{{ocientgeo}} polygon constructors use geospatial data to create a polygon object st forceccw creates a standardized polygon from an existing one {{ocient}} defines standardized as the exterior being counterclockwise (ccw) and all holes being clockwise (cw) oriented syntax st forceccw(polygon) argument data type description polygon polygon a polygon to be converted on its exterior counterclockwise and clockwise for any interior holes example select st forceccw(st polygon('polygon((0 0,0 1,1 1,1 0,0 0))')); output polygon((0 0,1 0,1 1,0 1,0 0)) st makepolygon alias for /#stpolygon st polygon creates a polygon st polygon(geo) creates a polygon from the specified point , point array, linestring , or polygon geography syntax st polygon(geo) argument data type description geo polygon a point , point array, linestring , or polygon value to be converted to a polygon object example select st polygon( st linestring( st point \[]\( st point(1, 2), st point(1, 3), st point(1, 4), st point(1, 2)))); output polygon((1 2,1 3,1 4,1 2)) st polygon(char) alias for st makepolygon(char) creates a polygon from the specified char representing a polygon in wkt format syntax st polygon(char) argument data type description char char that represents a polygon in wkt format the char argument must represent a polygon in wkt format example select st polygon('polygon((1 2,1 3,1 4,1 2))'); output polygon((1 2,1 3,1 4,1 2)) st polygon(binary) alias for st polygonfromwkb(binary) creates a polygon from the specified binary the binary value must represent a polygon in wkb format syntax st polygon(binary) argument data type description binary binary that represents a polygon in wkb format a binary argument to be converted to a polygon the binary value must represent a polygon in wkb format example select st polygon(binary('0x01030000000100000005000000000000000000000000000000000000000000000000000000000000000000f03f000000000000f03f000000000000f03f000000000000f03f000000000000000000000000000000000000000000000000')); output polygon((0 0,0 1,1 1,1 0,0 0)) st polygon(outer ring, inner rings) alias for st makepolygon(outerring, innerrings) creates a polygon from the specified outer ring (that must be either a point , point array, or linestring ) and the array of interior rings (closed lines) the interior of the polygon is on the left when traveling around the exterior ring the interior of a hole is on the right when traveling around a hole syntax st polygon(outer ring, inner rings) argument data type description outer ring point , point array, or linestring a point , point array, or linestring that represents the outer ring of the polygon object inner rings array of point arrays, or array of linestring values an array of point arrays or linestring values that represents the inner rings or holes in the polygon object example select st polygon( st linestring(st point \[]\(st point(1, 2))), st linestring \[]\(st linestring(st point \[]\(st point(1, 2))))); output polygon((1 000000 2 000000), (1 000000 2 000000)) st polygonfromwkb alias for /#stpolygonbinary st polygonfromewkt alias for the /#stpolygon constructor creates a polygon using an ewkt formatted char as an input argument syntax st polygonfromewkt(char) argument data type description char char a string that includes an srid value and an ewkt formatted value that represents a polygon separate the values in the string by a semicolon in this format 'srid = value; polygon value' the input string must include the srid = value; component however, the database ignores this component as all ocient geography types are srid = 4326 example select st polygonfromewkt('srid=4326;polygon((1 2,1 3,1 4,1 2))'); output polygon((1 2,1 3,1 4,1 2)) st polygonfromgeojson creates a polygon represented by the specified geojson value as an input argument syntax st polygonfromgeojson(geojson \[, geodesic ] ) argument data type description geo json string a string of a geojson valid geojson formats follow https //datatracker ietf org/doc/rfc7946/ , which you can generate using the docid\ uq rlzenk gtplkr2hyb5 function if you specify an invalid geojson, the behavior of the function is undefined the function returns null if any argument is a null value geodesic boolean optional if you specify geodesic as true , the function adds points to the resulting polygon such that it remains within 10 meters of the original planar polygon if you do not specify this argument, the value defaults to false examples in this example, the function produces an empty polygon value from the geojson representation select st polygonfromgeojson('{"type" "polygon","coordinates" \[]}',false); output polygon empty in this example, the function produces a polygon value from the geojson representation select st polygonfromgeojson( '{"type" "polygon","coordinates" \[\[\[1,1],\[1,5],\[5,5],\[5,1]]]}', false); output polygon((1 1, 1 5, 5 5, 5 1)) st polygonfromtext alias for /#stpolygonchar st wholeearth returns the database internal representation of the whole earth polygon the docid\ aawcrtqvk1nkc0hcgthci function returns this polygon value, with the envelope set as the entire earth gis specifications do not describe a canonical polygon for the whole earth, but this value serves as the ocient canonical polygon the whole earth polygon is also equivalent to st polygon('polygon((0 0,0 0,0 0,0 0'))) , which can have a separate meaning in other gis implementations syntax st wholeearth() example select st wholeearth(); output polygon((0 0 0 0, 0 0 0 0, 0 0 0 0, 0 0 0 0)) related links docid\ ogtviwl gtbgv0chhrh 3 docid\ uq rlzenk gtplkr2hyb5