Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Applies to:
Databricks SQL
Databricks Runtime 17.1 and above
Important
This feature is in Public Preview.
Note
This feature is not available on Databricks SQL Classic warehouses. To learn more about Databricks SQL warehouses, see SQL warehouse types.
Parses the input description of a geometry and returns the corresponding GEOMETRY value, or NULL if the input description is invalid.
The SRID value of the returned GEOMETRY value depends on the input format.
Syntax
try_to_geometry ( geoRepExpr )
Arguments
geoRepExpr: ABINARYorSTRINGexpression representing a geometry in WKB, WKT, GeoJSON, or Extended WKB (EWKB).
Returns
A value of type GEOMETRY(ANY), corresponding to the input geometry description.
- The function returns
NULLif the input isNULL. - The function returns
NULLif the inputBINARYorSTRINGvalue is an invalid description of a geometry.
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 value is not the description of a geometry.
> SELECT st_astext(try_to_geometry('some string that does not represent a geometry'))
NULL
Related functions
st_asbinaryfunctionst_asewkbfunctionst_asewktfunctionst_asgeojsonfunctionst_astextfunctionst_aswkbfunctionst_aswktfunctionst_geogfromgeojsonfunctionst_geogfromtextfunctionst_geogfromwkbfunctionst_geogfromwktfunctionst_geomfromewkbfunctionst_geomfromgeojsonfunctionst_geomfromtextfunctionst_geomfromwkbfunctionst_geomfromwktfunctionto_geographyfunctionto_geometryfunctiontry_to_geographyfunction