Share via


st_geomfromtext function

Applies to: check marked yes Databricks Runtime 17.1 and above

Important

This feature is in Public Preview.

Parses the WKT description of a geometry and returns the corresponding GEOMETRY value. The SRID value of the returned GEOMETRY value is the value of the sridExpr if specified, or 0 otherwise.

Syntax

st_geomfromtext ( wktExpr[, sridExpr] )

Arguments

  • wktExpr: A STRING value, representing a geometry in WKT format.
  • sridExpr: An optional INTEGER value that is set to be the SRID of the returned GEOMETRY value.

Returns

A value of type GEOMETRY(srid) where srid is the value of sridExpr if sridExpr is a constant (foldable) expression, or GEOMETRY(ANY) otherwise. If sridExpr is omitted the type of the returned value is GEOMETRY(0). The returned value is the geometry corresponding to the input WKT description.

The function returns NULL if any of the inputs is NULL.

Error conditions

  • If the value of wktExpr is an invalid WKT description, the function returns WKT_PARSE_ERROR.
  • If the value of sridExpr is unsupported, the function returns ST_INVALID_SRID_VALUE.

Examples

-- Simple example where we do not specify the output SRID. It defaults to 0.
> SELECT st_srid(st_geomfromtext('POINT Z (1 2 3)'))
  0

-- Simple example where we specify the SRID value for the output.
> SELECT SELECT st_asewkt(st_geomfromtext('POINT Z (1 2 3)', 3857))
  SRID=3857;POINT Z (1 2 3)