List<Coordinate2D> outerCoordinates = new List<Coordinate2D>();
outerCoordinates.Add(new Coordinate2D(10.0, 10.0));
outerCoordinates.Add(new Coordinate2D(10.0, 20.0));
outerCoordinates.Add(new Coordinate2D(20.0, 20.0));
outerCoordinates.Add(new Coordinate2D(20.0, 10.0));
// define the inner polygon as anti-clockwise
List<Coordinate2D> innerCoordinates = new List<Coordinate2D>();
innerCoordinates.Add(new Coordinate2D(13.0, 13.0));
innerCoordinates.Add(new Coordinate2D(17.0, 13.0));
innerCoordinates.Add(new Coordinate2D(17.0, 17.0));
innerCoordinates.Add(new Coordinate2D(13.0, 17.0));
// Builder constructors need to run on the MCT.
ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
// use the PolygonBuilder as we wish to manipulate the parts
using (PolygonBuilder pb = new PolygonBuilder(outerCoordinates))
{
Polygon donut = pb.ToGeometry();
double area = donut.Area; // area = 100
pb.AddPart(innerCoordinates);
donut = pb.ToGeometry();
area = donut.Area; // area = 84.0
area = GeometryEngine.Instance.Area(donut); // area = 84.0
}
});
// builderEx constructors don't need to run on the MCt
PolygonBuilderEx pbEx = new PolygonBuilderEx(outerCoordinates);
Polygon donutEx = pbEx.ToGeometry() as Polygon;
double areaEx = donutEx.Area; // area = 100
pbEx.AddPart(innerCoordinates);
donutEx = pbEx.ToGeometry() as Polygon;
areaEx = donutEx.Area; // area = 84.0
areaEx = GeometryEngine.Instance.Area(donutEx); // area = 84.0