ST_GeomFromText

ST_GeomFromText takes a string column and returns a geometry column. The string column must contain the well-known text (WKT) representation of geometries. You can optionally specify a spatial reference for the result geometry column. The sr parameter value must be a valid SRID or WKT string.

This function should only be used when you don't know the geometry type represented by the input column or when the input column contains more than one geometry type. In other cases, use the function specific to the geometry type of your input data (i.e. ST_PointFromText, ST_LineFromText, ST_MPointFromText, or ST_PolyFromText).

FunctionSyntax
Pythongeom_from_text(wkt,sr=None)
SQLST_GeomFromText(wkt,sr)
ScalageomFromText(wkt,sr)

For more details, go to the GeoAnalytics Engine API reference for geom_from_text.

This function implements the OpenGIS Simple Features Implementation Specification SQL 1.2.1.

Examples

PythonPythonSQLScala
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
from geoanalytics.sql import functions as ST

data = [
    ("POINT (-2533858.73 8107527.81)",),
    ("LINESTRING (-3636954.77 7750916.26, -3168756.90 7966747.98, -3124795.45 7893415.62)", )
]

df = spark.createDataFrame(data, ["wkt"])

df.select(ST.geom_from_text("wkt", sr=8857).alias("geom_from_text")).show(truncate=False)
Result
Use dark colors for code blocksCopy
1
2
3
4
5
6
+---------------------------------------------------------------------------------------+
|geom_from_text                                                                         |
+---------------------------------------------------------------------------------------+
|{"x":-2533858.73,"y":8107527.81}                                                       |
|{"paths":[[[-3636954.77,7750916.26],[-3168756.9,7966747.98],[-3124795.45,7893415.62]]]}|
+---------------------------------------------------------------------------------------+

Version table

ReleaseNotes

1.0.0

Python and SQL functions introduced

1.5.0

Scala function introduced

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.