ArcEngine调用GeoServer中的WMS地图服务

  1. ArcEngine是可以连接ArcIMS、ArcServer及WMS等地图服务的,而开源GeoServeer提供了高效、高质量的WMS地图服务。用瓦片缓存的WMS地图服务作为ArcEngine地图的底图,则大大提高了地图放大、缩小、漫游等地图操作。

下面将步骤记录如下:

  1. 启动PostGIS,导入需要的图层,如新疆行政区划图层Admin等;
  2. 在Udig中配置好该图层的样式(style),并将该样式保存为sld文件:admin.sld;
  3. 启动apache-tomcat,本人用的是Tomcat 7。启动Tomcat的同时也启动了GeoServer,本人的GeoServer的版本是2.0.2;
  4. 在GeoServer中预览刚才导入的图层,其地址为:http://localhost:8080/geoserver/wms?service=WMS&version=1.1.0&request=GetMap&layers=topp:adminbndy&styles=&bbox=73.491,34.333,96.389,49.18&width=512&height=331&srs=EPSG:4326&format=application/openlayers
  5. 在ArcEngine中调用GeoServer的WMS服务,并连接到该图层,代码如下:

     

          private void Connect2WMS()

          {

 

            IPropertySet pPropertyset = new PropertySetClass();

            pPropertyset.SetProperty(“url”, “http://localhost:8080/geoserver/wms?”);

 

            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 == “admin”)

                        {

                            pWmsMapLayer.InsertLayer(layer, 0);

                            layer.Visible = true;

                            break;

                        }

                    }                  

 

                }               

            }

            ILayer pLayer = pWmsMapLayer as ILayer;

            pLayer.Name = pWmsServiceDesc.WMSTitle;

            pLayer.Visible = true;

            this.mapControl.AddLayer(pLayer, 0);           

        }

    }


运行ArcEngine程序,执行该方法,可以看到新疆的WMS地图服务已经加到ArcEngine中了,和在GeoServer中预览的一样。

 

转载自:https://blog.csdn.net/FlexMapServer/article/details/5809667

You may also like...