Categories:

TO_GEOMETRY¶

Parses an input and returns a value of type GEOMETRY.

Syntax¶

Use one of the following:

TO_GEOMETRY( <varchar_expression> )

TO_GEOMETRY( <binary_expression> )

TO_GEOMETRY( <variant_expression> )


Arguments¶

varchar_expression

The argument must be a string expression that represents a valid geometric object in one of the following formats:

• WKT (well-known text).

• WKB (well-known binary) in hexadecimal format (without a leading 0x).

• EWKT (extended well-known text).

• EWKB (extended well-known binary) in hexadecimal format (without a leading 0x).

• GeoJSON.

binary_expression

The argument must be a binary expression in WKB or EWKB format.

variant_expression

The argument must be an OBJECT in GeoJSON format.

Returns¶

The function returns a value of type GEOMETRY.

Usage Notes¶

• Issues an error if the input cannot be parsed as one of the supported formats (WKT, WKB, EWKT, EWKB, GeoJSON).

• For GeoJSON, WKT, and WKB input, the resulting GEOMETRY object has SRID set to 0. To change the SRID, pass the GEOMETRY object to ST_SETSRID, specifying the SRID that you want to set. ST_SETSRID returns the GEOMETRY object with that SRID set.

• To construct a GEOMETRY object from WKT or EWKT input, you can also use ST_GEOMETRYFROMWKT.

• To construct a GEOMETRY object from WKB or EWKB input, you can also use ST_GEOMETRYFROMWKB.

Examples¶

This shows a simple use of the TO_GEOMETRY function with VARCHAR data:

alter session set geometry_output_format='WKT';

select to_geometry('POINT(1820.12 890.56)');

+--------------------------------------+
| TO_GEOMETRY('POINT(1820.12 890.56)') |
|--------------------------------------|
| POINT(1820.12 890.56)                |
+--------------------------------------+

맨 위로 이동