/// <summary> /// Compute the centroid of the polygon. /// </summary> /// <param name="shell">The coordinates of the polygon shell.</param> /// <param name="precisionModel">The precision model.</param> /// <param name="holes">The collection of coordinates representing the polygon holes.</param> /// <returns>The centroid of the polygon.</returns> public static Coordinate ComputeCentroid(IList <Coordinate> shell, IEnumerable <IList <Coordinate> > holes, PrecisionModel precisionModel) { PolygonCentroidAlgorithm algorithm = new PolygonCentroidAlgorithm(shell, holes, precisionModel); algorithm.Compute(); return(algorithm.Result); }
/// <summary> /// Compute the centroid of the polygon. /// </summary> /// <param name="source">The polygon.</param> /// <param name="precisionModel">The precision model.</param> /// <returns>The centroid of the polygon.</returns> public static Coordinate ComputeCentroid(IBasicPolygon source, PrecisionModel precisionModel) { if (source == null) { throw new ArgumentNullException("source", "The source is null."); } if (source.Shell == null || source.Shell.Coordinates == null) { return(Coordinate.Undefined); } PolygonCentroidAlgorithm algorithm = new PolygonCentroidAlgorithm(source.Shell.Coordinates, source.Holes != null ? source.Holes.Select(hole => hole != null ? hole.Coordinates : null) : null, precisionModel); algorithm.Compute(); return(algorithm.Result); }