2

I try to select object from layer by name. I think i found sollution here. First problem i got is that i use GroupLayer. So i made research how to get subLayer from GroupLayer. Sollution is here. Now i have a problem how to get IFeatureLayer if i already have ILayer from where i need to select object.

var mapControl = form.axMapControl2.ActiveView.FocusMap;

var basemapCompositeLayer = mapControl.Layer[0] as ICompositeLayer;
var basemapSubLayer = basemapCompositeLayer.Layer[0];
var featureLayer1 = basemapSubLayer as IFeatureLayer; // always NULL

Or this is because that Layer isn't Featured by default?

8
  • is layer 0 (the first or top layer) a composite layer (group layer)? Commented Jun 3, 2014 at 21:57
  • @MichaelMiles-Stimson thanks for reply! basemapCompositeLayer is Composite Layer ("World Map") and basemapSubLayer is simple layer(" City(points)"). This map i get from ArcGIS Data and Maps, "World Map.mxd" Commented Jun 3, 2014 at 22:02
  • is the layer valid? basemapSubLayer.isValid() edndoc.esri.com/arcobjects/9.2/componenthelp/esriCarto/… that looks like Java, does Java have typeof? In the map world map.mxd is the layer a WMS layer or is the data local? Commented Jun 3, 2014 at 22:05
  • yes, layer is valid. This is c#. Layer is local (this is base map-template from ArcGIS) Commented Jun 3, 2014 at 22:13
  • It doesn't look like c#. So the data is not referring to a WMS service on ESRI base maps... this is odd. Commented Jun 3, 2014 at 22:16

2 Answers 2

2

based on the conversation here is the code:

IMap mapControl = form.axMapControl2.ActiveView.FocusMap;
ICompositeLayer basemapCompositeLayer = (ICompositeLayer) mapControl.Layer[0];
ILayer basemapSubLayer = basemapCompositeLayer.Layer[0];
if (basemapSubLayer.Valid)
{
    if (basemapSubLayer is IFeatureLayer)
    {
        IFeatureLayer featureLayer1 = (IFeatureLayer) basemapSubLayer;
        // do your selection here
    }
    else if (basemapSubLayer is ICompositeLayer)
    {
        ILayer nextDown = (basemapSubLayer as ICompositeLayer).Layer[0];
        if (nextDown is IFeatureLayer)
        {
            IFeatureLayer featureLayer1 = (IFeatureLayer)nextDown;
            // do your selection here
        }
    }
}
0

See this post, you might serve: http://forums.esri.com/Thread.asp?c=159&f=1705&t=263219

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.