Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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,

share|improve this question
up vote 9 down vote accepted

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).

share|improve this answer
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). – Sasa Ivetic Mar 31 '11 at 16:10
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 posting your answer, you agree to the privacy policy and terms of service.

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