### Author Topic: How to get the center of mpolygon in objectarx using C#  (Read 1126 times)

0 Members and 1 Guest are viewing this topic.

#### autogis

• Mosquito
• Posts: 19 ##### How to get the center of mpolygon in objectarx using C#
« 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

#### autogis

• Mosquito
• Posts: 19 ##### Re: How to get the center of mpolygon in objectarx using C#
« Reply #1 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; }    }`
« Last Edit: October 07, 2016, 04:11:10 PM by autogis »