ST_PolyFromSparkGeom takes a Spark GEOMETRY column and returns a GeoAnalytics Engine polygon column.
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 | poly |
| SQL | ST |
| Scala | poly |
For more details, go to the GeoAnalytics Engine API reference for poly_from_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"]) \
.select(ST.as_spark_geom(ST.poly_from_text("wkt", sr=4326)).alias("spark_geom"))
df.select(ST.as_text(ST.poly_from_spark_geom("spark_geom")).alias("esri_geom")).show(truncate=False)Result
+-----------------------------------------------------------------------------------------------+
|esri_geom |
+-----------------------------------------------------------------------------------------------+
|POLYGON ((-117.271 34.059, -117.225 33.919, -116.963 33.662, -116.668 33.712, -117.271 34.059))|
+-----------------------------------------------------------------------------------------------+Version table
| Release | Notes |
|---|---|
2.2.0 | Python, SQL, and Scala functions introduced |