Skip to content

feat(c/sedona-geos): Add ST_HausdorffDistance#1039

Merged
paleolimbot merged 6 commits into
apache:mainfrom
paleolimbot:hausdorff-distance
Jul 9, 2026
Merged

feat(c/sedona-geos): Add ST_HausdorffDistance#1039
paleolimbot merged 6 commits into
apache:mainfrom
paleolimbot:hausdorff-distance

Conversation

@paleolimbot

Copy link
Copy Markdown
Member

Adds ST_HausdorffDistance backed by GEOS

import sedona.db
import pandas as pd

sd = sedona.db.connect()

sd.sql("""
    SELECT ST_HausdorffDistance(
       ST_GeomFromText('LINESTRING (0 0, 1 1 1)'),
       ST_GeomFromText('LINESTRING (0.5 0, 1 0, 1.5 1)')
    ) AS h
""").show()
# ┌────────────────────┐
# │          h         │
# │       float64      │
# ╞════════════════════╡
# │ 0.7071067811865476 │
# └────────────────────┘


densify_values = pd.DataFrame(
    {
        "l": ["LINESTRING (130 0, 0 0, 0 150)"] * 4,
        "r": ["LINESTRING (10 10, 10 150, 130 10)"] * 4,
        "dens": [0.1, 0.25, 0.75, 1.0],
    }
)
sd.create_data_frame(densify_values).to_view("t", overwrite=True)

sd.sql("""
   SELECT dens, ST_HausdorffDistance(
    ST_GeomFromText(l),
    ST_GeomFromText(r),
    dens
   ) as h 
   FROM t
""").show()
# ┌─────────┬────────────────────┐
# │   dens  ┆          h         │
# │ float64 ┆       float64      │
# ╞═════════╪════════════════════╡
# │     0.1 ┆               70.0 │
# ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
# │    0.25 ┆               70.0 │
# ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
# │    0.75 ┆ 14.142135623730951 │
# ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
# │     1.0 ┆ 14.142135623730951 │
# └─────────┴────────────────────┘

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds the SQL scalar function ST_HausdorffDistance (with optional densifyFrac) backed by the GEOS kernel layer, and exposes it through docs and tests.

Changes:

  • Introduces a new GEOS scalar kernel implementation for ST_HausdorffDistance(geom1, geom2) and ST_HausdorffDistance(geom1, geom2, densifyFrac).
  • Registers the new kernels in the GEOS extension and documents the SQL function.
  • Adds Python-level cross-engine (SedonaDB/PostGIS) tests for NULL/EMPTY handling and representative geometry cases.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
python/sedonadb/tests/functions/test_distance.py Adds Python tests for ST_HausdorffDistance (2-arg and densify variants).
docs/reference/sql/st_hausdorffdistance.qmd Adds SQL reference documentation page for ST_HausdorffDistance.
c/sedona-geos/src/st_hausdorffdistance.rs Implements GEOS-backed kernels and Rust unit tests for Hausdorff distance.
c/sedona-geos/src/register.rs Registers the new scalar kernels under st_hausdorffdistance.
c/sedona-geos/src/lib.rs Wires the new module into the GEOS crate.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +39 to +41
The Hausdorff distance is a measure of the similarity between two geometric shapes. This implementation returns the greatest of all distances from a point in one geometry to the closest point in the other geometry.

Returns `NULL` if either geometry is `NULL`. Returns 0 if either geometry is empty.
Comment thread c/sedona-geos/src/st_hausdorffdistance.rs
Comment thread c/sedona-geos/src/st_hausdorffdistance.rs
Comment thread c/sedona-geos/src/st_hausdorffdistance.rs
Comment on lines +284 to +290
// With densify fraction
let result = tester
.invoke_scalar_scalar_scalar("LINESTRING (0 0, 100 0)", "LINESTRING (0 1, 0 1)", 0.5)
.unwrap();
// Without densification this would be 1.0, with densification it should be sqrt(100^2 + 1^2) ≈ 100.005
let result_f64: f64 = result.try_into().unwrap();
assert!(result_f64 > 1.0);
@paleolimbot paleolimbot merged commit 50038ed into apache:main Jul 9, 2026
17 checks passed
@paleolimbot paleolimbot deleted the hausdorff-distance branch July 9, 2026 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants