ST_Aggr_ConvexHull operates on a grouped DataFrame and returns the convex hull of geometries in each group. You can group your DataFrame using DataFrame.groupBy() or with a GROUP BY clause in a SQL statement.
When there are coincident points, the z-value from the first input geometry is used.
To find the convex hull of geometries in each record, use ST_ConvexHull.
It is possible for ST_Aggr_ConvexHull to return a degenerate polygon. A polygon is degenerate when one or more vertices lie on an edge joining two other vertices, or when a side has a length of zero. This most commonly happens when using inputs that are a single point or colinear.
Function | Syntax |
---|---|
Python | aggr |
SQL | ST |
Scala | aggr |
For more details, go to the GeoAnalytics for Microsoft Fabric API reference for aggr_convex_hull.
Examples
from geoanalytics_fabric.sql import functions as ST, Point
data = [
(1, Point(40, 10)),
(1, Point(30, 20)),
(1, Point(20, 10)),
(2, Point(80, 20)),
(2, Point(30, 30)),
(2, Point(60, 50))
]
df = spark.createDataFrame(data, ["id", "point"])
df.groupBy("id")\
.agg(ST.aggr_convex_hull("point").alias("aggr_convexhull"))\
.show(truncate=False)
+---+---------------------------------------------+
|id |aggr_convexhull |
+---+---------------------------------------------+
|1 |{"rings":[[[40,10],[20,10],[30,20],[40,10]]]}|
|2 |{"rings":[[[80,20],[30,30],[60,50],[80,20]]]}|
+---+---------------------------------------------+
Version table
Release | Notes |
---|---|
1.0.0-beta | Python, SQL, and Scala functions introduced |