public frmBuffer(IMap _pMap) { InitializeComponent(); //load all the feature layers in the map to the layers combo UID uid = new UIDClass(); uid.Value = "{40A9E885-5533-11d0-98BE-00805F7CED21}"; pMap = _pMap; layers = pMap.get_Layers(uid, true); layers.Reset(); ILayer layer = null; while ((layer = layers.Next()) != null) { cboLayers.Items.Add(layer.Name); } //select the first layer if (cboLayers.Items.Count > 0) cboLayers.SelectedIndex = 0; string tempDir = System.IO.Path.GetTempPath(); txtOutputPath.Text = System.IO.Path.Combine(tempDir, ((string)cboLayers.SelectedItem + "_buffer.shp")); //set the default units of the buffer int units = Convert.ToInt32(pMap.MapUnits); cboUnits.SelectedIndex = units; }
private void populateComboBox() { if (mp != null) { IEnumLayer rstLyrs = vUtil.getActiveViewLayers(viewUtility.esriIFeatureLayer); ILayer lyr = rstLyrs.Next(); while (lyr != null) { string lyrNm = lyr.Name; IFeatureLayer ftrLyr = (IFeatureLayer)lyr; IFeatureClass ftrCls = ftrLyr.FeatureClass; if (!ftrDic.ContainsKey(lyrNm)) { ftrDic.Add(lyrNm, ftrCls); cmbSampleFeatureClass.Items.Add(lyrNm); } lyr = rstLyrs.Next(); } } }
public static ILayer GetFeatureLayer(ref IBasicMap ibasicMap_0, ref string string_0) { ILayer result; if (ibasicMap_0.LayerCount > 0) { IEnumLayer enumLayer = ibasicMap_0.get_Layers(null, true); enumLayer.Reset(); for (ILayer layer = enumLayer.Next(); layer != null; layer = enumLayer.Next()) { if (layer.Name == string_0 && layer is IFeatureLayer && layer.Valid) { result = layer; return(result); } } } result = null; return(result); }
/// <summary> /// This function will search the map for a service location and then return it /// </summary> /// <param name="map">the map</param> /// <returns>the service location layer</returns> public static ILayer ReturnServiceLocationLayerByUtility(IMap map) { IEnumLayer enumLayer = map.get_Layers(null, true); ILayer layer = enumLayer.Next(); while (layer != null) { if (IsValidGisLayer(layer) && layer is IGeoFeatureLayer) { string sName = ((IDataset)layer).BrowseName; if (sName == "Service") { return(layer); } } layer = enumLayer.Next(); } return(null); }
private void SpatialExtentQuery_Load(object sender, EventArgs e) { if (m_hookHelper == null || null == m_hookHelper.Hook || 0 == m_hookHelper.FocusMap.LayerCount) { return; } IEnumLayer layers = GetLayers(); if (layers == null) { return; } layers.Reset(); ILayer layer = null; while ((layer = layers.Next()) != null) { chklstLayers.Items.Add(layer.Name, false); } }
private void cmbDEMlayer_SelectedIndexChanged(object sender, EventArgs e) { //初始化图层列表 IEnumLayer pEnumLayer = pMapControl.Map.get_Layers(null, true); pEnumLayer.Reset(); ILayer pLayer = null; while ((pLayer = pEnumLayer.Next()) != null) { if (pLayer is IRasterLayer) { if (pLayer.Name == cmbDEMlayer.SelectedItem.ToString()) { IRasterLayer pRasterLayer = pLayer as IRasterLayer; pRasterDem = pRasterLayer.Raster; } } } }
private IFeatureLayer GetFeatureLayer(string layerName) { //get the layers from the maps IEnumLayer layers = GetLayers(); layers.Reset(); ILayer layer; while ((layer = layers.Next()) != null) { if (layer.Name == layerName) { return(layer as IFeatureLayer); } } return(null); }
private List <IDataset> GetAllDataset(IMap pMap) { List <IDataset> list = new List <IDataset>(); UID uid = new UIDClass { Value = "{6CA416B1-E160-11D2-9F4E-00C04F6BC78E}" }; IEnumLayer layer = pMap.get_Layers(uid, true); layer.Reset(); for (ILayer layer2 = layer.Next(); layer2 != null; layer2 = layer.Next()) { IFeatureLayer layer3 = layer2 as IFeatureLayer; if ((layer3 != null) && (layer3.FeatureClass != null)) { list.Add(layer3.FeatureClass as IDataset); } } return(list); }
/// <summary> /// 刷新图层列表 /// </summary> /// <returns></returns> private List <string> RefreshLayers() { List <string> list = new List <string>(); IEnumLayer layers = Utils.getFeatureLayers(mMap); if (layers == null || layers.Next() == null) { return(list); } ILayer layer = null; layers.Reset(); //将游标归位 //遍历获取到的矢量图层,并添加到下拉列表中 while ((layer = layers.Next()) != null) { // ToolStripMenuItem menuItem = new ToolStripMenuItem(layer.Name); list.Add(layer.Name); } return(list); }
/// <summary> /// 作用:根据图层名称获取IFeatureLayer /// 作者:汪建龙 /// 编写时间:2016年12月22日19:37:25 /// </summary> /// <param name="map"></param> /// <param name="layerName"></param> /// <returns></returns> public static IFeatureLayer GetFeatureLayerByLayerName(this IMap map, string layerName) { IFeatureLayer currentfeatureLayer = null; if (map != null) { IEnumLayer layers = map.get_Layers(null, true); ILayer layer = layers.Next(); while (layer != null) { IFeatureLayer featureLayer = layer as IFeatureLayer; if (featureLayer != null && featureLayer.Valid && featureLayer.FeatureClass != null && featureLayer.Name == layerName) { currentfeatureLayer = featureLayer; break; } } } return(currentfeatureLayer); }
private ILayer method_1(string string_1) { IFileName name = new FileNameClass { Path = string_1 }; ILayerFactoryHelper helper = new LayerFactoryHelperClass(); try { IEnumLayer layer = helper.CreateLayersFromName(name as IName); layer.Reset(); return(layer.Next()); } catch (Exception exception) { Logger.Current.Error("", exception, ""); } return(null); }
//Custom private IGeoFeatureLayer GetLayerByName(string LayerName) { UID uid = new UID(); uid.Value = "{E156D7E5-22AF-11D3-9f99-00C04F6BC78E}"; IEnumLayer allFLayers = axMapControl1.ActiveView.FocusMap.get_Layers(uid, true); //loop until LayerName is found ILayer layer; layer = allFLayers.Next(); while (layer != null) { if (layer.Name.Equals(LayerName)) { return(layer as IGeoFeatureLayer); } layer = allFLayers.Next(); } return(null); }
private IFeatureLayer GetFeatureLayer(string layerName) { if (GetLayers() == null) { return(null); } IEnumLayer layers = GetLayers(); layers.Reset(); ILayer layer = null; while ((layer = layers.Next()) != null) { if (layer.Name == layerName) { return(layer as IFeatureLayer); } } return(null); }
private void CbxLayersAddItems() { if (GetLayers() == null) { return; } IEnumLayer layers = GetLayers(); layers.Reset(); ILayer layer = layers.Next(); while (layer != null) { if (layer is IFeatureLayer) { cbxLayers2Symbolize.Items.Add(layer.Name); } layer = layers.Next(); } }
private void CboAddItems(ComboBox cbo) { IEnumLayer layers = GetLayers(); if (layers == null) { return; } layers.Reset(); ILayer layer = layers.Next(); while (layer != null) { if (layer is IFeatureLayer) { cbo.Items.Add(layer.Name); } layer = layers.Next(); } }
private void populateComboBox() { if (mp != null) { IEnumLayer rstLyrs = vUtil.getActiveViewLayers(viewUtility.esriIRasterLayer); ILayer lyr = rstLyrs.Next(); while (lyr != null) { string lyrNm = lyr.Name; IRasterLayer rstLyr = (IRasterLayer)lyr; IRaster rst = rsUtil.createRaster(((IRaster2)rstLyr.Raster).RasterDataset); if (!rstDic.ContainsKey(lyrNm)) { rstDic.Add(lyrNm, rst); cmbInRaster1.Items.Add(lyrNm); } lyr = rstLyrs.Next(); } } }
protected override void OnUpdate() { m_pMxDoc = (IMxDocument)ArcMap.Application.Document; m_pMap = m_pMxDoc.FocusMap; //** If a brand new data frame, reading Layers property will generate an error if (m_pMap.LayerCount > 0) { m_pLayers = m_pMap.Layers; m_pLayers.Reset(); m_pLoopLayer = m_pLayers.Next(); m_pOrthoIndexLayer = null; //** Loop through all layers while (!(m_pLoopLayer == null)) { if (m_pLoopLayer.Name == "orth_idx") { //** Ortho index found. Set the ortho var, enable the tool and exit the loop m_pOrthoIndexLayer = (IFeatureLayer)m_pLoopLayer; Enabled = true; break; } else { //** STATES not found yet. Move to next layer m_pLoopLayer = m_pLayers.Next(); } } } else { m_pOrthoIndexLayer = null; } if (m_pOrthoIndexLayer == null) { //** Ortho Index layer must not be in data frame, disable the tool Enabled = false; } }
//窗口启动程序 private void Buffer_Load(object sender, EventArgs e) { AxMapControl axMapControl1 = new AxMapControl(); //m_hookHelper.Hook = axMapControl1.Object; if (null == m_hookHelper || null == m_hookHelper.Hook || 0 == m_hookHelper.FocusMap.LayerCount) { return; } //load all the feature layers in the map to the layers combo IEnumLayer layers = GetLayers(); layers.Reset(); ILayer layer = null; while ((layer = layers.Next()) != null) { cboLayers.Items.Add(layer.Name); } //select the first layer if (cboLayers.Items.Count > 0) { cboLayers.SelectedIndex = 0; } // string tempDir = System.IO.Path.GetTempPath(); string tempDir = SystemSet.Base_Map + "\\处理数据库\\实验数据"; txtOutputPath.Text = System.IO.Path.Combine(tempDir, ((string)cboLayers.SelectedItem + "_buffer.shp")); //set the default units of the buffer m_hookHelper.FocusMap.MapUnits = esriUnits.esriMeters; CNunit.SelectedIndex = 0; /* int units = Convert.ToInt32(m_hookHelper.FocusMap.MapUnits); * cboUnits1.SelectedIndex = units; */ }
private void cmbLayersList_SelectedIndexChanged(object sender, EventArgs e) { if (m_map == null) { return; } //遍历所有图层 IEnumLayer layers = GetAllLayersList(); if (layers == null) { return; } layers.Reset(); ILayer layer = null; while ((layer = layers.Next()) != null) { if (layer is IGroupLayer) { continue; } IFeatureLayer featureLayer = layer as IFeatureLayer;//设置图层要素可选择性 if (featureLayer != null) { if (this.cmbLayersList.SelectedItem.ToString() == layer.Name) { DataEditCommon.g_pLayer = layer; featureLayer.Selectable = true; } else { featureLayer.Selectable = false; } } } }
protected override void OnUpdate() { pMxDoc = (IMxDocument)ArcMap.Application.Document; pMap = pMxDoc.FocusMap; //** If a brand new data frame, reading Layers property will generate an error if (pMap.LayerCount > 0) { pLayers = pMap.Layers; pLayers.Reset(); pLoopLayer = pLayers.Next(); pRoadIdxLayer = null; //** Loop through all layers while (!(pLoopLayer == null)) { if (pLoopLayer.Name == "road_idx") { //** Road_idx found. Set the id var, enable the tool and exit the loop pRoadIdxLayer = (IFeatureLayer)pLoopLayer; Enabled = true; break; } else { //** roads not found yet. Move to next layer pLoopLayer = pLayers.Next(); } } } else { pRoadIdxLayer = null; } if (pRoadIdxLayer == null) { //** roads must not be in data frame, disable the tool Enabled = false; } }
//确认并退出 private void SubmitROIToolStripMenuItem_Click(object sender, EventArgs e) { Geoprocessor gp = new Geoprocessor { OverwriteOutput = true }; try { for (int i = 0; i < ROIFileNames.Count; i++) { Clip clip = new Clip(); IEnumLayer enumLayer = axMapControl1.get_Layer(i) as IEnumLayer; clip.in_features = axMapControl1.get_Layer(i) as IFeatureLayer; //clip.out_feature_class = txtOutputPath.Text + "\\" + "clip_" + obj; } //if (GetFeatureLayer(obj) != null) //{ // clip.in_features = GetFeatureLayer(obj); // clip.out_feature_class = txtOutputPath.Text + "\\" + "clip_" + obj; //} //else //{ // return; //} //clip.clip_features = clipFeatureClass; //clip.cluster_tolerance = tolerance; //IGeoProcessorResult results = (IGeoProcessorResult)gp.Execute(clip, null); //if (results != null) //{ // if (results.Status != esriJobStatus.esriJobSucceeded) // { // txtMessages.Text += "裁剪要素/层失败: " + obj + "\r\n"; // } //} } catch (Exception ex) { MessageBox.Show("裁剪要素问题: " + ex.Message); } }
private void Form1_Load(object sender, EventArgs e) { comboBox1.SelectedIndex = 0; //comboBox3.SelectedIndex = 0; mxDoc = ArcMap.Document; pBasicDocument = (IBasicDocument2)mxDoc; pMap = pBasicDocument.FocusMap; IEnumLayer pEnumLayer = pMap.Layers; ILayer pLayer; for (int i = 0; i < pMap.LayerCount; i++) { pLayer = pEnumLayer.Next(); comboBox2.Items.Add(pLayer.Name); } comboBox2.SelectedIndex = 0; }
private void CreateLayer(IName name) { ILayerFactoryHelper helper = new LayerFactoryHelperClass(); try { IEnumLayer layer = helper.CreateLayersFromName(name); layer.Reset(); for (ILayer layer2 = layer.Next(); layer2 != null; layer2 = layer.Next()) { int toIndex = 0; toIndex = LocalCommonHelper.GetLayerIndex(this.axMapControl1.Map, layer2); this.axMapControl1.AddLayer(layer2, toIndex); this.axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, layer2, null); } } catch (Exception) { MessageBox.Show("无法打开指定文档!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Hand); } }
/// <summary> /// 根据图层名称获取图层 /// </summary> /// <param name="pMap"></param> /// <param name="LayerName"></param> /// <returns></returns> public ILayer GetLayer(IMap pMap, string LayerName) { IEnumLayer pEnunLayer = pMap.get_Layers(null, false); pEnunLayer.Reset(); ILayer pRetureLayer; pRetureLayer = pEnunLayer.Next(); while (pRetureLayer != null) { if (pRetureLayer.Name == LayerName) { break; } pRetureLayer = pEnunLayer.Next(); } return(pRetureLayer); }
private void FrmNEDtoENU_Load(object sender, EventArgs e) { this.EnableGlass = false; //初始化图层列表 IEnumLayer pEnumLayer = pMapControl.Map.get_Layers(null, true); pEnumLayer.Reset(); ILayer pLayer = null; while ((pLayer = pEnumLayer.Next()) != null) { if (pLayer is IFeatureLayer) { cmbLayerTrans.Items.Add(pLayer.Name); } } if (cmbLayerTrans.Items.Count > 0) { cmbLayerTrans.SelectedIndex = 0; } }
private IFeatureLayer GetFeatureLayer(string layerName) { //get the layers from the maps UID uid = new UIDClass(); uid.Value = "{40A9E885-5533-11d0-98BE-00805F7CED21}"; layers = pMap.get_Layers(uid, true); layers.Reset(); ILayer layer = null; while ((layer = layers.Next()) != null) { if (layer.Name == layerName) { return(layer as IFeatureLayer); } } return(null); }
/// <summary> /// Gets all featurelayer in map返回地图中包括grouplayer中在内的所有的地理图层featurelayer. /// </summary> /// <param name="pMap">The p map.</param> /// <returns></returns> public static List <IFeatureLayer> GetAllFeaturelayerInMap(IMap pMap) { List <IFeatureLayer> list = new List <IFeatureLayer>(); IEnumLayer layers = pMap.Layers; layers.Reset(); ILayer layer; while ((layer = layers.Next()) != null) { if (layer.Visible) { IFeatureLayer featureLayer = layer as IFeatureLayer; if (featureLayer != null) { list.Add(featureLayer); } } } return(list); }
private void CacheTOC() { IMap aMap = ArcMap.Document.FocusMap as IMap; //UID anUID = new UID(); //anUID.Value = "{EDAD6644-1810-11D1-86AE-0000F8751720}"; // get all the 'top level' items IEnumLayer someLayers = aMap.Layers[null, false]; ILayer aLayer = null; int depth = 0; while ((aLayer = someLayers.Next()) != null) { rootLayers.Add(aLayer); } someLayers = aMap.Layers[null, true]; while ((aLayer = someLayers.Next()) != null) { Tree.Add(depth, aLayer); depth += 1; } }
/// <summary> /// get the list of all graphics layers in the map /// </summary> /// <returns></returns> private IEnumLayer GetGraphicsLayersList() { IEnumLayer layers = null; if (null == m_map || 0 == m_map.LayerCount) { return(null); } try { layers = m_map.get_Layers(m_uid, true); } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return(null); } return(layers); }
/// <summary> /// 通过名字获得索引图层. /// </summary> /// <param name="layerName">Name of the layer.</param> /// <returns></returns> public static IFeatureLayer GetIndexLayerByName(string layerName, IMap pMap) { UID pUID = new UIDClass(); pUID.Value = "{40A9E885-5533-11d0-98BE-00805F7CED21}"; IEnumLayer pEnumLayer = pMap.get_Layers(pUID, true); pEnumLayer.Reset(); ILayer pLayer = pEnumLayer.Next(); while (pLayer != null) { if (pLayer.Name == layerName) { return((IFeatureLayer)pLayer); } pLayer = pEnumLayer.Next(); } return(null); }
//Get the tracking layer that is selected in the combo box according to its name private ITemporalLayer GetSelectedTemporalLayer() { ITemporalLayer temporalLayer = null; if (cbTrackingServices.SelectedIndex > 0) { ILayer lyr = null; IEnumLayer temporalLayers = GetAllTrackingLayers(); string selectedLayerName = cbTrackingServices.Text; while ((lyr = temporalLayers.Next()) != null) { if (lyr.Name == selectedLayerName) { temporalLayer = (ITemporalLayer)lyr; } } } return(temporalLayer); }
public Buffer(IMap _pMap) { InitializeComponent(); //����Glass���� this.EnableGlass = false; //����ʾ�����С����ť this.MaximizeBox = false; this.MinimizeBox = false; // this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable; //ȥ��ͼ�� this.ShowIcon = false; //load all the feature layers in the map to the layers combo UID uid = new UIDClass(); uid.Value = "{40A9E885-5533-11d0-98BE-00805F7CED21}"; pMap = _pMap; layers = pMap.get_Layers(uid, true); layers.Reset(); ILayer layer = null; while ((layer = layers.Next()) != null) { cboLayers.Items.Add(layer.Name); } //select the first layer if (cboLayers.Items.Count > 0) cboLayers.SelectedIndex = 0; string tempDir = System.IO.Path.GetTempPath(); txtOutputPath.Text = System.IO.Path.Combine(tempDir, ((string)cboLayers.SelectedItem + "_buffer.shp")); //set the default units of the buffer int units = Convert.ToInt32(pMap.MapUnits); cboUnits.SelectedIndex = units; }
private IFeatureLayer GetFeatureLayer(string layerName) { //get the layers from the maps UID uid = new UIDClass(); uid.Value = "{40A9E885-5533-11d0-98BE-00805F7CED21}"; layers = pMap.get_Layers(uid, true); layers.Reset(); ILayer layer = null; while ((layer = layers.Next()) != null) { if (layer.Name == layerName) return layer as IFeatureLayer; } return null; }
private Dictionary<IFeatureLayer, string> GetTransMapLayers(IEnumLayer layers, IWorkspace transWorkspace) { Dictionary<IFeatureLayer, string> theReturn = new Dictionary<IFeatureLayer,string>(); layers.Reset(); ILayer theLayer = layers.Next(); while (theLayer != null) { if (theLayer is IFeatureLayer) { IDataset theDataset = ((IFeatureLayer)theLayer).FeatureClass as IDataset; if (theDataset != null && theDataset.Workspace == transWorkspace) { theReturn.Add((IFeatureLayer)theLayer, theDataset.Name); } } theLayer = layers.Next(); } return theReturn; }
private string CreateSchLayers(IEnumLayer pLayers) { if (pLayers == null) return ""; ILayer pLayer = pLayers.Next(); IFeatureLayer featureLayer; IFeatureClass featureClass; string pStrLayerNames = ""; IDataset pDataset; System.Windows.Forms.Cursor.Current = Cursors.WaitCursor; System.Windows.Forms.Cursor.Show(); m_pSDS.DesignMode = true; m_pSDI = (ESRI.ArcGIS.Schematic.ISchematicDatasetImport)m_pSDS; Dictionary<string, IFeatureClass> myDictionary = new Dictionary<string, IFeatureClass>(); IGeometricNetwork gn = null; do { featureLayer = (IFeatureLayer)pLayer; featureClass = featureLayer.FeatureClass; pDataset = (IDataset)featureClass; if (featureClass.FeatureType == esriFeatureType.esriFTSimpleJunction || featureClass.FeatureType == esriFeatureType.esriFTSimpleEdge || featureClass.FeatureType == esriFeatureType.esriFTComplexEdge || featureClass.FeatureType == esriFeatureType.esriFTComplexJunction) { //The FeatureType property of feature classes that implement this interface will be esriFTSimpleJunction, esriDTSimpleEdge, esriFTComplexJunction, or esriFTComplexEdge. INetworkClass networkClass = (INetworkClass)featureLayer.FeatureClass; if (networkClass.GeometricNetwork != null) { //we have a network class if ((gn == null) || (gn != networkClass.GeometricNetwork)) { //need to process all the classes Dictionary<string, IFeatureClass> localDictionary = new Dictionary<string, IFeatureClass>(); gn = networkClass.GeometricNetwork; IEnumFeatureClass fcComplexEdge = networkClass.GeometricNetwork.get_ClassesByType(esriFeatureType.esriFTComplexEdge); IEnumFeatureClass fcComplexNode = networkClass.GeometricNetwork.get_ClassesByType(esriFeatureType.esriFTComplexJunction); IEnumFeatureClass fcSimpleEdge = networkClass.GeometricNetwork.get_ClassesByType(esriFeatureType.esriFTSimpleEdge); IEnumFeatureClass fcSimpleNode = networkClass.GeometricNetwork.get_ClassesByType(esriFeatureType.esriFTSimpleJunction); localDictionary = ProcessFCs(fcComplexEdge, fcComplexNode, fcSimpleEdge, fcSimpleNode); if (myDictionary.Count == 0) //just copy it { myDictionary = localDictionary; } else //merge { Dictionary<string, IFeatureClass>.KeyCollection keyColl = localDictionary.Keys; foreach (string s in keyColl) { IFeatureClass fc; bool bln = localDictionary.TryGetValue(s, out fc); myDictionary.Add(s, fc); } } } //Build up the string that will go to the select items to reduce form pStrLayerNames += pDataset.Name.ToString(); pStrLayerNames += ";"; //Build up the string for just the node feature classes if (featureClass.FeatureType == esriFeatureType.esriFTSimpleJunction || featureClass.FeatureType == esriFeatureType.esriFTComplexJunction) { strNodeLayers += pDataset.Name.ToString(); strNodeLayers += ";"; } //create the fields collections to be used by the frmAdvanced form IFields pFields = featureClass.Fields; if (pFields.FieldCount > 0) { for (int i = 0; i < pFields.FieldCount; i++) { //don't mess with objectid or shape or GlobalID if ((pFields.get_Field(i).Name.ToString() != "OBJECTID") && (pFields.get_Field(i).Name.ToString() != "SHAPE") && (pFields.get_Field(i).Name.ToString() != "GlobalID") && (pFields.get_Field(i).Name.ToString() != featureClass.OIDFieldName.ToString()) && (pFields.get_Field(i).Name.ToString() != featureClass.ShapeFieldName.ToString())) { m_myCol.Add(pDataset.Name.ToString(), pFields.get_Field(i).Name.ToString()); } } } //remove the layer from the list of dictionary classes if (myDictionary.ContainsKey(featureClass.AliasName)) { myDictionary.Remove(featureClass.AliasName); } m_pSDI.ImportFeatureLayer(featureLayer, m_pSDT, true, true, true); } } pLayer = pLayers.Next(); } while (pLayer != null); //handle any feature classes that were not in the map if (myDictionary.Count > 0) { Dictionary<string, IFeatureClass>.KeyCollection keyColl = myDictionary.Keys; foreach (string s in keyColl) { IFeatureClass fc; bool bln = myDictionary.TryGetValue(s, out fc); IObjectClass o = (IObjectClass)fc; pDataset = (IDataset)fc; pStrLayerNames += pDataset.Name.ToString(); pStrLayerNames += ";"; //Build up the string for just the node feature classes if (fc.FeatureType == esriFeatureType.esriFTSimpleJunction || featureClass.FeatureType == esriFeatureType.esriFTComplexJunction) { strNodeLayers += pDataset.Name.ToString(); strNodeLayers += ";"; } //create the fields collections to be used by the frmAdvanced form IFields pFields = fc.Fields; if (pFields.FieldCount > 0) { for (int i = 0; i < pFields.FieldCount; i++) { //don't mess with objectid or shape or GlobalID if ((pFields.get_Field(i).Name.ToString() != "OBJECTID") && (pFields.get_Field(i).Name.ToString() != "SHAPE") && (pFields.get_Field(i).Name.ToString() != "GlobalID") && (pFields.get_Field(i).Name.ToString() != fc.OIDFieldName.ToString()) && (pFields.get_Field(i).Name.ToString() != fc.ShapeFieldName.ToString())) { m_myCol.Add(pDataset.Name.ToString(), pFields.get_Field(i).Name.ToString()); } } } if ((fc.FeatureType == esriFeatureType.esriFTComplexJunction) || (fc.FeatureType == esriFeatureType.esriFTSimpleJunction)) { //node m_pSDI.ImportObjectClass(o, m_pSDT, true, esriSchematicElementType.esriSchematicNodeType); } else { //link m_pSDI.ImportObjectClass(o, m_pSDT, true, esriSchematicElementType.esriSchematicLinkType); } } } m_pSDS.Save(ESRI.ArcGIS.esriSystem.esriArcGISVersion.esriArcGISVersionCurrent, true); m_pSDS.DesignMode = false; return pStrLayerNames; }
private void LegendWizard_Load(object sender, EventArgs e) { if (m_pageLayoutControl.ActiveView.FocusMap == null) { MessageBox.Show("请先添加地图"); return; } #region //点击 添加图例按钮 或在 PageLayoutControl中双击图例时 if (mapSurroundFrame == null) //当点击 添加图例按钮 或在 PageLayoutControl中双击图例时 先创建图例 或从地图上获得已经添加的图例; { //Get the GraphicsContainer IGraphicsContainer graphicsContainer = m_pageLayoutControl.GraphicsContainer; graphicsContainer.Reset(); IElementProperties pElementPerties = graphicsContainer.Next() as IElementProperties; //Get the MapFrame IMapFrame mapFrame = (IMapFrame)graphicsContainer.FindFrame(m_pageLayoutControl.ActiveView.FocusMap); if (mapFrame == null) return; while (pElementPerties != null) //从地图中获得已有的图例 { if (pElementPerties.Type == "Map Surround Frame") { pMapSurrounFrame = pElementPerties as IMapSurroundFrame; if (pMapSurrounFrame.MapSurround.Name == "Legend") { m_legend = pMapSurrounFrame.MapSurround as ILegend; break; } } pElementPerties = (IElementProperties)graphicsContainer.Next(); } if (m_legend == null) //当地图中没有添加图例时 创建新图例 { //Create a legend UID uID = new UIDClass(); uID.Value = "esriCarto.Legend"; //Create a MapSurroundFrame from the MapFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uID, null); if (mapSurroundFrame == null) return; if (mapSurroundFrame.MapSurround == null) return; m_legend = mapSurroundFrame.MapSurround as ILegend; } else { mapSurroundFrame = pMapSurrounFrame; } UID m_uid = new UIDClass(); m_uid.Value = "{34C20002-4D3C-11D0-92D8-00805F7C28B0}"; m_mapLayers = m_mapControl.Map as IMapLayers; m_emuLayer = m_mapLayers.get_Layers(m_uid, true);//获取图层 if (m_emuLayer != null) { m_emuLayer.Reset(); ILayer m_layer = null; while ((m_layer = m_emuLayer.Next()) != null) { this.listBox1.Items.Add(m_layer.Name);//将图层名添加到图例备选项中 } } } #endregion else //在双击任意范围打印框中图例时,获得图例,及图层信息; { if (m_Map == null) { MessageBox.Show("请先添加地图!"); } for (int k = 0; k < m_Map.LayerCount; k++) { listBox1.Items.Add(m_Map.get_Layer(k).Name.ToString()); } m_legend = mapSurroundFrame .MapSurround as ILegend; } //以下设置需要用到的变量 及初始化 对话框 plegendFormat = m_legend.Format as ILegendFormat; //设置图例格式需要用到的 pTextSymbol = new TextSymbolClass(); pTextSymbol.Size = 10; pTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft; //初始化图例标签的文本格式 if (m_legend.Title != null) textBox1.Text = m_legend.Title.ToString(); //初始化对话框中的文本框 文本 else textBox1.Text = "Legend"; this.textBoxWidth.Text = "36"; this.textBoxHeight.Text = "15"; IMapSurround mapSurround = m_legend as IMapSurround; mapSurroundFrame.MapSurround = mapSurround; m_FrameProperties = (IFrameProperties)mapSurroundFrame; ISymbolBackground pSymbolBack = m_FrameProperties.Background as ISymbolBackground; ISymbolBorder pSymbolBorder = m_FrameProperties.Border as ISymbolBorder; ISymbolShadow pSymbolShadow = m_FrameProperties.Shadow as ISymbolShadow; if (pSymbolBack !=null ) this.btnBackGroundColor.BackColor =ColorTranslator.FromOle ( pSymbolBack.FillSymbol.Color.RGB ) ; if (pSymbolBorder != null) this.btnBolderColor.BackColor = ColorTranslator.FromOle(pSymbolBorder.LineSymbol.Color.RGB); if (pSymbolShadow != null) this.btnShadowColor.BackColor = ColorTranslator.FromOle(pSymbolShadow.FillSymbol.Color.RGB); }
/// <summary> /// 窗体初始化 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SelectByAttrFrm_Load(object sender, EventArgs e) { this.pMap = this.tempMainFrm.mainMapControl.Map; if (this.pMap.LayerCount == 0) return; this.pEnumLayer = this.pMap.get_Layers(null, true); if (pEnumLayer == null) { return; } pEnumLayer.Reset(); for (this.pLayer = pEnumLayer.Next(); this.pLayer != null; this.pLayer = pEnumLayer.Next()) { if (this.pLayer is IFeatureLayer) { this.comboBoxLayers.Items.Add(this.pLayer.Name); } } if (this.comboBoxLayers.Items.Count == 0) { MessageBox.Show("没有可供选择的图层!"); this.Close(); return; } this.comboBoxLayers.SelectedIndex = 0; this.comboBoxMethod.SelectedIndex = 0; }