1. 程式人生 > >AE二次開發中幾個功能速成歸納(符號設計器、創建要素、圖形編輯、屬性表編輯、緩沖區分析)

AE二次開發中幾個功能速成歸納(符號設計器、創建要素、圖形編輯、屬性表編輯、緩沖區分析)

文件夾路徑 及其 基本框架 option 開啟 rgs database ets remove

/*
 * 實習課上講進階功能所用文檔,因為趕時間從網上抄抄改改,湊合能用,記錄一下以備個人後用。
 *
 * -------------------------------------------------------------------
 *
 * 使用前提:已搭建好AE的GIS基本框架,包括TOC、mapcontrol、toolbar拖控件,mxd、shp文件載入顯示,查看圖層屬性表等
 *
 * -------------------------------------------------------------------
 */
/* Form1中的using */

using
System; using System.Windows.Forms; using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Controls; using ESRI.ArcGIS.Display; using ESRI.ArcGIS.Geometry; using ESRI.ArcGIS.Geodatabase; using ESRI.ArcGIS.SystemUI; using ESRI.ArcGIS.esriSystem; using System.Drawing; using System.Runtime.InteropServices;
using ESRI.ArcGIS.DataSourcesFile; using System.Collections; /* * 一、符號設計 * * 在TOC的doubleclick事件中寫入: */ esriTOCControlItem toccItem = esriTOCControlItem.esriTOCControlItemNone; ILayer iLayer = null; IBasicMap iBasicMap = null; object unk = null; object data = null; axTOCControl1.HitTest( e.x, e.y,
ref toccItem, ref iBasicMap, ref iLayer, ref unk, ref data ); /* 獲取所點擊圖例及其圖層 */ if ( e.button == 1 ) { if ( toccItem == esriTOCControlItem.esriTOCControlItemLegendClass ) { ILegendClass pLC = new LegendClassClass(); pLC = ( (ILegendGroup) unk).get_Class( (int) data ); /* 獲取圖例 */ ISymbol pSym = pLC.Symbol; /* 獲取圖例的符號 */ ESRI.ArcGIS.DisplayUI.ISymbolSelector pSS = new ESRI.ArcGIS.DisplayUI.SymbolSelectorClass(); /* 創建符號選擇器 */ bool a = false; pSS.AddSymbol( pSym ); a = pSS.SelectSymbol( 0 ); /* 打開符號選擇器 */ if ( a ) { pLC.Symbol = pSS.GetSymbolAt( 0 ); } this.axMapControl1.ActiveView.Refresh(); this.axTOCControl1.Refresh(); } } /* * 二、創建要素 * * 1.創建並添加shp新圖層 */ /* 點shp的創建並添加 */ private void 點ToolStripMenuItem_Click( object sender, EventArgs e ) { string pointshppath = ""; SaveFileDialog spointdlg = new SaveFileDialog(); /* 打開保存文件對話框,設置保存路徑和shp文件名 */ if ( spointdlg.ShowDialog() == DialogResult.OK ) { pointshppath = spointdlg.FileName; }else { return; } /* 準備好要素類空對象 */ IFeatureClass m_pointfeatureclass = null; /* 從文件路徑中分解出文件夾路徑和文件名稱 */ int count = pointshppath.LastIndexOf ("\"); string folder = pointshppath.Substring(0, count); string name = pointshppath.Substring(count + 1, pointshppath.Length - count - 1); //根據文件夾路徑創建工作空間工廠和工作空間 IWorkspace ipws; IWorkspaceFactory ipwsf = new ShapefileWorkspaceFactoryClass(); ipws = ipwsf.OpenFromFile(folder, 0); //轉為要素工作空間 IFeatureWorkspace ifeatws; ifeatws = ipws as IFeatureWorkspace; //對shp文件的一些必要設置,除了紅字部分外都不用改 IFields pFields = new FieldsClass(); IField pField = new FieldClass(); IFieldsEdit pFieldsEdit = pFields as IFieldsEdit; IFieldEdit pFieldEdit = pField as IFieldEdit; IGeometryDef ipGeodef = new GeometryDefClass(); IGeometryDefEdit ipGeodefEdit = ipGeodef as IGeometryDefEdit; ISpatialReference ipSpatialRef; IUnknownCoordinateSystem iunknowncoord = new UnknownCoordinateSystemClass(); ipSpatialRef = iunknowncoord; ipGeodefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;//確定你要生成的shp的幾何類型(點線面) ipSpatialRef.SetMDomain(-10000, 10000); ipGeodefEdit.HasM_2 = false; ipGeodefEdit.HasZ_2 = false; ipGeodefEdit.SpatialReference_2 = ipSpatialRef; pFieldEdit.Name_2 = "Shape "; pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry; pFieldEdit.GeometryDef_2 = ipGeodef; pFieldsEdit.AddField(pField); ////////////////////////////////////////// //創建要素類並導出shp文件於預設文件路徑 m_pointfeatureclass = ifeatws.CreateFeatureClass(name, pFields, null, null, esriFeatureType.esriFTSimple, "Shape ", " "); //加載新創建的shp文件並調到圖層顯示順序的最頂層 axMapControl1.AddShapeFile(folder,name); axMapControl1.MoveLayerTo(0, axMapControl1.LayerCount - 1); return; } //線shp的創建並添加 private void 線ToolStripMenuItem_Click(object sender, EventArgs e) { string lineshppath = " "; SaveFileDialog slinedlg = new SaveFileDialog();//打開保存文件對話框,設置保存路徑和shp文件名 if (slinedlg.ShowDialog() == DialogResult.OK) { lineshppath = slinedlg.FileName; } else { return; } //準備好要素類空對象 IFeatureClass m_linefeatureclass = null; //從文件路徑中分解出文件夾路徑和文件名稱 int count = lineshppath.LastIndexOf(" \ "); string folder = lineshppath.Substring(0, count); string name = lineshppath.Substring(count + 1, lineshppath.Length - count - 1); //根據文件夾路徑創建工作空間工廠和工作空間 IWorkspace ipws; IWorkspaceFactory ipwsf = new ShapefileWorkspaceFactoryClass(); ipws = ipwsf.OpenFromFile(folder, 0); //轉為要素工作空間 IFeatureWorkspace ifeatws; ifeatws = ipws as IFeatureWorkspace; //對shp文件的一些必要設置,除了紅字部分外都不用改 IFields pFields = new FieldsClass(); IField pField = new FieldClass(); IFieldsEdit pFieldsEdit = pFields as IFieldsEdit; IFieldEdit pFieldEdit = pField as IFieldEdit; IGeometryDef ipGeodef = new GeometryDefClass(); IGeometryDefEdit ipGeodefEdit = ipGeodef as IGeometryDefEdit; ISpatialReference ipSpatialRef; IUnknownCoordinateSystem iunknowncoord = new UnknownCoordinateSystemClass(); ipSpatialRef = iunknowncoord; ipGeodefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolyline;//確定你要生成的shp的幾何類型(點線面) ipSpatialRef.SetMDomain(-10000, 10000); ipGeodefEdit.HasM_2 = false; ipGeodefEdit.HasZ_2 = false; ipGeodefEdit.SpatialReference_2 = ipSpatialRef; pFieldEdit.Name_2 = "Shape "; pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry; pFieldEdit.GeometryDef_2 = ipGeodef; pFieldsEdit.AddField(pField); ////////////////////////////////////////// //創建要素類並導出shp文件於預設文件路徑 m_linefeatureclass = ifeatws.CreateFeatureClass(name, pFields, null, null, esriFeatureType.esriFTSimple, "Shape ", " "); //加載新創建的shp文件並調到圖層顯示順序的最頂層 axMapControl1.AddShapeFile(folder,name); axMapControl1.MoveLayerTo(0, axMapControl1.LayerCount - 1); return; } //面shp的創建並添加 private void 面ToolStripMenuItem_Click(object sender, EventArgs e) { string polygonshppath = " "; SaveFileDialog spolygondlg = new SaveFileDialog();//打開保存文件對話框,設置保存路徑和shp文件名 if (spolygondlg.ShowDialog() == DialogResult.OK) { polygonshppath = spolygondlg.FileName; } else { return; } //準備好要素類空對象 IFeatureClass m_polygonfeatureclass = null; //從文件路徑中分解出文件夾路徑和文件名稱 int count = polygonshppath.LastIndexOf(" \ "); string folder = polygonshppath.Substring(0, count); string name = polygonshppath.Substring(count + 1, polygonshppath.Length - count - 1); //根據文件夾路徑創建工作空間工廠和工作空間 IWorkspace ipws; IWorkspaceFactory ipwsf = new ShapefileWorkspaceFactoryClass(); ipws = ipwsf.OpenFromFile(folder, 0); //轉為要素工作空間 IFeatureWorkspace ifeatws; ifeatws = ipws as IFeatureWorkspace; //對shp文件的一些必要設置,除了紅字部分外都不用改 IFields pFields = new FieldsClass(); IField pField = new FieldClass(); IFieldsEdit pFieldsEdit = pFields as IFieldsEdit; IFieldEdit pFieldEdit = pField as IFieldEdit; IGeometryDef ipGeodef = new GeometryDefClass(); IGeometryDefEdit ipGeodefEdit = ipGeodef as IGeometryDefEdit; ISpatialReference ipSpatialRef; IUnknownCoordinateSystem iunknowncoord = new UnknownCoordinateSystemClass(); ipSpatialRef = iunknowncoord; ipGeodefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;//確定你要生成的shp的幾何類型(點線面) ipSpatialRef.SetMDomain(-10000, 10000); ipGeodefEdit.HasM_2 = false; ipGeodefEdit.HasZ_2 = false; ipGeodefEdit.SpatialReference_2 = ipSpatialRef; pFieldEdit.Name_2 = "Shape "; pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry; pFieldEdit.GeometryDef_2 = ipGeodef; pFieldsEdit.AddField(pField); ////////////////////////////////////////// //創建要素類並導出shp文件於預設文件路徑 m_polygonfeatureclass = ifeatws.CreateFeatureClass(name, pFields, null, null, esriFeatureType.esriFTSimple, "Shape ", " "); //加載新創建的shp文件並調到圖層顯示順序的最頂層 axMapControl1.AddShapeFile(folder,name); axMapControl1.MoveLayerTo(0, axMapControl1.LayerCount - 1); return; } /* 2.在shp中繪制點線面要素並儲存 課上只提到調用Toolbar裏的工具: 使用流程: 開始編輯——>選擇目標圖層——>開啟草圖工具——>繪制新圖形——>保存並停止編輯 而寫代碼方式的主要思路如下(沒做撤銷和雙緩沖): */ //獲取MapControl中的全部圖層名稱,並加入ComboBox //圖層 toolStripComboBox1.Visible = true; ILayer pLayer; //圖層名稱 string strLayerName; for (int i = 0; i < this.axMapControl1.LayerCount; i++) { pLayer = this.axMapControl1.get_Layer(i); strLayerName = pLayer.Name; //圖層名稱加入ComboBox this.toolStripComboBox1.Items.Add(strLayerName); } //默認顯示第一個選項 this.toolStripComboBox1.SelectedIndex = 0; //用三個int成員變量drawpoint、drawline、drawregion指示添加的是點、線還是面 //用三個IFeatureClass成員變量startpointshp、startlineshp、startpolygonshp來取出所選圖層的要素類 //用一個點集數列IPointArray pts存儲畫線、面時連續產生的節點 //當combobox中選項變化時判斷所選圖層的要素類的幾何類型並取出 IFeatureLayer layer = axMapControl1.get_Layer(this.toolStripComboBox1.SelectedIndex) as IFeatureLayer; if (layer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPoint) { startpointshp = layer.FeatureClass; drawpoint = 1; drawline = 0; drawregion = 0; } if (layer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline) { startlineshp = layer.FeatureClass; drawpoint = 0; drawline = 1; drawregion = 0; } if (layer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon) { startpolygonshp = layer.FeatureClass; drawpoint = 0; drawline = 0; drawregion = 1; } //在onmousedown(onmouseup也行)中進行判斷並創建新要素圖形 if (e.button == 2 &&drawline ==0 &&drawpoint==0 && drawregion==0) { m_menuMap.PopupMenu(e.x, e.y, m_mapControl.hWnd);//沒開啟添加要素功能,則正常彈菜單項 } if (e.button == 1 && drawpoint == 1) { IPoint pt; pt = axMapControl1.ToMapPoint(e.x, e.y); IFeature pFeature = startpointshp.CreateFeature(); pFeature.Shape = pt; pFeature.Store(); this.axMapControl1.ActiveView.Refresh(); return; } if (e.button == 1 && drawline == 1)//左鍵創建線的節點 { IPoint pt; pt = axMapControl1.ToMapPoint(e.x, e.y); pts.Add(pt); return; } if (e.button == 2 && drawline == 1)//右鍵根據節點創建線 { ESRI.ArcGIS.Geometry.IPolyline ipPolyline = new PolylineClass(); ESRI.ArcGIS.Geometry.IPointCollection ipPointCol = (IPointCollection)ipPolyline; object missing = Type.Missing; for (int i = 0; i < pts.Count; i++) { object t = pts.get_Element(i); ESRI.ArcGIS.Geometry.Point p = (ESRI.ArcGIS.Geometry.Point)t; if (p != null) { ipPointCol.AddPoint(p, ref missing, ref missing); } } IPolyline polyline = ipPolyline; IFeature pFeature = startlineshp.CreateFeature(); pFeature.Shape = polyline; pFeature.Store(); this.axMapControl1.ActiveView.Refresh(); pts.RemoveAll(); return; } if (e.button == 1 && drawregion == 1)//左鍵創建面的節點 { IPoint pt; pt = axMapControl1.ToMapPoint(e.x, e.y); pts.Add(pt); return; } if (e.button == 2 && drawregion == 1)//右鍵根據節點創建面 { ESRI.ArcGIS.Geometry.IPolygon ipPolyGon = new PolygonClass(); ESRI.ArcGIS.Geometry.IPointCollection ipPointCol = (IPointCollection)ipPolyGon; object missing = Type.Missing; for (int i = 0; i < pts.Count; i++) { object t = pts.get_Element(i); ESRI.ArcGIS.Geometry.Point p = (ESRI.ArcGIS.Geometry.Point)t; if (p != null) { ipPointCol.AddPoint(p, ref missing, ref missing); } } ipPointCol.AddPoint(pts.get_Element(0), ref missing, ref missing);//面的坐標串首尾坐標應一致(如P1-P2-P3-P4-P1) IPolygon polygon = ipPolyGon; IFeature pFeature = startpolygonshp.CreateFeature(); pFeature.Shape = polygon; pFeature.Store(); this.axMapControl1.ActiveView.Refresh(); pts.RemoveAll(); return; } //結束創建時執行清理、重置 drawpoint = 0; drawline = 0; drawregion = 0; pts.RemoveAll(); startpointshp = null; startlineshp = null; startpolygonshp = null; this.toolStripComboBox1.Visible = false; this.toolStripComboBox1.Items.Clear(); /* 3.shp中點線面要素的圖形編輯 使用Toolbar 使用流程: 開始編輯——>選擇目標圖層——>開啟編輯工具——>圖形編輯——>保存並停止編輯 三、屬性表編輯 1.在屬性表窗體設計中加一個按鈕用於更新數據 2.屬性表類中至少應有如下成員對象,在表開啟後這些值應都已經賦值或初始化 * */ public DataTable attributeTable;//你的表 string tableName;//你的表的名字 public List array = new List();//你用來記錄哪些行的數據被改變了的數列 public ILayer currentlayer;//你用來獲取當前圖層的對象其中,比如,attributeTable和tableName可在Load函數中賦值,currentlayer可在構造函數中賦值 /* 3.添加如下函數 */ //在按鈕的點擊事件中添加如下代碼 private void button1_Click(object sender, EventArgs e) { if (array.Count < 1)//沒有記錄到任何數據可能改變的行 { MessageBox.Show(" 未 修改任何數據 ! "); return; } array.Sort(); ILayer player = this.currentlayer; UpdateFTOnDV(player, attributeTable, array.ToArray()); dataGridView1.EditMode = DataGridViewEditMode.EditProgrammatically;//dataGridView1是你屬性表中顯示數據的視圖 dataGridView1.Refresh(); } //在表的CellValueChanged事件中添加如下代碼 private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e) { array.Add(e.RowIndex);//將有值改變的那個行的行號記錄下來 } //在屬性表類中添加如下函數 public void UpdateFTOnDV(ILayer player, DataTable pdatatable, int[] array) { IFeatureLayer pFTClass = player as IFeatureLayer; ITable pTable = pFTClass as ITable; IRow pRow; ICursor pCursor = pTable.GetRows(array, false); for (int i = 0; i < array.Length; i++) { pRow = pCursor.NextRow(); int k = array[i]; for (int j = 2; j < pdatatable.Columns.Count; j++) { object pgridview = pdatatable.Rows[k][j]; object prow = pRow.get_Value(j); if (prow.ToString() != pgridview.ToString())//當表格中值與shp文件屬性表中值不同時發生替換 { if (pgridview == System.DBNull.Value) { string skipinfo = "" + (k+1).ToString() + "行第 " + (j+1).ToString() + " 列 的數據 可 為 空 自動跳過修改 "; MessageBox.Show(skipinfo); continue; } pRow.set_Value(j, pgridview); pRow.Store(); } } } MessageBox.Show("數據保存 成 功 ! "); } /* 四、空間分析 以緩沖區分析為例,實現對某類地物周邊一定範圍內其他地物的統計與顯示。 */ //buffer類中的using using System; using System.Windows.Forms; using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Controls; using ESRI.ArcGIS.Geoprocessing; using ESRI.ArcGIS.Geoprocessor; using ESRI.ArcGIS.Geodatabase; using ESRI.ArcGIS.AnalysisTools; using System.Collections; /* 1.創建一個windows窗體類buffer.cs 2.對窗體進行設計 目標地物(上面的)下拉框的Name設為comboBox2 被統計地物(下面的)下拉框Name設為comboBox3 分析距離textBox的Name設為textBox1 按鈕Name設為button1 3.添加相關代碼 */ //1>Buffer類中添加三個成員 private static int counter = 1;//用來對生成圖層的計數 private AxMapControl axMapControl1;//用來獲取主框架傳進來的AxMapControl private ArrayList flyr = new ArrayList();//用來存儲生成的圖層,便於結束分析後刪除 //2>修改構造函數為 public buffer(AxMapControl mapControl) { InitializeComponent(); this.axMapControl1 = mapControl; } //3>在窗體設計布局中,雙擊Buffer的對話框,進入buffer_Load函數,添加以下代碼 //MapControl中沒有圖層時返回 if (axMapControl1.LayerCount <= 0) return; ILayer pLayer;//圖層 string strLayerName;//圖層名稱 //獲取MapControl中的全部圖層名稱,並加入ComboBox for (int i = 0; i < axMapControl1.LayerCount; i++) { pLayer = axMapControl1.get_Layer(i); strLayerName = pLayer.Name; comboBox2.Items.Add(strLayerName); comboBox3.Items.Add(strLayerName); } //默認顯示第一個選項 comboBox2.SelectedIndex = 0; comboBox3.SelectedIndex = 0; //3>在窗體設計布局中,雙擊按鈕,進入click事件,添加以下代碼 //獲取所設置的緩沖區距離 string distance = this.textBox1.Text.ToString(); //給距離加上單位,默認為米 string para = distance + " Meters "; //根據所選圖層確定其數據源位置,即shp文件所在的文件夾路徑 IDataLayer combo2 = (IDataLayer)axMapControl1.get_Layer(comboBox2.SelectedIndex); IWorkspaceName ws = ((IDatasetName)(combo2.DataSourceName)).WorkspaceName; string featurefolder = ws.PathName; //使用gp處理工具 Geoprocessor gp = new Geoprocessor(); //允許覆蓋同名文件 gp.OverwriteOutput = true; //調用緩沖區工具 ESRI.ArcGIS.AnalysisTools.Buffer buffertool = new ESRI.ArcGIS.AnalysisTools.Buffer(); //設置輸入圖層路徑和輸出圖層路徑 buffertool.in_features = featurefolder+ " \ " + comboBox2.SelectedItem + ".shp "; buffertool.out_feature_class = featurefolder + " \ " + comboBox2.SelectedItem + "_buffer " + counter.ToString() + ".shp "; //設置緩沖區相關參數 buffertool.buffer_distance_or_field = para; buffertool.dissolve_option = "ALL "; //執行 try { gp.Execute(buffertool, null); } catch (Exception ex) { MessageBox.Show("ERROR "); return; } //對生成圖層的計數 counter++; //用生成的緩沖區與被統計地物進行疊置分析求交集 Intersect pIntersect = new Intersect(); int chooselayer = counter - 1; Geoprocessor gp2 = new Geoprocessor(); gp2.OverwriteOutput = true; //允許覆蓋同名文件 FeatureLayer pFeatureLayer = new FeatureLayerClass(); //設置相關參數 object obj = gp2.GetEnvironmentValue("Extent "); gp2.SetEnvironmentValue("Extent ", "MAXOF "); obj = gp2.GetEnvironmentValue("OutputZFlag "); gp2.SetEnvironmentValue("OutputZFlag ", "DEFAULT "); obj = gp2.GetEnvironmentValue("OutputMFlag "); gp2.SetEnvironmentValue("OutputMFlag ", "DEFAULT "); obj = gp2.GetEnvironmentValue("QualifiedFieldNames "); gp2.SetEnvironmentValue("QualifiedFieldNames ", "QUALIFIED "); //把要求交的兩個要素放到一個IGpValueTableObject中作為參數 IGpValueTableObject pObject = new GpValueTableObjectClass(); pObject.SetColumns(2); object inputfeature = featurefolder + " \ " + comboBox3.SelectedItem + ".shp "; pObject.AddRow(ref inputfeature); object inputfeature2 = featurefolder + " \ " + comboBox2.SelectedItem + "_buffer " + chooselayer.ToString() + ".shp "; pObject.AddRow(ref inputfeature2); //設置輸入圖層路徑和輸出圖層路徑 pIntersect.in_features = pObject; pIntersect.out_feature_class = featurefolder + " \ " + comboBox2.SelectedItem + "_insert " + chooselayer.ToString() + ".shp "; pIntersect.join_attributes = "All "; //執行 IGeoProcessorResult pResult = (IGeoProcessorResult)gp2.Execute(pIntersect, null); //從求交的結果中提取Feature並做相關統計 IGPUtilities pGPUtil = new GPUtilitiesClass(); IFeatureClass pFC; IQueryFilter pQF; pGPUtil.DecodeFeatureLayer(pResult.GetOutput(0), out pFC, out pQF); int count = pFC.FeatureCount(null); IFeatureCursor pCursor = pFC.Insert(true); pFeatureLayer.FeatureClass = pFC; //將緩沖區載入地圖中顯示 axMapControl1.AddShapeFile(featurefolder + " \ ", comboBox2.SelectedItem + "_buffer " + chooselayer.ToString() + ".shp "); axMapControl1.MoveLayerTo(0, axMapControl1.LayerCount - 1); //獲取生成的緩沖區對象 FeatureLayer bufferlayer = axMapControl1.get_Layer(axMapControl1.LayerCount - 1) as FeatureLayer; //將求交得到的對象載入地圖中顯示 pFeatureLayer.Name = comboBox2.SelectedItem + " 周邊 " + textBox1.Text + "米內的 " + comboBox3.SelectedItem; axMapControl1.Map.AddLayer(pFeatureLayer); //將生成的緩沖區和求交對象放到一個圖層數組中,在關閉緩沖區分析工具後統一移出系統 flyr.Add(bufferlayer); flyr.Add(pFeatureLayer); //將緩沖區分析的結果放到屬性表中並顯示 ILayer layer = pFeatureLayer as ILayer; FrmAttribute attributeTable = new FrmAttribute(layer, axMapControl1); attributeTable.Show(); //4>在窗體的FormClosing事件中,添加以下代碼 //刪除所有生成的緩沖區和求交對象 foreach (FeatureLayer pFeatureLayer in flyr) { IDataLayer2 OnOff = pFeatureLayer as IDataLayer2; OnOff.Disconnect(); axMapControl1.Map.DeleteLayer(pFeatureLayer); } /* 4.在主窗體中調用此模塊 首先在菜單欄中新建一個選項如“周邊設施分析” 之後雙擊該選項,添加如下代碼 */ buffer b = new buffer(axMapControl1); b.Show(); /* 五、esriAddIn擴展項在ArcEngine中的添加 對原代碼中接口適當修改,使其可用於ArcEngine二次開發工程中 1.在服務中引用“AE開發用”文件夾中的MappingTools.dll 2.菜單欄中創建對應菜單,在單擊事件中加入調用代碼,並在Form1類的頂端填寫using MappingTools; */ //調用創建直方圖時,是在mapcontrol1的onmousedown事件中觸發創建直方圖的函數 //首先到onmousedown中加入如下代碼 if (zhifangtu == 1 && e.button==1)//開啟了直方圖功能且在地圖上單擊了鼠標左鍵時 { Createzft (e.x,e.y); } //之後在Form1主類中加入如下函數 Public void Createzft(int x,int y) { MappingTools.CreateGraph a = new MappingTools.CreateGraph(); frmGraph frm = new frmGraph(this.axMapControl1); frm.BasePoint = axMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y); DialogResult re = frm.ShowDialog(); }

AE二次開發中幾個功能速成歸納(符號設計器、創建要素、圖形編輯、屬性表編輯、緩沖區分析)