Я пытаюсь добавить слой в ArcGIS
, получая данные из базы данных. Здесь я добавил DataGridView
, в котором я получаю данные из базы данных.
private void button3_Click(object sender, EventArgs e)
{
IMxApplication mxApplication = ArcMap.Application.Document as IMxApplication;
//IApplication pApp = (IApplication)mxApplication;
IMxDocument pMxDocument = (IMxDocument)ArcMap.Application.Document;
IMap pMap = pMxDocument.FocusMap;
IPropertySet propSet = new PropertySetClass();
propSet.SetProperty("URL", "......");
IWMSConnectionName connName = new WMSConnectionNameClass();
connName.ConnectionProperties = propSet;
IWMSGroupLayer wmsMapLayer = new WMSMapLayerClass();
IDataLayer dataLayer = (IDataLayer)wmsMapLayer;
dataLayer.Connect((IName)connName);
IWMSServiceDescription serviceDesc = wmsMapLayer.WMSServiceDescription;
for (int k = 0; k < serviceDesc.LayerDescriptionCount - 1; k++)
{
IWMSLayerDescription layerDesc = serviceDesc.get_LayerDescription(k);
ILayer newLayer = null;
if (layerDesc.LayerDescriptionCount == 0)
{
try
{
IWMSLayer newWMSLayer = wmsMapLayer.CreateWMSLayer(layerDesc);
newLayer = (ILayer)newWMSLayer;
}
catch (Exception Ex)
{
System.Diagnostics.Debug.WriteLine(Ex.Message);
}
if (newLayer == null)
{
IWMSGroupLayer grpLayer = wmsMapLayer.CreateWMSGroupLayers(layerDesc);
newLayer = (ILayer)grpLayer;
}
}
else
{
IWMSGroupLayer grpLayer = wmsMapLayer.CreateWMSGroupLayers(layerDesc);
newLayer = (ILayer)grpLayer;
}
newLayer.Visible = true;
wmsMapLayer.InsertLayer(newLayer, 0);
}
if (wmsMapLayer == null || wmsMapLayer.Count == 0)
{
MessageBox.Show("wmsMapLayer is null.");
}
ILayer wmsLayer = (ILayer)wmsMapLayer;
wmsLayer.Visible = true;
if (string.IsNullOrEmpty(layerName))
{
wmsLayer.Name = serviceDesc.WMSTitle;
}
pMap.AddLayer(wmsLayer);
}
From my code I am getting the layer from geo server web map service, I am trying to add layer that I choose from `DataGridView`, after choose one row of `DataGridView`that layer should be shown.