7

Does anybody know if there is a way to statistical calculate the similarity of two polygons using QGIS?

I want to know how similar is the polygon (red outline) with the polygon (black outline).

enter image description here

  • similarity measured by what? – pLumo Aug 28 '17 at 7:07
  • I would say, sImilarity measured by how close are the polygon vertices. have tried to develop my own similarity index using intersection and symmetrical difference in QGIS. Unfortunately i havent succeed. I was searching on the web but I havent found a solution. I was thinking, perhaps there is already a tool to assess the shape similarity – nico Aug 28 '17 at 7:09
  • Measuring the closeness of vertices may be quite complicated to achieve. Why not computing the relative area of the symmetrical difference? Seems much easier to me. – ArMoraer Aug 28 '17 at 8:26
  • This paper might give you some hints: Mapcurves: a quantitative method for comparing categorical maps (look at figure 2 to see an example of similarity index). – ArMoraer Aug 28 '17 at 8:35
  • 1
    You could do Hausdorff distance, implemented in PostGIS en.wikipedia.org/wiki/Hausdorff_distance – HeikkiVesanto Aug 28 '17 at 9:47
3

There is a script available at https://github.com/anitagraser/QGIS-Processing-tools/blob/master/1.1/scripts/hausdorff_distance_pairwise.py

It needs to be updated by changing the following line:

from processing.core.VectorWriter import VectorWriter

to

from processing.tools.vector import VectorWriter

Save the script in .qgis2/processing/scripts/hausdorff_distance_pairwise.py

Now when you open QGIS and the Processing Toolbox you can search for 'hausdorff'

Processing scripts in toolbox

Add your two layers to compare

layers for comparison

Open the script and set the options - you need some key fields so the correct features can be compared to each other.

script dialogue box

Once the tool has run the output file has a new field - HAUSDORFF - added to it with the similarity score. Smaller is better.

similarity score results

I found the script worked with polylines rather than polygons and you can use the Vector > Geometry Tools > Polygons to Lines tool to convert.

  • Sweet!!! It works. Now i just have one more question and it is about citation. If i want to cite this work (hausdorff distance formula or script) in a paper. How should I cite? Or should i cite just QGIS – nico Aug 28 '17 at 11:32
  • I'd cite the script repository as well as QGIS and possibly references to the Hausdorff Distance method if it's for an academic paper. But that's just me. – mixedbredie Aug 28 '17 at 11:43
  • 2
    Note that the Hausdorff metric, while easy to compute, might not be a good descriptor for polygon similarity, despite it having an official sciency German name. It merely is the longest possible distance from a point of polygon A to the closest point on polygon B. This means that a single stark outlier (think of a "spike") will result in a huge Hausdorff distance, even if the rest of the polygon is a perfect fit. Be wary of using it blindly/undiscussed in academic papers. – Senshi Aug 30 '17 at 8:13
1

You don't describe your objective clearly, so I assume that you want to use the resulting statistics to compare how well various simplified polygons fit their complex counterparts.

If so, you can create your own metric for that:

  • Sample a very large number of points along the complex polygon's border (the more the better for accuracy. It's a simple calculation, so aim for hundreds of thousands). You can either sample randomly or even-spaced along the border. There's a number of scripts you can use in QGIS itself or plugins for that.
  • Calculate the minimum distance between all points and the other polygon's border. For this to work in QGIS, you might have to convert the polygon to a polyline so you can use the available distance tools (e.g. GRASS v.distance)
  • Using the sum of distances, you can create the metric suitable for your needs. If you want to compare the goodness-of-fit of various simplified polygons, you could form a ratio with a property of the polygon (e.g. area, border length, etc.) . You could also calculate the "average distance" by dividing the summed distance by number of sample points. An easy to understand metric, that should also be easy to visualize and compare.

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.