Need help adding a WMTSLayer from service.

6252
7
11-28-2013 03:13 PM
JulieTeal
New Contributor
Hi guys.

I may be way off base here but I'm trying to add a layer from a WMTS connection. I'm using the .Net SDK (C#).

So far  I can connect to the Server using IWMTSConnection and then create a WMTSLayer with WMTSConnection() but I can only ever use the first WMTSLayer as an ILayer. I can iterate over the whole structure and pull layer descriptions using IWMTSServiceDescription with IWMTSLayerDescription. But Im at a loss creating a connection where I can use a specific LayerName/Identifier.

Is there a way to either specify the LayerName perhaps when creating the IWMTSConnection or creating the WMTSLayer, that will allow me access other WMTSLayers?

Heres a cut down version of what I currently have:

    IWMTSLayer wmtsLayer = new WMTSLayerClass();
    IDataLayer dLayer = new WMTSLayerClass();
   
    IPropertySet propSet = new PropertySetClass();
    propSet.SetProperty("URL", "http://localhost/erdas-iws/ogc/wmts/?Service=WMTS&Request=GetCapabilities");

    IWMTSConnectionFactory wmtsConnFactory = new WMTSConnectionFactoryClass();
    IWMTSConnection wmtsConnection = wmtsConnFactory.Open(propSet, 0, null);

    ESRI.ArcGIS.GISClient.IWMTSServiceDescription wmtsServiceDescription = wmtsConnection as IWMTSServiceDescription;
    wmtsLayer.WMTSConnection(wmtsConnection);
                 
    for (int i = 0; i < wmtsServiceDescription.LayerDescriptionCount; i++)
    {
          IWMTSLayerDescription layerDescription = wmtsServiceDescription.get_LayerDescription(i);
          if (layerDescription.Identifier.Equals(Wmts_Name, StringComparison.InvariantCultureIgnoreCase))
          {
               //We have a match
               //Maybe need something here to open the correct WMTSLayer?
          } 
     }

     if (wmtsLayer != null)
     {
          IMxDocument mxDocument = (IMxDocument)mxApp.Document;
          mxDocument.FocusMap.AddLayer((ILayer)wmtsLayer);
          return true;
     }


Any help on this is greatly appreciate.

Thanks.
0 Kudos
7 Replies
ShamusFuller
New Contributor
It does not seem like it should be rocket surgery to add a WMTS layer into a layer or layer group. Be that as it may, I can find no working c# example or reference to anyone that has successfully accomplished such a feat. Has anyone done this? Can it be done? How? I have successfully displayed a single layer from a WMTS service, but the other layers would be nice to have too. I can't even find a UID for a WMTS layer.

Seems oddly quiet, would appreciate someone who knows speaking up.
0 Kudos
JulieTeal
New Contributor
I guess the lack of response on this means it isn't possible. Seems strange that WMTS is implemented but is not usable.
0 Kudos
JimRaynor
New Contributor

Hi,

I reviewed your code and corrected it like below:

public static ILayer GetWMTSLayer(string url = "http://IP-Address:Port/Service/rest/services/OSM/MapServer/WMTS")

        {

            IWMTSLayer wmtsLayer = new WMTSLayerClass();

  

            IPropertySet propSet = new PropertySetClass();

            propSet.SetProperty("URL", url);

            try

            {

                IWMTSConnectionFactory wmtsConnFactory = new WMTSConnectionFactoryClass();

                IWMTSConnection wmtsConnection = wmtsConnFactory.Open(propSet, 0, null);

                var con = wmtsLayer.Connect(wmtsConnection.FullName);

                //ESRI.ArcGIS.GISClient.IWMTSServiceDescription wmtsServiceDescription = wmtsConnection as IWMTSServiceDescription;

                //string layerName = "GoogleMapsRoad",

                //for (int i = 0; i < wmtsServiceDescription.LayerDescriptionCount; i++)

                //{

                //      IWMTSLayerDescription layerDescription = wmtsServiceDescription.get_LayerDescription(i);

                //      if (layerDescription.Identifier.Equals(layerName, StringComparison.InvariantCultureIgnoreCase))

                //      {

                //           //We have a match

                //           //Maybe need something here to open the correct WMTSLayer?

                //      }

                // }

                if (con)

                    return (ILayer)wmtsLayer;

            }

            catch (COMException ex)

            {

                MessageBox.Show("Couldn't Get the service:" + url);

            }

            catch (Exception ex)

            {

                MessageBox.Show("Couldn't Get the service:" + url);

            }

            return null;

        }

0 Kudos
JulieTeal
New Contributor

Thanks for your reply but I was already at a point where I could connect to a WMTS service and add a layer. The issue here is retrieving anything other than the first layer.

0 Kudos
TomSchuller
Occasional Contributor III

Hy,

I have the same problem:

  I need to get a specific sublayer of a WMTS-mapservice.

  I'm also getting listed all the sublayers in the IWMTSLayerDescription but can't return a single sublayer as ILayer.

  I'm also always getting the first sublayer from the list returned as ILayer.

Any solution or workaround?

Thanks,

Tom

NitinKandpal1
New Contributor

I am facing similar problem. I want to add all the layers in my WMTS service to ArcMap, but I am able to get only one. Has someone got any solution for this.

Thanks

Regards

Nitin Kandpal

0 Kudos
NitinKandpal1
New Contributor

I got solution for adding all layers at ones, as well as a particular layer to ArcMap:

public static void GetWMTSLayer(string url = "http://IP-Address:Port/Service/rest/services/OSM/MapServer/WMTS")

{

     IProperySet propSet= new PropertySetClass();

     propSet.SetProperty("URL",url);

     IWMTSConnectionFactory wmtsConnFactory=new WMTSConnectionFactoryClass();

     IWMTSConnection wmtsConnection=wmtsConnFactory.Open(propSet,0,null);

     IWMTSServiceDescription wmtsServceDescriotion=wmtsConnection as IWMTSServiceDescription ;

     for(int i=0;i< wmtsServceDescriotion.LayerDescriptionCount;i++)

     {

          IWMTSLayerDescription layerDescription=wmtsServceDescriotion.getLayerDescription(i);

          IWMTSLayer wmtsLayer=new WMTSLayerClass();

          IPropertySet propSet_1=new PropertySetClass();

          propSet_1.SetProperty("URL", url);

          propSet_1.SetProperty("LayerName",layerDescription.Identifier);

          

          WMTSConnectionName connectonName= new WMTSConnectionNameClass();

          connectionName.ConnectionProperties=propSet_1;

          wmtsLayer.Connect((IName)connectionName);

            addData(wmtslayer);

     }

}

public static void addData(IWMTSLayer wmtslayer)

{

     IMap pMap=(IMap)((IMxDocument)ArcMap.Application.Document).FocusMap);

     ILayer pLayer=new FeatureLayer();

     

     pLayer=(ILayer)wmtslayer;

     pMap.AddLayer(pLayer);

}

0 Kudos