# ST_Aggr_Intersection

ST_Aggr_Intersection operates on a grouped DataFrame and returns the intersection of geometries in each group. You can group your DataFrame using DataFrame.groupBy() or with a GROUP BY clause in a SQL statement. An empty geometry is returned when no geometries intersect.

When there are coincident points, the first input geometry is used.

To find the intersection of geometries in each record, use ST_Intersection.

FunctionSyntax
Python`aggr_intersection(geometry)`
SQL`ST_Aggr_Intersection(geometry)`

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

### Examples

PythonPythonSQL
Use dark colors for code blocksCopy
``````from geoanalytics.sql import functions as ST, Polygon

data = [
(1, Polygon([[[5,5],[12,5],[12,10],[5,10],[5,5]]])),
(1, Polygon([[[10,8],[14,8],[14,15],[10,15],[10,8]]])),
(2, Polygon([[[6,8],[20,8],[20,20],[6,20],[6,8]]]))
]

df = spark.createDataFrame(data, ["id", "polygon"])

df.groupBy("id")\
.agg(ST.aggr_intersection("polygon").alias("aggr_intersection"))\
.show(truncate=False)
``````
Result
Use dark colors for code blocksCopy
``````+---+--------------------------------------------------+
|id |aggr_intersection                                 |
+---+--------------------------------------------------+
|1  |{"rings":[[[10,8],[10,10],[12,10],[12,8],[10,8]]]}|
|2  |{"rings":[[[6,8],[20,8],[20,20],[6,20],[6,8]]]}   |
+---+--------------------------------------------------+``````

### Version table

ReleaseNotes

1.0.0

Function introduced