arcgis engine connected WMS, WMTS service and precautions

arcgis engine secondary development need to connect GIS services, arcgis engine provides a similar interface.

arcgis engine connected WMS service:

try
            {
                IPropertySet pPropertyset = new PropertySetClass();
                pPropertyset.SetProperty("url", pURL);//
                IWMSConnectionFactory pWmsFac = new WMSConnectionFactory();
                IWMSConnection pWmsC = pWmsFac.Open(pPropertyset, 0, null);
                IWMSConnectionName pWmsConnectionName = pWmsC.FullName as IWMSConnectionName;

                ILayerFactory pLayerFactory = new EngineWMSMapLayerFactoryClass();
                IGroupLayer pGroupLayer = new GroupLayerClass();
                if (pLayerFactory.get_CanCreate(pWmsConnectionName))
                {
                    IEnumLayer pEnumLayer = pLayerFactory.Create(pWmsConnectionName);
                    pEnumLayer.Reset();
                    ILayer pLayer = pEnumLayer.Next();
                    while (pLayer != null)
                    {
                        if (pLayer is IWMSMapLayer)
                        {
                            pGroupLayer.Name = "服务库";
                            pGroupLayer.Add(pLayer);
                        }
                        pLayer = pEnumLayer.Next();
                    }
                }
                return pGroupLayer as ILayer;
            }
            catch (Exception ex)
            {
                MessageBox.Show("添加失败! " + ex.Message);
                return null;
            }

arcgis engine connected WMTS services:

IPropertySet pPropertyset = new PropertySetClass();
pPropertyset.SetProperty(url, http://t0.tianditu.com/vec_c/wmts);    
IWMTSConnectionFactory pWMTSConnectionfactory = new WMTSConnectionFactory();
IWMTSConnection pWMTSConnection = pWMTSConnectionfactory.Open(pPropertyset, 0, null);
IWMTSLayer pWMTSLayer = new WMTSLayer();
IName pName = pWMTSConnection.FullName;
pWMTSLayer.Connect(pName);
            
axMapControl1.AddLayer(pWMTSLayer as ILayer);
axMapControl1.Refresh();

We give you a small gift is the actual development must have similar needs, such as load wms service to the layer, but wms service will all add to all the layers, the following code is to help you add your own target layers for a filter.

 try { 
            IPropertySet pPropertyset = new PropertySetClass();
            pPropertyset.SetProperty("url", pURL);

            IWMSConnectionName pWmsConnectionName = new WMSConnectionNameClass();

            pWmsConnectionName.ConnectionProperties = pPropertyset;

            ILayerFactory pLayerFactory = new EngineWMSMapLayerFactoryClass();

            IWMSGroupLayer pWmsMapLayer = new WMSMapLayerClass();

            IDataLayer pDataLayer = pWmsMapLayer as IDataLayer;

            pDataLayer.Connect(pWmsConnectionName as IName);

            IWMSServiceDescription pWmsServiceDesc = pWmsMapLayer.WMSServiceDescription;


            for (int i = 0; i < pWmsServiceDesc.LayerDescriptionCount; i++)
            {
                IWMSLayerDescription pWmsLayerDesc = pWmsServiceDesc.get_LayerDescription(i);

                ILayer pNewLayer = null;

                if (pWmsLayerDesc.LayerDescriptionCount == 0)
                {
                    IWMSLayer pWmsLayer = pWmsMapLayer.CreateWMSLayer(pWmsLayerDesc);

                    pNewLayer = pWmsLayer as ILayer;

                }
                else
                {
                    IWMSGroupLayer pWmsGroupLayer = pWmsMapLayer.CreateWMSGroupLayers(pWmsLayerDesc);

                    for (int j = 0; j < pWmsGroupLayer.Count; j++)
                    {
                        ILayer layer = pWmsGroupLayer.get_Layer(j);

                        if (layer.Name == layerName)
                        {
                            pWmsMapLayer.Clear();
                            pWmsMapLayer.InsertLayer(layer, 0);
                            layer.Visible = true;
                            break;
                        }

                    }

                }

            }
            ILayer pLayer = pWmsMapLayer as ILayer;
            pLayer.Name = "UninphoServer Web Map Service";
            pLayer.Visible = true;
            return pLayer;
            }
            catch (Exception ex)
            {
                MessageBox.Show("wms服务链接错误! "+ex.Message);
                return null;
            }

Focus here, if you schedule a program in accordance with the above code, should not be a problem. But sometimes you will encounter a very nasty problem, which will be reported com component issues. As com component issues, I arcgis engine is the most disgusting problem, first of all the problem, if Baidu, then, most of the experience stickers will tell you because parameters of the problem. In fact, true, but the parameter error range is actually very wide, very difficult to locate specific to that.
Gis server connection for this one usually pDataLayer.Connect(pWmsConnectionName as IName);given, in fact very difficult to reason about the lock, side to a seemingly useless really useful way. Which is the case in arcgis map test the connection, your code is passed in url, will first arcgis map error prompt, and you can determine if you pass parameters of the problem.
Well, here today, I hope my article can effectively help to everyone. I deeply understand that this road can not be programmed, just hope my efforts promised if we can bring the dim light, nothing more. Come on! Oh me a lot of support, point a praise Well, hey.

Published 14 original articles · won praise 15 · views 333

Guess you like

Origin blog.csdn.net/weixin_42970847/article/details/103092631