ThinkGeo.com    |     Documentation    |     Premium Support

Center points within a polygon shape

I am working on a project where I need to find the center points of polygon shapes (or at least points that are close). In the attached image there are three examples where the red points are the ones I fount using .GetShape.GetCenterPoint and the blue points are what I am striving for. These points were found using a GIS software called Atlas. Two of these points line up well. the problem is with the third where the center point is outside of the polygon it represents. Is there a way to force center points to be within their parent shape?

If not, though it is not shown on the image, the labels for these shapes are close enough for my needs. Is there a way to find the points where labels are drawn?

Hi Tyler,

I think you should means the “visual center”, that’s not a GIS concept and we don’t have an API for it, this code can get a similar point which is in the edge of shape, you can adjust its X or Y to make it contained by the shape.

            PolygonShape p = new PolygonShape();
        PointShape centerPoint = p.GetCenterPoint();
        if (!p.Contains(centerPoint))
        {
            centerPoint = p.GetClosestPointTo(centerPoint, GeographyUnit.Meter);
        }  

If the result is not enough for your target, you can also refer this topic to write your custom logic about this point.

Wish that’s helpful.

Regards,

Ethan