ST_AsSparkGeom takes a GeoAnalytics Engine geometry column and returns the equivalent Spark GEOMETRY column. Converting a GeoAnalytics Engine geometry column to an Spark SQL geometry column can be useful for interoperability with Spark's built-in geospatial features or export to other systems.

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
Pythonas_spark_geom(geometry)
SQLST_AsSparkGeom(geometry)
ScalaasSparkGeom(geometry)

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

Examples

PythonPythonSQLScala
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10

from geoanalytics.sql import functions as ST

data = [("POLYGON ((-117.271 34.059, -117.225 33.919, -116.963 33.662, -116.668 33.712))",),]

df = spark.createDataFrame(data, ["wkt"]) \
          .withColumn("esri_geom", ST.poly_from_text("wkt", sr=4326)) \
          .select(ST.as_spark_geom("esri_geom"))

df.printSchema()
Result
Use dark colors for code blocksCopy
1
2
root
 |-- ST_AsSparkGeom(esri_geom): geometry(4326) (nullable = true)

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.