Pular para o conteúdo

Analisa uma entrada e devolve um valor do tipo GEOMETRY.

TRY_TO_GEOMETRY devolve um valor NULL se ocorrer um erro durante a análise.

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>])
Argumentos Descrição
<string> O argumento tem de ser uma expressão de cadeia de caracteres em WKT, EWKT, WKB ou EWKB em formato hexadecimal, ou em formato GeoJSON.
<binary> O argumento tem de ser uma expressão binária em formato WKB ou EWKB.
<variant> O argumento tem de ser um OBJECT JSON em formato GeoJSON.
<srid> O valor inteiro do SRID a utilizar.

Geometry.

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) │
└───────────────────────────────────────────┘