2

I am interested in the area of a dynamic NetTopologySuite.Geometries.Polygon that is within a fixed bounding box rectangle(105x68).

It can sometimes break out the of rectangle (which is fine), but I am only interested in the area that is covered by the bounding box.

So basically I want to get as result:

//Polygon is completely inside my rectangle
var FinalArea = Polygon.Area();

// Polygon breaks out of bounding box
var FinalArea I Polygong.Area() - (double)AreaOutsideTheBoundingBox;

How could I achieve this with NTS Topology Suite in C#?

Illustration

ManuKaracho
  • 1,180
  • 1
  • 14
  • 32

1 Answers1

3

To get the area of the polygon inside the rectangle:

poly.Intersection(rect).Area;

To get the area of the polygon outside the rectangle:

poly.Area - poly.Intersection(rect).Area;

To get the area of the rectangle minus the polygon:

rect.Difference(poly).Area;
tval
  • 412
  • 3
  • 17