TO_GEOMETRY
Introduced or updated: v1.2.431
Parses an input and returns a value of type GEOMETRY.
TRY_TO_GEOMETRY
returns a NULL value if an error occurs during parsing.
Syntax
TO_GEOMETRY(<string>, [<srid>])
TO_GEOMETRY(<binary>, [<srid>])
TO_GEOMETRY(<variant>, [<srid>])
TRY_TO_GEOMETRY(<string>, [<srid>])
TRY_TO_GEOMETRY(<binary>, [<srid>])
TRY_TO_GEOMETRY(<variant>, [<srid>])
Arguments
Arguments | Description |
---|---|
<string> | The argument must be a string expression in WKT, EWKT, WKB or EWKB in hexadecimal format, GeoJSON format. |
<binary> | The argument must be a binary expression in WKB or EWKB format. |
<variant> | The argument must be a JSON OBJECT in GeoJSON format. |
<srid> | The integer value of the SRID to use. |
Return Type
Geometry.
Examples
SELECT
TO_GEOMETRY(
'POINT(1820.12 890.56)'
) AS pipeline_geometry;
┌───────────────────────┐
│ pipeline_geometry │
├───────────────────────┤
│ POINT(1820.12 890.56) │
└───────────────────────┘
SELECT
TO_GEOMETRY(
'0101000020797f000066666666a9cb17411f85ebc19e325641', 4326
) AS pipeline_geometry;
┌───────────────────────────────────────┐
│ pipeline_geometry │
├───────────────────────────────────────┤
│ SRID=4326;POINT(389866.35 5819003.03) │
└───────────────────────────────────────┘
SELECT
TO_GEOMETRY(
FROM_HEX('0101000020797f000066666666a9cb17411f85ebc19e325641'), 4326
) AS pipeline_geometry;
┌───────────────────────────────────────┐
│ pipeline_geometry │
├───────────────────────────────────────┤
│ SRID=4326;POINT(389866.35 5819003.03) │
└───────────────────────────────────────┘
SELECT
TO_GEOMETRY(
'{"coordinates":[[389866,5819003],[390000,5830000]],"type":"LineString"}'
) AS pipeline_geometry;
┌───────────────────────────────────────────┐
│ pipeline_geometry │
├───────────────────────────────────────────┤
│ LINESTRING(389866 5819003,390000 5830000) │
└───────────────────────────────────────────┘
SELECT
TO_GEOMETRY(
PARSE_JSON('{"coordinates":[[389866,5819003],[390000,5830000]],"type":"LineString"}')
) AS pipeline_geometry;
┌───────────────────────────────────────────┐
│ pipeline_geometry │
├───────────────────────────────────────────┤
│ LINESTRING(389866 5819003,390000 5830000) │
└───────────────────────────────────────────┘