Truecentroid of a geometry object

601
3
05-09-2011 05:55 AM
Highlighted
New Contributor
I am searching for the TRUECENTROID property of a polyline geometry using c#.NET.
The IGpDescribeGeometry interface seems to have it. Does anybody know how to use it??

Roland
Reply
0 Kudos
3 Replies
Highlighted
New Contributor
Has anybody an example, how to use  IGpDescribeGeometry?
Any hints?

Tia

Roland
Reply
0 Kudos
Highlighted
New Contributor
Ok, this solution works for me. Calculating the TRUECENTROID (lenght weighted centroid) of a polyline(c#):

public IPoint get_TrueCentroid(IPolyline pLine)
        {
            IPoint pTrueCentroid = new PointClass();
            double pTC_X = 0;
            double pTC_Y = 0;
            ISegmentCollection pSegs = (ISegmentCollection)pLine;
            for (int k = 0; k <= (pSegs.SegmentCount - 1); k++)
            {
                ISegment seg = pSegs.get_Segment(k);
                double length = seg.Length / 2;
                IPoint pFP = seg.FromPoint;
                IPoint pTP = seg.ToPoint;
                pTC_X = ((pFP.X + pTP.X) * length) + pTC_X;
                pTC_Y = ((pFP.Y + pTP.Y) * length) + pTC_Y;

            }
            pTrueCentroid.X = pTC_X / pLine.Length;
            pTrueCentroid.Y = pTC_Y / pLine.Length;
            return pTrueCentroid;


Roland
Reply
0 Kudos
Highlighted
Occasional Contributor II
What do you mean by the "true centroid", the center of gravity? In that case you could use IGeometry5.CentroidEx(). If you want the midpoint on a polyline (halfway between 'from' and 'to'), use ICurve.QueryPoint(esriSegmentExtension.esriNoExtension, 0.5, true, outPoint).
Reply
0 Kudos