Skip to main content

ST_POLYGON

Description​

Converts a string in WKT (Well-Known Text) format into an in-memory Polygon geometric object.

Alias​

  • st_polygonfromtext
  • st_polyfromtext

Sytax​

ST_POLYGON( <wkt>)

Parameters​

ParameterDescription
<wkt>A WKT text of a polygon generated by the POLYGON function

Return value​

Returns a geometric object of type Polygon, which is stored in memory in Doris' internal spatial data format and can be directly passed as a parameter to other spatial functions (such as ST_AREA, ST_CONTAINS, etc.) for calculation.

  • Returns NULL if the input WKT string is invalid (e.g., unclosed ring, syntax error).
  • Returns NULL if the input is NULL or an empty string.

Example​

Basic polygon

SELECT ST_AsText(ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))"));
+------------------------------------------------------------------+
| st_astext(st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) |
+------------------------------------------------------------------+
| POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0)) |
+------------------------------------------------------------------+

Self-intersecting polygon (invalid)

mysql> select st_polygon('POLYGON ((0 0, 1 1, 0 1, 1 0, 0 0))');
+---------------------------------------------------+
| st_polygon('POLYGON ((0 0, 1 1, 0 1, 1 0, 0 0))') |
+---------------------------------------------------+
| NULL |
+---------------------------------------------------+

Invalid WKT (unclosed ring)

mysql> SELECT ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10))");
+--------------------------------------------------+
| ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10))") |
+--------------------------------------------------+
| NULL |
+--------------------------------------------------+

Invalid WKT (syntax error)


mysql> SELECT ST_Polygon("POLYGON (0 0, 10 0, 10 10, 0 10, 0 0)");
+-----------------------------------------------------+
| ST_Polygon("POLYGON (0 0, 10 0, 10 10, 0 10, 0 0)") |
+-----------------------------------------------------+
| NULL |
+-----------------------------------------------------+

input NULL

mysql> SELECT ST_Polygon(NULL);
+------------------+
| ST_Polygon(NULL) |
+------------------+
| NULL |
+------------------+