ST_Aggr_ConvexHull

ST_Aggr_ConvexHull
Two aggregated groups of points (blue and orange) and the resulting convex hulls.

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.

FunctionSyntax
Pythonaggr_convex_hull(geometry)
SQLST_Aggr_ConvexHull(geometry)
ScalaaggrConvexHull(geometry)

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

Examples

PythonPythonSQLScala
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from geoanalytics.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)
Result
Use dark colors for code blocksCopy
1
2
3
4
5
6
+---+---------------------------------------------+
|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

ReleaseNotes

1.0.0

Python and SQL functions introduced

1.5.0

Scala function introduced

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.