TheSwamp

Code Red => .NET => Topic started by: autogis on October 04, 2016, 10:12:25 AM

Title: How to get the center of mpolygon in objectarx using C#
Post by: autogis on October 04, 2016, 10:12:25 AM
Does anyone know how to get the center of mpolygon in objectarx using C#?

Code: [Select]
MPolygon mPolygon = new MPolygon();
DBPoint point = mPolygon.getCenter(); // <== does not exist

Thanks
Title: Re: How to get the center of mpolygon in objectarx using C#
Post by: autogis on October 05, 2016, 02:23:47 PM
I could not figure this one out but here is what I ended up using to find a center point.

Code: [Select]
private static Point2d generateCentroid(List<clsPoint> lstPoint)
        {

            double x, y, min_x, min_y, max_x, max_y;
            min_x = lstPoint.Min(p => p.X);
            min_y = lstPoint.Min(p => p.Y);
            max_x = lstPoint.Max(p => p.X);
            max_y = lstPoint.Max(p => p.Y);
            x = min_x + (max_x - min_x) / 2;
            y = min_y + (max_y - min_y) / 2;
            Point2d point = new Point2d(x, y);
            return point;

        }

lstPoint is just a list of the polygon points stored in a class:

Code: [Select]
public class clsPoint
    {
        public double X { get; set; }
        public double Y { get; set; }
    }