Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am having problems in ArcObjects. I am struggling to get to the individual (feature-)layers inside a GroupLayer. Does anyone know how to do that ?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

Try this:

public List<ILayer> GetLayers(string groupLayerName)
{

    ICompositeLayer compositeLayer = GetGroupLayer(groupLayerName);
    List<ILayer> layers = new List<ILayer>();

    if (compositeLayer != null)
    {
        for (int j = 0; j < compositeLayer.Count; j++)
        {
            layers.Add(new Layer(compositeLayer.Layer[j]));
        }
    }
    return layers;
}

ICompositeLayer GetGroupLayer(string groupLayerName)
{
     var mapLayers = _map.Layers;
     for (var layer = mapLayers.Next(); layer != null; layer = mapLayers.Next())
     {
            var comLayer = layer as ICompositeLayer;
            var groupLayer = layer as IGroupLayer;
            if ((comLayer != null) && (groupLayer != null) && (layer.Name.Equals(groupLayerName)))
                return groupLayer;
     }
}
share|improve this answer

Cast the group layer to ICompositeLayer which allows you to access the individual sublayers.

share|improve this answer

Your Answer

 
discard

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.