Categories:

Geospatial functions, Conversion functions

ST_GEOMETRYFROMWKT

Parses a WKT (well-known text) (link removed) or EWKT (extended well-known text) input and returns a value of type GEOMETRY.

Aliases:

ST_GEOMFROMWKT , ST_GEOMETRYFROMEWKT , ST_GEOMFROMEWKT , ST_GEOMETRYFROMTEXT , ST_GEOMFROMTEXT

See also:

TO_GEOMETRY

Syntax

ST_GEOMETRYFROMWKT( <varchar_expression> [ , <srid> ] [ , <allow_invalid> ] )

ST_GEOMFROMWKT( <varchar_expression> [ , <srid> ] [ , <allow_invalid> ] )

ST_GEOMETRYFROMEWKT( <varchar_expression> [ , <srid> ] [ , <allow_invalid> ] )

ST_GEOMFROMEWKT( <varchar_expression> [ , <srid> ] [ , <allow_invalid> ] )

ST_GEOMETRYFROMTEXT( <varchar_expression> [ , <srid> ] [ , <allow_invalid> ] )

ST_GEOMFROMTEXT( <varchar_expression> [ , <srid> ] [ , <allow_invalid> ] )
Copy

Arguments

Required:

varchar_expression

The argument must be a string expression in WKT or EWKT that represents a valid geospatial object.

Optional:

srid

The integer value of the SRID to use.

allow_invalid

If TRUE, specifies that the function should return a GEOGRAPHY or GEOMETRY object, even when the input shape is invalid and cannot be repaired. For details, refer to Specifying how invalid geospatial shapes are handled.

Returns

The function returns a value of type GEOMETRY.

Usage notes

  • Issues an error if the input cannot be parsed as WKT or EWKT.

  • For WKT input, if the srid argument is not specified, the resulting GEOMETRY object has the SRID set to 0.

Examples

The following example returns the GEOMETRY object for a geospatial object described in EWKT format:

-- Set the output format to EWKT
ALTER SESSION SET GEOMETRY_OUTPUT_FORMAT='EWKT';

SELECT ST_GEOMETRYFROMEWKT('SRID=32633;POINT(389866.35 5819003.03)');
Copy
+---------------------------------------------------------------+
| ST_GEOMETRYFROMEWKT('SRID=32633;POINT(389866.35 5819003.03)') |
|---------------------------------------------------------------|
| SRID=32633;POINT(389866.35 5819003.03)                        |
+---------------------------------------------------------------+

The following example returns the GEOMETRY object for a geospatial object with a Z coordinate described in EWKT format:

-- Set the output format to EWKT
ALTER SESSION SET GEOMETRY_OUTPUT_FORMAT='EWKT';

SELECT ST_GEOMETRYFROMEWKT('SRID=32633;POINTZ(389866.35 5819003.03 30)');
Copy
+-------------------------------------------------------------------+
| ST_GEOMETRYFROMEWKT('SRID=32633;POINTZ(389866.35 5819003.03 30)') |
|-------------------------------------------------------------------|
| SRID=32633;POINTZ(389866.35 5819003.03 30)                        |
+-------------------------------------------------------------------+

In the next example, the input is in WKT format, and the function call specifies the SRID to use:

-- Set the output format to EWKT
ALTER SESSION SET GEOMETRY_OUTPUT_FORMAT='EWKT';

SELECT ST_GEOMETRYFROMWKT('POINT(389866.35 5819003.03)', 4326);
Copy
+----------------------------------------------------------+
| ST_GEOMETRYFROMWKT('POINT(389866.35 5819003.03)', 4326)  |
|----------------------------------------------------------|
| SRID=4326;POINT(389866.35 5819003.03)                    |
+----------------------------------------------------------+
Language: English