4

Does any one has better idea how to detect similar polygons or geographies using C# and SQL Server? Currently I am doing it by taking the STSymDifference (detects the points that do not lie in both of instances) of two SqlGeography objects and then calculating the STArea of the resulting SqlGeography object like this:

const double maxAreaDifference = 1000.0;
var diffGeography = geography1.STSymDifference(geography2);
var similar = ((double) diffGeography.STArea()) < maxAreaDifference;

Does anyone has any better algorithm? I know one more solution to detect how much in percent both shapes are similar, but it is not working in my case as the shapes can be so big that this percent difference can be in thousands of square meters. Also I know there is a STEquals method in SqlGeography but it only works if both SqlGeography objects have the same point set.

You can also see the image below of a polygon on a Google map, if I get a similar polygon next time, my algorithm should detect how similar it is.

https://i.stack.imgur.com/jGUr5.png

Diego
  • 18,035
  • 5
  • 62
  • 66
  • So, you're trying to find similarly shaped polygon, or similar as in about the same area? – DaMachk Aug 03 '13 at 19:44
  • 1
    welcome to the wonderful world of shape analysis http://en.wikipedia.org/wiki/Shape_analysis_%28digital_geometry%29 – Spacedman Aug 03 '13 at 19:57
  • @DaMackh Say if there is a shape of Sweden and next we have a similar shape but it has 1 or more extra point init which makes the shape a bit different but actually its the same shape. The algorithm shouldbfind the shapes which are exactly the same or differ by some lat lng points. I hope it will clear your question. – Faheem Ramzan Aug 04 '13 at 06:42
  • @Spacedman I know this world of shape analysis but unfortunetely your link doesn't help much. – Faheem Ramzan Aug 04 '13 at 06:51
  • 1
    So what is more similar - a right angled triangle and an equilateral triangle, or a triangle and a square? – podiluska Aug 27 '13 at 08:11
  • Anyway a moderator can get this over to : http://gis.stackexchange.com/ / – Eric Dec 28 '13 at 16:04
  • 1
    What about something where you add up the perimeter (p), and number of sides (s) and the area (a), then you'd have a decent idea of how closely related they are. Not that precise but what else is there (aside from position) other than size, area, and sides? If you wanted to get really particular you could store the intersections of line segments for the shape and keep track of the angles too. – Eric Jul 22 '14 at 16:29
  • You mention and tag SQL Server, but we have no idea what you're storing in the database. Is it a POINTS table? – Ross Presser Oct 16 '14 at 02:11
  • You say "not working in my case as [...] this percent difference can be in thousands of square meters". Percentages do not have units. Why don't you like `PctDifference = Math.Abs(Area1 - Area2) / Math.Min(Area1, Area2)` ?? – Diego Jun 26 '15 at 22:47

0 Answers0