I currently have an instance of a selected feature class, and I want to be able to get the midpoint X,Y (if its polygon) or the X,Y (if its IPoint) of the feature from the layer, is there some build in GIS method that I can achieve that easily?

Thanks and Regards,


By "midpoint" I'm assuming you're asking about a centroid.

For polygons, you'll want to cast it to an IArea object (see link for example), and then access the Centroid property. For points, you can simply get the X/Y property of the IPoint object. To get the feature, you can use various IFeatureClass methods such as GetFeature to access it using the ObjectID, or Search to find a feature using a Query (spatial or text).

  • Hi Sasa, I tried to use your method, I have my IFeature, before, I casted it to IEnvelope and used minX + width/2, to get the center, when I casted my IFeature.Shape(IPolygon) to IArea, ((IArea)IFeature.Shape).Centroid, it returns me 0s, but my envelope has the minX and minY set properly, any ideas? Thanks
    – Kev84
    Mar 31 '11 at 15:43
  • I can't remember off the top of my head now, but try the QueryCentroid() method instead. Create a new IPoint and pass it to the QueryCentroid() method, then check the X/Y of the point after the call. It should contain the correct values. If not, check the Area property of IArea, see if it gets populated properly (again, it should). Mar 31 '11 at 16:10
  • 2
    Remember that a centroid does not have to fall inside a polygon. IArea has a LabelPoint property that is guaranteed to be within the polygon.
    – mkennedy
    Mar 31 '11 at 18:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.