[GIS] Get Coordinates of selected item on map using ArcGIS Engine

arcgis-enginearcobjectscoordinatesgetfeatureinfo

I have IFeatureSelection. Then select from it items by QueryFilter.
How can i get coordinates of selected item? (If there are more then 1 object, then select first)?

Selected item is Point in Attribute Table.
I am using C# to write code.


Using samples and Links from @artwork21 and @GISKid i think that i can get coordinates of selected item using this code:

var fClass = featureLayer.FeatureClass;
var fCursor = fClass.Update(null, false);
var aFeature = fCursor.NextFeature();
var tPoint = aFeature.Shape as IPoint;
// then i get Coordinates from tPoint.

But i get new problem – method Update isn't implemented. Have SomeBody any advices?
Thanks.

Best Answer

If you're using FeatureSelection, either from the map or from the feature layer it impements IEnumFeature... no need to search/update at all.

// IMap.FeatureSelection implements IEnumFeature
IEnumFeature pFsel = (IEnumFeature) map.FeatureSelection;
pFsel.Reset(); // make sure it starts from the first feature
IFeature pFeat = pFsel.Next();
do
{
    ESRI.ArcGIS.Geometry.IGeometry pGeom = pFeat.ShapeCopy;
    if (pGeom.GeometryType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint)
    {
        ESRI.ArcGIS.Geometry.IPoint pPnt = (ESRI.ArcGIS.Geometry.IPoint)pGeom;
        double x, y;
        pPnt.QueryCoords(out x,out y); // use the coordinates from here
    }
    pFeat = pFsel.Next();
} while (pFeat != null);