Sunday, 31 January 2016

arcgis 10.0 - How to add individual layer of WMS group layer to ArcMap?


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;
dataLayer.Connect((IName)connName);

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;
mxDoc.FocusMap.AddLayer((ILayer)wmsMapLayer);
IActiveView activeView = (IActiveView)mxDoc.FocusMap;
activeView.Refresh();
}
}

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?




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...