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.