Hello.
First, thank you for your effort in creating NetTopologySuite. We have used it for some time, and it looks very sturdy and fits the bill very much for us.
I have run into somewhat of a snag, though. We are looking at farmers field polygons, and we have some polygons representing various legislation based no-go zones.
In order to correctly calculate areas for the field polygons, we subtract the areas of the no-go zones from the field polygons. Locally, the no-go zones are represented as only the zone area that overlaps the field, which some times can be very small areas.
When we calculate the area to subtract, we have to remove areas of a specific no-go zone that has already been covered by another no-go zone. From time to time, this work ends us with very small multipolygons as a remainder. Some times these remains wreak havoc with the calculations, thus ending with exceptions being thrown.
I have created an example (Accompanying .zip file), built on version 1.14 of NetTopologySuite. My problem were found in a larger application, using NTS version 1.7
The basic code is like this:
1 static void Main(string[] args)
2 {
3 var pol1String= "MULTIPOLYGON (((636192.59787309519 6154321.699591
4 var pol2String = "MULTIPOLYGON (((636167.79101204267 6154298.27038
5 var polygon1 = (MultiPolygon) new WKTReader().Read(pol1String);
6 var polygon2 = (MultiPolygon) new WKTReader().Read(pol2String);
7 var result = polygon1.Difference(polygon2);
8 Console.WriteLine(result.Area);
9 Console.ReadKey();
10 }
11 }
When I go and find the difference in line 7, the program throws an error. The error stems from one of the polygons in multipolygon polygon1. Asking the polygon if it is valid yields true.
I have looked at the offending polygon, and the sides are VERY close to each others, thus yielding very small areas to consider.
Can you confirm whether or not the problem is my polygon (and suggest ways to better the polygon without hurting the area of it)?
Can you suggest other ways to allow the program to do the correct calculation?
If none of the above: Is this a bug in NTS?
MS SQL server geometry can do the above calculations with no errors.
Best regards,
Keld Laursen