ST_Intersection

ST_Intersection
Input geometries (blue and orange) and the resulting intersections (green).

ST_Intersection takes two geometry columns and returns a geometry column. The output column contains the intersection of two input geometry records. You can optionally specify a string value that determines the geometry type of the result. The string can be one of: 'point', 'multipoint', 'linestring', or 'polygon'. If no intersection type is specified, the function will return the same geometry type as the input geometry with the lowest dimension. For example, if you calculate the intersection of a polygon and a linestring the function will return a linestring.

The function will return an empty geometry if the two input geometries do not intersect or there is no intersection that matches the specified intersect type. If the intersection is a single point, the geometry type of the result column will be a multipoint.

To find the intersection of all records in a column or a group use ST_Aggr_Intersection.

FunctionSyntax
Pythonintersection(geometry1, geometry2, intersect_type=None)
SQLST_Intersection(geometry1, geometry2, intersect_type)
Scalaintersection(geometry1, geometry2, intersectType)

For more details, go to the GeoAnalytics for Microsoft Fabric API reference for intersection.

This function implements the OpenGIS Simple Features Implementation Specification for SQL 1.2.1.

Examples

PythonPythonSQLScala
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
from geoanalytics_fabric.sql import functions as ST, Linestring, Polygon

data = [
    (Polygon([[[0,0],[10,10],[20,0]]]), Linestring([[[5,2],[20,20]]])),
    (Polygon([[[0,0],[10,10],[20,0]]]), Linestring([[[30,40],[32,43]]])),
]

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

df.select(ST.intersection("polygon", "linestring").alias("intersection")).show(truncate=False)
Result
Use dark colors for code blocksCopy
1
2
3
4
5
6
+----------------------------------------------------------+
|intersection                                              |
+----------------------------------------------------------+
|{"paths":[[[5,2],[10.909090909090908,9.090909090909092]]]}|
|{"paths":[]}                                              |
+----------------------------------------------------------+

Version table

ReleaseNotes

1.0.0-beta

Python, SQL, and Scala functions introduced

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