ST_Difference

ST_Difference
Input geometry 1 polygons (blue) and geometry 2 polygon (orange) and the resulting erased polygons.

ST_Difference takes two geometry columns and returns a geometry column. The result geometries represent the parts of the first geometry that do not intersect the second geometry. The result column geometry type will be that of the first geometry. If the first geometry is completely contained in the second geometry, then null geometry is returned.

If the two geometry columns are in different spatial references, the function will automatically transform the second geometry into the spatial reference of the first.

FunctionSyntax
Pythondifference(geometry1, geometry2)
SQLST_Difference(geometry1, geometry2)
Scaladifference(geometry1, geometry2)

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

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
from geoanalytics_fabric.sql import functions as ST, MultiPoint

data = [
    (MultiPoint([[30,10],[10,30],[20,0]]), MultiPoint([[30,10],[10,30]]))
]

df = spark.createDataFrame(data, ["mpoint1", "mpoint2"])

df.select(ST.difference("mpoint1", "mpoint2").alias("difference")).show()
Result
Use dark colors for code blocksCopy
1
2
3
4
5
+-------------------+
|         difference|
+-------------------+
|{"points":[[20,0]]}|
+-------------------+

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.