0

I have been using PostGIS 3.0. The ST_HausdorffDistance() function calculates a symmetric distance between two polygons. However, Hausdorff distance is not a metric since it is the maximum distance between the closest pairs of vertices. Therefore, it depends on the number of vertices each polygon possess. I could not understand how PostGIS made it symmetric.

In addition, when I investigated a toy dataset, where we have two polygon layers (A and B), and their corresponding vertices generated by the Coord. AttribuTable plugin of QGIS (A_vertices, B_vertices), I calculated the Hausdorff distance from A to B as 16.41 and 18.13 for polygons with IDs 111 and 222 respectively. These distances are 31.19 and 25.70 in PostGIS.

select ST_HausdorffDistance(a.geom, b.geom)
from a, b 
where a.id=222 and b.id=222
3

PostGIS implements the Hausdorff metric (as stated in the doc), which is symmetric. It is defined as the maximum of the two Oriented Hausdorff distances between the two geometries.

It's hard to say why you might be seeing different results. If you can provide a pure SQL example that would help to see what's going on.

| improve this answer | |
  • I have written a code that calculates Hausdorff distance. I could not spot the bug. The code and data are here: github.com/banbar/stackoverflow There is no further SQL that I have posted previously. – banbar Oct 15 at 13:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.