jiayuasu opened a new issue, #2721:
URL: https://github.com/apache/sedona/issues/2721

   ### Description
   
   `ST_HausdorffDistance` returns `0.0` when either input geometry is empty. 
The correct behavior (matching PostGIS and shapely/geopandas) is to return 
`null`/`NaN`, since the distance between empty geometries is undefined.
   
   ### Root cause
   
   In [`GeomUtils.java` line 
551](https://github.com/apache/sedona/blob/master/common/src/main/java/org/apache/sedona/common/utils/GeomUtils.java#L551):
   
   ```java
   public static Double getHausdorffDistance(Geometry g1, Geometry g2, double 
densityFrac) {
       if (g1.isEmpty() || g2.isEmpty()) return 0.0;  // should return null/NaN
       DiscreteHausdorffDistance hausdorffDistanceObj = new 
DiscreteHausdorffDistance(g1, g2);
       ...
   }
   ```
   
   ### Steps to reproduce
   
   ```sql
   SELECT ST_HausdorffDistance(ST_GeomFromText('POINT EMPTY'), 
ST_GeomFromText('POINT EMPTY'))
   -- Sedona returns: 0.0
   -- Expected (PostGIS / shapely): null / NaN
   ```
   
   ```python
   import geopandas as gpd
   from shapely.geometry import Point
   
   gpd.GeoSeries([Point()]).hausdorff_distance(gpd.GeoSeries([Point()]))
   # 0    NaN
   ```
   
   ### Suggested fix
   
   Return `null` or `Double.NaN` for empty geometries:
   
   ```java
   public static Double getHausdorffDistance(Geometry g1, Geometry g2, double 
densityFrac) {
       if (g1.isEmpty() || g2.isEmpty()) return Double.NaN;
       ...
   }
   ```
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to