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 am attempting to add a single WMS layer that is part of a WMS service group layer. I am writing code to do this using ArcObjects in C# .Net. So far I have been unsuccessful. I can either only add the whole group layer, or I can add the individual WMS sub-layer but the full group is also still added.

Here is the code I have tried. I have allowed the user to select a layer from a list, and this code is trying to only add that selected layer.

    IWMSGroupLayer wmsMapLayer = new WMSMapLayerClass();
    IWMSConnectionName connName = new WMSConnectionNameClass();

    IPropertySet propSet = new PropertySetClass();
    propSet.SetProperty("URL", "http://www.___________________?");

    connName.ConnectionProperties = propSet;

    IDataLayer dataLayer = (IDataLayer)wmsMapLayer;

    IWMSServiceDescription serviceDesc = wmsMapLayer.WMSServiceDescription;
    IWMSLayerDescription groupDesc = serviceDesc.LayerDescription[0];

    for (int i = 0; i < groupDesc.LayerDescriptionCount - 1; i++)
        IWMSLayerDescription layerDesc = groupDesc.LayerDescription[i];

        if (layerDesc.Title == lstWMSLayers.SelectedItem.ToString())//Checking if this is the selected layer
            ILayer newLayer;
            IWMSLayer newWMSLayer = wmsMapLayer.CreateWMSLayer(layerDesc);
            newLayer = (ILayer)newWMSLayer;
            wmsMapLayer.InsertLayer(newLayer, 0);

            IMxDocument mxDoc = (IMxDocument)ArcMap.Application.Document;
            IActiveView activeView = (IActiveView)mxDoc.FocusMap;

In ArcMap I get the following tree of layers

  • WMS Service Group Layer
    • Selected WMS Layer
    • WMS Group Layer
      • All the layers that are part of the service...

Any suggestions?

share|improve this question
Are you able to add that layer (and that layer only) through the ArcMap user interface? – Petr Krebs May 29 '13 at 19:47
Yes, when I add an individual layer through ArcMap, I get the WMS Service Group Layer, and then only the one WMS layer, nothing else. So it should be possible through ArcObjects too right? – JeremyFon May 30 '13 at 18:20

You need to clear the WMS Service Group Layer before adding the single WMSMapLayer.

wmsMapLayer.InsertLayer(newLayer, 0);

Note that this will remove all group/map layers from the WMS Service Group Layer, so if you're adding more than one, it might be advisable to not call wmsMapLayer.Clear() in the body of your loop. I haven't tested as I'm only adding a single layer, but perhaps instead, loop through groupDesc.LayerDescriptionCount and grab all the layerDesc objects that match your criteria, then Clear() and add the selected WMS layers back in.

share|improve this answer

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.