ArcGIS Pro 3.4 API Reference Guide
ArcGIS.Core.Geometry Namespace / IGeometryEngine Interface / Centroid Method
The input geometry.
Example

In This Topic
    Centroid Method (IGeometryEngine)
    In This Topic
    Gets the centroid (center of gravity) of the geometry.
    Syntax
    MapPoint Centroid( 
       Geometry geometry
    )
    Function Centroid( _
       ByVal geometry As Geometry _
    ) As MapPoint

    Parameters

    geometry
    The input geometry.

    Return Value

    Returns the centroid of the geometry.
    Exceptions
    ExceptionDescription
    Geometry is null or empty.
    The method is not implemented for GeometryBag.
    Remarks
    If the geometry is a MapPoint, then the centroid returned is the same as the source; including Z and M-values (if any exist on the source geometry). The centroid of any other geometry type is a point with HasZ = false, HasM = false.
    Example
    Find the centroid of geometries
    // simple polygon
    List<Coordinate2D> list2D = new List<Coordinate2D>();
    list2D.Add(new Coordinate2D(0, 0));
    list2D.Add(new Coordinate2D(0, 2));
    list2D.Add(new Coordinate2D(2, 2));
    list2D.Add(new Coordinate2D(2, 0));
    
    Polygon polygon = PolygonBuilderEx.CreatePolygon(list2D, SpatialReferences.WGS84);
    
    // verify it is simple
    bool isSimple = GeometryEngine.Instance.IsSimpleAsFeature(polygon);
    // find the centroid
    MapPoint centroid = GeometryEngine.Instance.Centroid(polygon);
    // centroid.X = 1
    // centroid.Y = 1
    
    // map Point
    MapPoint pt1 = MapPointBuilderEx.CreateMapPoint(1, 2, 3, 4, SpatialReferences.WGS84);
    MapPoint pt2 = MapPointBuilderEx.CreateMapPoint(5, 2, double.NaN, 7);
    
    // pt1.HasZ = true
    // pt1.HasM = true
    centroid = GeometryEngine.Instance.Centroid(pt1);
    // centroid.HasZ = true
    // centroid.HasM = true
    // pt1.IsEqual(centroid) = true
    
    // multipoint
    List<MapPoint> list = new List<MapPoint>() { pt1, pt2 };
    Multipoint multipoint = MultipointBuilderEx.CreateMultipoint(list);
    // multipoint.HasZ = true
    // multipoint.HasM = true
    
    centroid = GeometryEngine.Instance.Centroid(multipoint);
    // centroid.X = 3
    // centroid.Y = 2
    // centroid.HasZ = false
    // centroid.HasM = false
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also