try_to_geometry Função

Aplica-se a:check marked yes Databricks SQL check marked yes Databricks Runtime 17.1 e superior

Observação

Esse recurso não está disponível nos armazéns Databricks SQL Classic. Para saber mais sobre os armazéns SQL do Databricks, consulte Tipos de armazém SQL.

Analisa a descrição de entrada de uma geometria e retorna o valor correspondente GEOMETRY , ou NULL se a descrição de entrada for inválida. O valor SRID do valor retornado GEOMETRY depende do formato de entrada.

Syntax

try_to_geometry ( geoRepExpr )

Arguments

Returns

Um valor do tipo GEOMETRY(ANY), correspondente à descrição da geometria de entrada.

  • A função retorna NULL se a entrada for NULL.
  • A função retorna NULL se a entrada BINARY ou STRING valor for uma descrição inválida de uma geometria.

Examples

-- Input geometry is in WKT format.
> SELECT st_asgeojson(try_to_geometry('POINT Z (3 4 5)'));
  {"type":"Point","coordinates":[3,4,5]}

-- Input geometry is in GeoJSON format.
> SELECT st_astext(try_to_geometry('{"type":"Point","coordinates":[3,4,5]}'));
  POINT Z (3 4 5)

-- Input geometry is in WKB format.
> SELECT st_astext(try_to_geometry(X'0101000060110f0000000000000000084000000000000010400000000000001440'));
  POINT M (3 4 5)

-- Input geometry is in EWKB format.
> SELECT st_asewkt(try_to_geometry(X'01010000E0110F0000000000000000084000000000000010400000000000001440000000000000F0BF'));
  SRID=3857;POINT ZM (3 4 5 -1)

-- Input geometry is in EWKT format.
> SELECT concat_ws(';', st_srid(g)::STRING, st_asgeojson(g)) FROM (SELECT try_to_geometry('SRID=3857;POINT Z (3 4 5)') AS g);
  3857;{"type":"Point","coordinates":[3,4,5]}

-- Input value is not the description of a geometry.
> SELECT st_astext(try_to_geometry('some string that does not represent a geometry'));
  NULL