ST_HausdorffDistance

ST_HausdorffDistance takes two geometry columns and returns a double column. The output column represents the Hausdorff distance between the two input geometries.

Hausdorff distance is defined as the greatest distance among all vertices of a given geometry to the closest vertex in the reference geometry. Below is an example that calculates the Hausdorff distance between two lines.

ST_Hausdorff_Distance
Two linestrings (orange and blue). A distance (gray line) is calculated between all the vertex combinations in the two linestrings. The red lines represent the distance of the closest vertices. The Hausdorff distance is the green line which is the greatest distance among all the closest vertices.

The result will be in the same units as the input geometry data. For example, if your input geometries are in a spatial reference that uses meters, the result values will be in meters.

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.

If one of the input geometries has an unknown spatial reference the function will use planar distance calculations.

This function can be used to measure the similarity between two geometries. For more details, go to the core topic for similarity measures.

FunctionSyntax
Pythonhausdorff_distance(geometry1, geometry2)
SQLST_HausdorffDistance(geometry1, geometry2)
ScalahausdorffDistance(geometry1, geometry2)

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

Examples

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

data = [
    ("LINESTRING (10 10, 20 20)", "LINESTRING (10 30, 20 40)"),
    ("LINESTRING (0 20, 10 20)", "LINESTRING (0 80, -10 20)")
]

df = spark.createDataFrame(data, ["line1_wkt", "line2_wkt"]) \
          .withColumn("line1", ST.line_from_text("line1_wkt", 4326)) \
          .withColumn("line2", ST.line_from_text("line2_wkt", 4326))

df.select(ST.hausdorff_distance("line1", "line2").alias("hausdorff_distance")).show()
Result
Use dark colors for code blocksCopy
1
2
3
4
5
6
+------------------+
|hausdorff_distance|
+------------------+
|              20.0|
|              60.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.