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.
| Function | Syntax |
|---|---|
| Python | as |
| SQL | ST |
| Scala | as |
For more details, go to the GeoAnalytics Engine API reference for as_spark_geom.
Examples
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
root
|-- ST_AsSparkGeom(esri_geom): geometry(4326) (nullable = true)Version table
| Release | Notes |
|---|---|
2.2.0 | Python, SQL, and Scala functions introduced |