private void FrmPointToLine_Load(object sender, EventArgs e) { try { for (int i = 0; i < pMapcontrol.LayerCount; i++) { ILayer pLayer = null; if (pMapcontrol.get_Layer(i) is IFeatureLayer) { pLayer = pMapcontrol.get_Layer(i); IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer; IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass; if (pFeatureClass.ShapeType == esriGeometryType.esriGeometryPoint || pFeatureClass.ShapeType == esriGeometryType.esriGeometryMultipoint) { cboBoxPointLayer.Items.Add(pLayer.Name); } if (pFeatureClass.ShapeType == esriGeometryType.esriGeometryPoint || pFeatureClass.ShapeType == esriGeometryType.esriGeometryMultipoint) { comboBoxExCenterlineLayer.Items.Add(pLayer.Name); } if (pFeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline) { comboBoxExCenterlineLinearLayer.Items.Add(pLayer.Name); } } } if (cboBoxPointLayer.Items.Count > 0) { cboBoxPointLayer.SelectedIndex = 0; } if (comboBoxExCenterlineLayer.Items.Count > 0) { comboBoxExCenterlineLayer.SelectedIndex = 0; } if (comboBoxExCenterlineLinearLayer.Items.Count > 0) { comboBoxExCenterlineLinearLayer.SelectedIndex = 0; } } catch (SystemException ex) { } }
private void OpenAddFile(string file) { try { _FeatureLayer = null; for (int i = 0; i < _pMapControl.LayerCount; i++) { ILayer pLayer = _pMapControl.get_Layer(i); if (pLayer is IFeatureLayer) { IFeatureClass pFClass = (pLayer as IFeatureLayer).FeatureClass; string dtSource = Path.Combine((pFClass as IDataset).Workspace.PathName, (pFClass as IDataset).Name + ".shp"); if (dtSource == file) { _FeatureLayer = pLayer as IFeatureLayer; } } } if (_FeatureLayer == null) { IFeatureClass pFClass = EngineAPI.OpenFeatureClass(file); _FeatureLayer = new FeatureLayerClass(); _FeatureLayer.FeatureClass = pFClass; FileInfo fInfo = new FileInfo(file); _FeatureLayer.Name = fInfo.Name.Substring(0, fInfo.Name.Length - 4); _pMapControl.AddLayer(_FeatureLayer); } ITableConversion conver = new TableConversion(); this._CurrentTable = conver.AETableToDataTable(_FeatureLayer.FeatureClass); _CurrentTable.AcceptChanges(); gridView1.Columns.Clear(); this.gridControlTable.DataSource = _CurrentTable; } catch (Exception ex) { XtraMessageBox.Show(ex.Message); } }
/// <summary> /// 根据图层名找到图层索引 /// </summary> /// <param name="mainMap"></param> /// <param name="layerName"></param> /// <returns></returns> public static ILayer returnIndexByLayerName(IMapControl3 mainMap, string layerName) { ILayer index = null; ILayer temp = null; int layerCount = mainMap.LayerCount; for (int i = 0; i < layerCount; i++) { temp = mainMap.get_Layer(i); if (temp is GroupLayer) { ILayer LayerItem = temp; ICompositeLayer pGroupLayer = LayerItem as ICompositeLayer;//获取子图层 for (int j = 0; j < pGroupLayer.Count; j++) { ILayer pCompositeLayer; pCompositeLayer = pGroupLayer.get_Layer(j); if (pCompositeLayer.Name == layerName) { index = pCompositeLayer; IGroupLayer pGPLayer = LayerItem as IGroupLayer; pGPLayer.Delete(pCompositeLayer); } } if (pGroupLayer.Count == 0) { MainFrom.m_mapControl.Map.DeleteLayer(LayerItem); } } else if (temp.Name == layerName) { index = temp; } } return(index); }
private static ILayer funReturnLayerByLayerName(IMapControl3 mainMap, string strLayerName) { ILayer pLayer = null; ILayer pL = null; for (int i = 0; i < mainMap.LayerCount; i++) { pL = mainMap.get_Layer(i); if (pL is IGroupLayer) { ICompositeLayer pGL = pL as ICompositeLayer; for (int j = 0; j < pGL.Count; j++) { if (pGL.get_Layer(j).Name == strLayerName) { pLayer = pGL.get_Layer(j); } } } if (pL.Name == strLayerName) { pLayer = pL; } } return pLayer; }
private void FrmPointToLine_Load(object sender, EventArgs e) { for (int i = 0; i < pMapcontrol.LayerCount; i++) { ILayer pLayer = null; if (pMapcontrol.get_Layer(i) is IFeatureLayer) { pLayer = pMapcontrol.get_Layer(i); IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer; IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass; if (pFeatureClass.ShapeType == esriGeometryType.esriGeometryPoint || pFeatureClass.ShapeType == esriGeometryType.esriGeometryMultipoint) { cboBoxPointLayer.Items.Add(pLayer.Name); } if (pFeatureClass.ShapeType == esriGeometryType.esriGeometryPoint || pFeatureClass.ShapeType == esriGeometryType.esriGeometryMultipoint) { comboBoxExIMULayer.Items.Add(pLayer.Name); } if (pFeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline) { comboBoxExCenterline.Items.Add(pLayer.Name); } } } if (cboBoxPointLayer.Items.Count > 0) { cboBoxPointLayer.SelectedIndex = 0; } if (comboBoxExIMULayer.Items.Count > 0) { comboBoxExIMULayer.SelectedIndex = 0; } if (comboBoxExCenterline.Items.Count > 0) { comboBoxExCenterline.SelectedIndex = 0; } labelNeirong.Font = new System.Drawing.Font("仿宋", 4F); labelbiaotou.Font = new System.Drawing.Font("仿宋", 6F); }
/// <summary> /// 保存地图文档 /// </summary> public void Save() { //首先确认当前地图文档是否有效 if (m_MapControl.CheckMxFile(m_MapControl.DocumentFilename)) { ////创建一个新的地图文档实例 //IMapDocument mapDoc = new MapDocument(); ////打开当前地图文档 //mapDoc.Open(m_MapControl.DocumentFilename, string.Empty); ////判断地图数据是否只读 //if (mapDoc.get_IsReadOnly(m_MapControl.DocumentFilename)) //{ // MessageBox.Show("地图文档只读,不能加载!"); // mapDoc.Close(); // return; //} ////替换地图目录 //mapDoc.ReplaceContents((IMxdContents)m_MapControl.Map); ////保存地图文档 //mapDoc.Save(mapDoc.UsesRelativePaths,true); //mapDoc.Close(); System.Data.DataTable dt = new System.Data.DataTable("GIS"); dt.Columns.Add("name"); dt.Columns.Add("value"); dt.Columns.Add("params"); System.Data.DataRow dr = dt.NewRow(); string extent = Math.Round(m_MapControl.Extent.XMax, 2).ToString() + "," + Math.Round(m_MapControl.Extent.XMin, 2).ToString() + "," + Math.Round(m_MapControl.Extent.YMax, 2).ToString() + "," + Math.Round(m_MapControl.Extent.YMin, 2).ToString(); dr = dt.NewRow(); dr[0] = "extent"; dr[1] = extent; dt.Rows.Add(dr); string Scale = Math.Round(m_MapControl.MapScale, 0).ToString(); dr = dt.NewRow(); dr[0] = "Scale"; dr[1] = Scale; dt.Rows.Add(dr); string ckScale = Math.Round(m_MapControl.ReferenceScale, 0).ToString(); dr = dt.NewRow(); dr[0] = "ckScale"; dr[1] = ckScale; dt.Rows.Add(dr); string Rotation = Math.Round(m_MapControl.Rotation, 0).ToString(); dr = dt.NewRow(); dr[0] = "Rotation"; dr[1] = Rotation; dt.Rows.Add(dr); for (int i = 0; i < m_MapControl.LayerCount; i++) { ILayer player = m_MapControl.get_Layer(i); if (player is IGroupLayer) { dr = dt.NewRow(); dr[0] = "layer"; dr[1] = player.Name; dr[2] = player.Visible.ToString(); dt.Rows.Add(dr); setgisxml(ref dt, player as IGroupLayer); } else { dr = dt.NewRow(); dr[0] = "layer"; dr[1] = player.Name; dr[2] = player.Visible.ToString(); dt.Rows.Add(dr); } } dt.WriteXml(Application.StartupPath + @"\gis.xml"); } //else // this.SaveAs();//新建后m_MapControl.DocumentFilename为空,故调用另存为进行保存 }