I'm currently using ArcGIS and I'm trying to create a basic application where I can click on a country and then get back information such as the shape, size, etc.

I've looked at the code snippets and the documentation and up to date this is what I've come up with.

IPoint pt = new PointClass();
pt.X = e.X; 
pt.Y = e.Y;

IGeoFeatureLayer layer = myMapControl.get_Layer(0) as IGeoFeatureLayer;
ESRI.ArcGIS.Geodatabase.IFeatureCursor cursor = GetAllFeaturesFromPointSearchInGeoFeatureLayer(1.0 , IPoint , layer , myMapControl.ActiveView)

So at this point I can click on the map, get the X,Y coords from the mouse - get the base layer from the map control and then get the FeatureCursor. Looking at the cursor info I do see things like CNTRY_NAME but nothing else of use. Am I going about this in the totally wrong direction? I've looked at http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html quite a bit lately in addition to this site, but I'm coming up blank.

3 Answers 3


It may not the fastest way to get the requested feature using the IIdentify-Interface, but it works quite well:

IMxDocument doc = m_application.Document as IMxDocument;
IIdentify2 ident = featLayer as IIdentify2;
int tol = doc.SearchTolerancePixels;

// consruct a small rectangle out of the x,y coord and the document's pixel tolerance
tagRECT r;
r.left = x - tol;
r.top = y - tol;
r.right = x + tol;
r.bottom = y + tol;

// Tranform the device rectange into a geographic rectangle via the display transformation
IEnvelope env = new EnvelopeClass();
int opt = esriDisplayTransformationEnum.esriTransformPosition.GetHashCode()+
app.Display.DisplayTransformation.TransformRect(env, ref r, opt);

// setup the spatial reference on the newly hydrated envelope
env.SpatialReference = doc.FocusMap.SpatialReference;

// identify with the envelope
ident.Scale = m_application.Display.DisplayTransformation.ScaleRatio;
IArray ids = ident.Identify(env, null);

if(ids == null || ids.Count == 0) {
    return null;

IIdentifyObj obj = ids.get_Element(0) as IIdentifyObj;
IRowIdentifyObject row = obj as IRowIdentifyObject;
return row.Row;

m_application is of type IApplication - a reference to your ArcMap instance. And have a look at the example in ArcObjects.

  • Change IIdentify2 to IIdentify and a few small changes and it works. THANKS!
    – ist_lion
    Oct 27, 2010 at 18:13
  • Though not strictly an error, GetHashCode() is not intended to be used for this purposes. Instead, use direct cast to an int, for example (int)esriDisplayTransformationEnum.esriTransformPosition.
    – Petr Krebs
    Oct 28, 2010 at 22:50

Look at the sample: Tabbed feature inspector


You're almost there. You just have to add the following code :

    int countryNameIndex = featureClass.Fields.FindField("CNTRY_NAME");

    IFeature feature;
    while((feature = cursor.NextFeature()) != null)
        object countryName = feature.get_Value(countryNameIndex);

If you don't like the while loop you can add the following extension method :

    public static IEnumerable<IFeature> ToEnumerable(this IFeatureCursor cursor)
        IFeature feat;
        while ((feat = cursor.NextFeature()) != null)
            yield return feat;
        yield break;

And replace the while loop with :

    foreach(var feature in cursor.ToEnumerable())
         // add your code here
  • Where did featureClass come from?
    – ist_lion
    Oct 27, 2010 at 14:48
  • You can get at that by using layer.FeatureClass in your code. See here. Oct 27, 2010 at 15:12
  • I tried the code you suggested; however, it never steps into the cursor.NextFeature. HOWEVER, the countryNameIndex did return a value
    – ist_lion
    Oct 27, 2010 at 15:21
  • That probably means that your cursor didn't have any features in it, i.e. nothing was returned from the query. Are you certain that there should be some features at that location or via that where clause? Oct 27, 2010 at 15:29
  • I would think so. I'm clicking right on top of North America. If I use the pre-defined toolbar control "Identify" it selects North America and flashes briefly when selected.
    – ist_lion
    Oct 27, 2010 at 16:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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