ST_GeomFromSparkGeom takes a Spark GEOMETRY column and returns a GeoAnalytics Engine geometry column.

This function should only be used when you don't know the types of geometries in 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_PointFromSparkGeom, ST_LineFromSparkGeom, ST_MPointFromSparkGeom, or ST_PolyFromSparkGeom).

This function is supported with Spark 4.2.0 and above. The function can also be used with Spark 4.1.x after setting spark.sql.geospatial.enabled to true in the Spark configuration.

FunctionSyntax
Pythongeom_from_spark_geom(geometry)
SQLST_GeomFromSparkGeom(geometry)
ScalageomFromSparkGeom(geometry)

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

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"]) \
          .select(ST.as_spark_geom(ST.geom_from_text("wkt", sr=3857)).alias("spark_geom"))

df.select(ST.as_text(ST.geom_from_spark_geom("spark_geom")).alias("esri_geom")).show(truncate=False)
Result
Use dark colors for code blocksCopy
1
2
3
4
5
6
+----------------------------------------------------------------------------------+
|esri_geom                                                                         |
+----------------------------------------------------------------------------------+
|POINT (-2533858.73 8107527.81)                                                    |
|LINESTRING (-3636954.77 7750916.26, -3168756.9 7966747.98, -3124795.45 7893415.62)|
+----------------------------------------------------------------------------------+

Version table

ReleaseNotes

2.2.0

Python, SQL, and Scala functions introduced

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