public static void AddIdahoWms(string idahoId, string groupLayerName, string token) { IGroupLayer groupLayer = new GroupLayerClass(); groupLayer.Name = groupLayerName; var wmsMapLayer = new WMSMapLayerClass(); // create and configure wms connection name, this is used to store the connection properties IWMSConnectionName pConnName = new WMSConnectionNameClass(); IPropertySet propSet = new PropertySetClass(); // create the idaho wms url var idahoUrl = string.Format( "http://idaho.geobigdata.io/v1/wms/idaho-images/{0}/{1}/mapserv?", idahoId, token); // setup the arcmap connection properties propSet.SetProperty("URL", idahoUrl); pConnName.ConnectionProperties = propSet; //uses the name information to connect to the service IDataLayer dataLayer = wmsMapLayer; try { dataLayer.Connect((IName)pConnName); } catch (Exception e) { Jarvis.Logger.Error("Problems connecting to WMS: " + e.Message); } // get wms service description var serviceDesc = wmsMapLayer.IWMSGroupLayer_WMSServiceDescription; ILayer wmsLayer = null; // add layers for the wms currently there will only be one. for (var i = 0; i <= serviceDesc.LayerDescriptionCount - 1; i++) { var layerDesc = serviceDesc.LayerDescription[i]; var grpLayer = wmsMapLayer.CreateWMSGroupLayers(layerDesc); for (var j = 0; j <= grpLayer.Count - 1; j++) { wmsLayer = wmsMapLayer; wmsMapLayer.Name = idahoId; } } // turn on sub layers, add it to arcmap and move it to top of TOC // SublayerVisibleOn(wmsLayer); groupLayer.Add(wmsLayer); // turn on sub layers, add it to arcmap and move it to top of TOC ArcMap.Document.AddLayer(groupLayer); ArcMap.Document.FocusMap.MoveLayer(groupLayer, 0); }
/// <summary> /// 连接到WMS服务器,载入WMS图层 /// </summary> /// <param name="axMapControl1">axMapControl控件</param> /// <param name="url">WMS服务器地址</param> public static void Connect2WMS(AxMapControl axMapControl1, string url) { #region 初始化环境 IPropertySet pPropertyset = new PropertySetClass(); pPropertyset.SetProperty("url", url); IWMSConnectionName pWMSConnectionName = new WMSConnectionNameClass(); pWMSConnectionName.ConnectionProperties = pPropertyset; ILayerFactory pLayerFactory = new EngineWMSMapLayerFactoryClass();//Provides access to members that control the creation of layers through a factory. IWMSGroupLayer pWmsMapLayer = new WMSMapLayerClass(); IDataLayer pDataLayer = pWmsMapLayer as IDataLayer; pDataLayer.Connect(pWMSConnectionName as IName); IWMSServiceDescription pWmsServiceDesc = pWmsMapLayer.WMSServiceDescription; #endregion #region 获取WMS图层 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; } } } } #endregion #region 收尾工作 ILayer pLayer = pWmsMapLayer as ILayer; pLayer.Name = pWmsServiceDesc.WMSTitle; pLayer.Visible = true; axMapControl1.AddLayer(pLayer, 0); IEnvelope pEnv = axMapControl1.FullExtent; pEnv.Expand(0.8, 0.8, true); axMapControl1.Extent = pEnv; #endregion }
public ILayer GetWmsMapServerLyr(string url, string serviceName) { IPropertySet pPropertyset = new PropertySetClass(); pPropertyset.SetProperty("url", url); IWMSConnectionName pWmsConnectionName = new WMSConnectionNameClass(); pWmsConnectionName.ConnectionProperties = pPropertyset; IWMSConnectionFactory wmsConnFac = new WMSConnectionFactoryClass(); IName nn = wmsConnFac.Open(pPropertyset, 0, null) as IName; 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.ToLower() == serviceName.ToLower()) { pWmsMapLayer.InsertLayer(layer, 0); layer.Visible = true; break; } } } } ILayer pLayer = pWmsMapLayer as ILayer; pLayer.Name = pWmsServiceDesc.WMSTitle; pLayer.Visible = true; return(pLayer); }
/// <summary> /// Add all current idaho ids for a given catalog id to arcmap /// </summary> /// <param name="catalogId">catalog id to be added</param> /// <param name="colorInterp">Kind of color interpretation. PAN, MS</param> private void AddIdahoWms(string catalogId, string colorInterp) { HashSet<string> idahoIds; switch (colorInterp) { case "PAN": idahoIds = IdahoIdRepo.GetPanIdahoIds(catalogId); break; case "MS": idahoIds = IdahoIdRepo.GetMsIdahoIds(catalogId); break; default: idahoIds = null; break; } if (idahoIds == null) return; IGroupLayer groupLayer = new GroupLayerClass(); groupLayer.Name = colorInterp + " " + catalogId; foreach (var id in idahoIds) { var wmsMapLayer = new WMSMapLayerClass(); // create and configure wms connection name, this is used to store the connection properties IWMSConnectionName pConnName = new WMSConnectionNameClass(); IPropertySet propSet = new PropertySetClass(); // create the idaho wms url var idahoUrl = string.Format( "http://idaho.geobigdata.io/v1/wms/idaho-images/{0}/{1}/mapserv?", id, this.token); Jarvis.Logger.Info("Adding WMS Layer to: " + idahoUrl); // setup the arcmap connection properties propSet.SetProperty("URL", idahoUrl); pConnName.ConnectionProperties = propSet; //uses the name information to connect to the service IDataLayer dataLayer = wmsMapLayer; try { dataLayer.Connect((IName)pConnName); } catch (Exception e) { Jarvis.Logger.Error("Problems connecting to WMS: " + e.Message); } // get wms service description var serviceDesc = wmsMapLayer.IWMSGroupLayer_WMSServiceDescription; ILayer wmsLayer = null; // add layers for the wms currently there will only be one. for (var i = 0; i <= serviceDesc.LayerDescriptionCount - 1; i++) { var layerDesc = serviceDesc.LayerDescription[i]; var grpLayer = wmsMapLayer.CreateWMSGroupLayers(layerDesc); for (var j = 0; j <= grpLayer.Count - 1; j++) { wmsLayer = wmsMapLayer; wmsMapLayer.Name = id; } } // turn on sub layers, add it to arcmap and move it to top of TOC SublayerVisibleOn(wmsLayer); groupLayer.Add(wmsLayer); } // turn on sub layers, add it to arcmap and move it to top of TOC ArcMap.Document.AddLayer(groupLayer); ArcMap.Document.FocusMap.MoveLayer(groupLayer, 0); }
public static void AddIdahoWms(string idahoId, string groupLayerName, string token) { IGroupLayer groupLayer = new GroupLayerClass(); groupLayer.Name = groupLayerName; var wmsMapLayer = new WMSMapLayerClass(); // create and configure wms connection name, this is used to store the connection properties IWMSConnectionName pConnName = new WMSConnectionNameClass(); IPropertySet propSet = new PropertySetClass(); // create the idaho wms url var idahoUrl = string.Format( "http://idaho.geobigdata.io/v1/wms/idaho-images/{0}/{1}/mapserv?", idahoId, token); // setup the arcmap connection properties propSet.SetProperty("URL", idahoUrl); pConnName.ConnectionProperties = propSet; //uses the name information to connect to the service IDataLayer dataLayer = wmsMapLayer; try { dataLayer.Connect((IName)pConnName); } catch (Exception e) { Jarvis.Logger.Error("Problems connecting to WMS: " + e.Message); } // get wms service description var serviceDesc = wmsMapLayer.IWMSGroupLayer_WMSServiceDescription; ILayer wmsLayer = null; // add layers for the wms currently there will only be one. for (var i = 0; i <= serviceDesc.LayerDescriptionCount - 1; i++) { var layerDesc = serviceDesc.LayerDescription[i]; var grpLayer = wmsMapLayer.CreateWMSGroupLayers(layerDesc); for (var j = 0; j <= grpLayer.Count - 1; j++) { wmsLayer = wmsMapLayer; wmsMapLayer.Name = idahoId; } } // turn on sub layers, add it to arcmap and move it to top of TOC // SublayerVisibleOn(wmsLayer); groupLayer.Add(wmsLayer); // turn on sub layers, add it to arcmap and move it to top of TOC ArcMap.Document.AddLayer(groupLayer); ArcMap.Document.FocusMap.MoveLayer(groupLayer, 0); }
public static ILayer getWMSLayerByName(string WMSurl, string layerName) { IPropertySet propSet = new PropertySetClass(); IWMSConnectionName connName = new WMSConnectionNameClass(); IWMSGroupLayer wmsMapLayer = new WMSMapLayerClass(); IDataLayer dataLayer = (IDataLayer)wmsMapLayer; IWMSServiceDescription serviceDesc; ILayer qrylyr; ILayer wmsLyr; //connect to url propSet.SetProperty("URL", WMSurl); connName.ConnectionProperties = propSet; dataLayer.Connect((IName)connName); //get service description serviceDesc = wmsMapLayer.WMSServiceDescription; //loop through layers List<IWMSLayerDescription> lyrs = listWMSlayers(serviceDesc); //query layers List<IWMSLayerDescription> qry = ( from IWMSLayerDescription q in lyrs where q.Name == layerName select q).ToList<IWMSLayerDescription>() ; //nothing found if ( qry.Count == 0 ) return null; //else IWMSLayerDescription layerDesc = qry[0]; //clear allready loaded contents wmsMapLayer.Clear(); if (layerDesc.LayerDescriptionCount == 0) { qrylyr = (ILayer)wmsMapLayer.CreateWMSLayer(layerDesc); wmsMapLayer.InsertLayer(qrylyr, 0); } else { qrylyr = (ILayer)wmsMapLayer.CreateWMSGroupLayers(layerDesc); wmsMapLayer.InsertLayer(qrylyr, 0); } makeCompositeLayersVisibile(qrylyr); wmsMapLayer.Expanded = true; ((IWMSMapLayer)wmsMapLayer).BackgroundColor = new RgbColor() { NullColor = true }; wmsLyr = (ILayer)wmsMapLayer; wmsLyr.Name = serviceDesc.WMSTitle; wmsLyr.Visible = true; return wmsLyr; }