How to find the center of a complex shaped feature.

443
3
Jump to solution
03-10-2014 12:13 PM
RickeyTom
New Contributor II
I have a feature with the shape as shown below.

[ATTACH=CONFIG]32089[/ATTACH]

I want to draw an image at the center of this feature.

I was using a very simple algorithm to determine the center of the feature.
Clearly this does not work for all shapes (the icon is painted on the hypotenuse of the triangle)

My algorithm will likely fail for round objects to.

Is there a common way to get the center of a feature.

Thanks
0 Kudos
1 Solution

Accepted Solutions
RickeyTom
New Contributor II
Does the Centroid property off the IArea interface give you a more accurate center?

Envelope, GeoEllipse, GeoPolygon, Multipatch, Polygon, and Ring are all geometry types that implement IArea.




I saw something about this in the forums, and I will pursue that.
My current challenge is to determine, how to get an IArea from an IEnvelop (which is associated with an IFeature)

Thanks

View solution in original post

0 Kudos
3 Replies
ErinBrimhall
Occasional Contributor II
Does the Centroid property off the IArea interface give you a more accurate center?

Envelope, GeoEllipse, GeoPolygon, Multipatch, Polygon, and Ring are all geometry types that implement IArea.
0 Kudos
RickeyTom
New Contributor II
Does the Centroid property off the IArea interface give you a more accurate center?

Envelope, GeoEllipse, GeoPolygon, Multipatch, Polygon, and Ring are all geometry types that implement IArea.




I saw something about this in the forums, and I will pursue that.
My current challenge is to determine, how to get an IArea from an IEnvelop (which is associated with an IFeature)

Thanks
0 Kudos
ErinBrimhall
Occasional Contributor II
You can simply cast the IEnvelope object as an IArea, but keep in mind that the Envelope is the smallest rectangle that the geometry can fit inside.  So the centroid of the Envelope will still resemble the point drawn in your original post's screenshot.

You might want to try something like the method below:


private IPoint GetCentroid(IFeature feature)
{
    IArea area = feature.Shape as IArea;
    if (area == null)
        return null; // Or throw an exception here, or handle other Geometry types that don't implement IArea, etc.

    return area.Centroid;
}

0 Kudos