Return Value
A Polygon.
// Use a builderEx convenience method or use a builderEx constructor. MapPoint pt1 = MapPointBuilderEx.CreateMapPoint(1.0, 1.0); MapPoint pt2 = MapPointBuilderEx.CreateMapPoint(1.0, 2.0); MapPoint pt3 = MapPointBuilderEx.CreateMapPoint(2.0, 2.0); MapPoint pt4 = MapPointBuilderEx.CreateMapPoint(2.0, 1.0); List<MapPoint> list = new List<MapPoint>() { pt1, pt2, pt3, pt4 }; Polygon polygon = PolygonBuilderEx.CreatePolygon(list, SpatialReferences.WGS84); // polygon.HasZ will be false - it is determined by the HasZ flag of the points in the list // or specifically use AttributeFlags.NoAttributes polygon = PolygonBuilderEx.CreatePolygon(list, AttributeFlags.None); // use AttributeFlags.None as we have 2D points PolygonBuilderEx polygonBuilder = new PolygonBuilderEx(list, AttributeFlags.None); polygonBuilder.SpatialReference = SpatialReferences.WGS84; polygon = polygonBuilder.ToGeometry();
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)); 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
Target Platforms: Windows 11, Windows 10