ST_ConvexHull takes a geometry column and returns a geometry column. The result column represents the convex hull of the input geometries in each record. A convex hull is the smallest geometry having only interior angles measuring less than 180° that encloses each input geometry. For multipoint, linestring, and polygon geometries, the result will be a polygon. For point geometries, the result is a point. The result column will always have the generic geometry type.
Function | Syntax |
---|---|
Python | convex |
SQL | ST |
Scala | convex |
For more details, go to the GeoAnalytics Engine API reference for convex_hull.
This function implements the OpenGIS Simple Features Implementation Specification for SQL 1.2.1.
Python and SQL Examples
from geoanalytics.sql import functions as ST
data = [
("POINT (10 30)",),
("MULTIPOINT (0 0, 5 5, 0 5)", ),
("LINESTRING (15 15, 10 15, 12 2)", ),
("POLYGON ((20 30, 18 28, 22 35, 40 20))", )
]
df = spark.createDataFrame(data, ["wkt"])\
.select(ST.geom_from_text("wkt").alias("geometry"))
df = df.withColumn("convex_hull",ST.convex_hull("geometry"))
ax = df.st.plot("geometry", facecolor="none", edgecolor="red")
df.st.plot("convex_hull", ax=ax, facecolor="none", edgecolor="blue")

Scala Example
import com.esri.geoanalytics.sql.{functions => ST}
case class GeometryRow(wkt: String)
val data = Seq(GeometryRow("POINT (10 30)"),
GeometryRow("MULTIPOINT (0 0, 5 5, 0 5)"),
GeometryRow("LINESTRING (15 15, 10 15, 12 2)"),
GeometryRow("POLYGON ((20 30, 18 28, 22 35, 40 20))"))
val df = spark.createDataFrame(data)
.select(ST.geomFromText($"wkt").alias("geometry"))
.withColumn("convex_hull",ST.convexHull($"geometry"))
df.select("convex_hull").show(truncate = false)
+---------------------------------------------+
|convex_hull |
+---------------------------------------------+
|{"x":10,"y":30} |
|{"rings":[[[0,0],[0,5],[5,5],[0,0]]]} |
|{"rings":[[[15,15],[12,2],[10,15],[15,15]]]} |
|{"rings":[[[18,28],[22,35],[40,20],[18,28]]]}|
+---------------------------------------------+
Version table
Release | Notes |
---|---|
1.0.0 | Python and SQL functions introduced |
1.5.0 | Scala function introduced |