arcgis_engine二次开发——提高篇

上传人:飞*** 文档编号:35852412 上传时间:2018-03-21 格式:DOC 页数:77 大小:1.48MB
返回 下载 相关 举报
arcgis_engine二次开发——提高篇_第1页
第1页 / 共77页
arcgis_engine二次开发——提高篇_第2页
第2页 / 共77页
arcgis_engine二次开发——提高篇_第3页
第3页 / 共77页
arcgis_engine二次开发——提高篇_第4页
第4页 / 共77页
arcgis_engine二次开发——提高篇_第5页
第5页 / 共77页
点击查看更多>>
资源描述

《arcgis_engine二次开发——提高篇》由会员分享,可在线阅读,更多相关《arcgis_engine二次开发——提高篇(77页珍藏版)》请在金锄头文库上搜索。

1、ArcGIS Engine 高级功能开发ArcGIS Engine 二次开发二次开发 提高篇提高篇ArcGIS Engine 高级功能开发1 1缩略图缩略图( (鹰眼鹰眼) )鹰眼功能是 GIS 的主要功能之一,当地图范围很大时,它可以很好的为用户指明当前 地图的范围。在本小节中我们将学习如何制作这种鹰眼。1.11.1 添加控件添加控件新建一个 C#.Net 项目,项目名称为 OverView,将 Form1 的名字设置为 MainForm,并 添加 ToolbarControl 、两个 MapControl 和 LicenceControl 等四个控件。布局如下图所示。 左边的 axMapC

2、ontrol1 用于地图数据显示和操作,右边 axMapControl2 用于鹰眼显示。图 1 界面布局在 ToolbarControl 加载添加数据按钮和地图浏览的功能按钮,如下图所示,并将 ToolbarControl 的伙伴控件设为 axMapControl1。图 2 添加按钮1.21.2 代码添加及解释代码添加及解释鹰眼用来显示主窗体当前视图范围在全景视图中的位置,在 ArcMap 中使用一个线框 在鹰眼视图中标识。当主视图中的视图范围改变时,鹰眼中的线框随之改变,当拖动鹰眼 视图中的红线框时,主视图中的视图范围也随之改变。 下面开始实现鹰眼功能,添加 using ESRI.ArcGI

3、S.Carto、using ESRI.ArcGIS.Geometry、 using ESRI.ArcGIS.Display 三个引用。首先在 axMapControl1 中视图范围改变时鹰眼窗体要做 出对应的响应,即绘制线框并显示,在 OnExtentUpdated 事件中添加代码如下:private void axMapControl1_OnExtentUpdated(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnExtentUpdatedEvent e)/创建鹰眼中线框IEnvelope pEnv = (IEnvelope

4、)e.newEnvelope;IRectangleElement pRectangleEle = new RectangleElementClass();IElement pEle = pRectangleEle as IElement;pEle.Geometry = pEnv;/设置线框的边线对象,包括颜色和线宽IRgbColor pColor = new RgbColorClass();pColor.Red = 255;pColor.Green = 0;pColor.Blue = 0;pColor.Transparency = 255;/ 产生一个线符号对象 ILineSymbol pOu

5、tline = new SimpleLineSymbolClass();pOutline.Width = 2;pOutline.Color = pColor;/ 设置颜色属性 pColor.Red = 255;pColor.Green = 0;pColor.Blue = 0;pColor.Transparency = 0;/ 设置线框填充符号的属性 IFillSymbol pFillSymbol = new SimpleFillSymbolClass();pFillSymbol.Color = pColor;pFillSymbol.Outline = pOutline;IFillShapeEl

6、ement pFillShapeEle = pEle as IFillShapeElement;pFillShapeEle.Symbol = pFillSymbol;/ 得到鹰眼视图中的图形元素容器IGraphicsContainer pGra = axMapControl2.Map as IGraphicsContainer;IActiveView pAv = pGra as IActiveView;/ 在绘制前,清除 axMapControl2 中的任何图形元素 pGra.DeleteAllElements();/ 鹰眼视图中添加线框pGra.AddElement(IElement)pFi

7、llShapeEle, 0);/ 刷新鹰眼pAv.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); 当鼠标点击鹰眼窗体时,主窗体 Extent 随之改变。在 axMapControl2 的 OnMouseDown 事件中添加代码如下:private void axMapControl2_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)if (this.axMapControl2.Map.Laye

8、rCount != 0)/ 按下鼠标左键移动矩形框 if (e.button = 1)IPoint pPoint = new PointClass();pPoint.PutCoords(e.mapX, e.mapY);IEnvelope pEnvelope = this.axMapControl1.Extent;pEnvelope.CenterAt(pPoint);this.axMapControl1.Extent = pEnvelope;this.axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeograp

9、hy, null, null);/ 按下鼠标右键绘制矩形框 else if (e.button = 2)IEnvelope pEnvelop = this.axMapControl2.TrackRectangle();this.axMapControl1.Extent = pEnvelop;this.axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);当鼠标在鹰眼窗体移动时,主窗体 Extent 随之改变。在 axMapControl2 的 OnMouseMove 事件

10、中添加代码如下:private void axMapControl2_OnMouseMove(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseMoveEvent e)/ 如果不是左键按下就直接返回 if (e.button != 1) return;IPoint pPoint = new PointClass();pPoint.PutCoords(e.mapX, e.mapY);this.axMapControl1.CenterAt(pPoint);this.axMapControl1.ActiveView.Parti

11、alRefresh(esriViewDrawPhase.esriViewGeography, null, null);下面代码用于实现 axMapControl2 与 axMapControl1 的数据的同步更新,获取主视图 中视图范围最大的图层作为鹰眼中的视图。这个更新由两部分组成,一个是对 axMapControl1 添加地图文档(mxd 文件)的响应,通过 axMapControl1 的 OnMapReplace 事件实现,一个是对 axMapControl1 添加单个图层的响应,通过 axMapControl1 的 OnFullExtentUpdated 事件实现。我们获取主视图中的视

12、图范围最大的图层写成一个独立的 函数,方便调用。private ILayer GetOverviewLayer(IMap map)/获取主视图的第一个图层ILayer pLayer = map.get_Layer(0);/遍历其他图层,并比较视图范围的宽度,返回宽度最大的图层ILayer pTempLayer = null;for (int i = 1; i 0)cboLayers.SelectedIndex = 0;/设置生成文件的默认输出路径和名称string tempDir = “D:Temp“;txtOutputPath.Text = System.IO.Path.Combine(te

13、mpDir, (string)cboLayers.SelectedItem + “_buffer.shp“);ArcGIS Engine 高级功能开发/设置默认地图单位lblUnits.Text = Convert.ToString(mHookHelper.FocusMap.MapUnits);双击路径设置按钮,进入代码编辑界面,添加如下代码:private void btnOutputLayer_Click(object sender, EventArgs e)/定义输出文件路径SaveFileDialog saveDlg = new SaveFileDialog();/检查路径是否存在sa

14、veDlg.CheckPathExists = true;saveDlg.Filter = “Shapefile (*.shp)|*.shp“;/保存时覆盖同名文件saveDlg.OverwritePrompt = true;saveDlg.Title = “输出路径“;/对话框关闭前还原当前目录saveDlg.RestoreDirectory = true;saveDlg.FileName = (string)cboLayers.SelectedItem + “_buffer.shp“;/读取文件输出路径到txtOutputPathDialogResult dr = saveDlg.Show

15、Dialog();if (dr = DialogResult.OK)txtOutputPath.Text = saveDlg.FileName;双击“分析”按钮,添加代码如下:private void btnBuffer_Click(object sender, EventArgs e)/缓冲距离double bufferDistance;/输入的缓冲距离转换为doubledouble.TryParse(txtBufferDistance.Text.ToString(),out bufferDistance);/判断输出路径是否合法if (!System.IO.Directory.Exists

16、(System.IO.Path.GetDirectoryName(txtOutputPath.Text) |“.shp“ != System.IO.Path.GetExtension(txtOutputPath.Text)MessageBox.Show(“输出路径错误!“);return;/判断图层个数ArcGIS Engine 高级功能开发if (mHookHelper.FocusMap.LayerCount = 0)return;/获取图层IFeatureLayer pFeatureLayer = GetFeatureLayer(string)cboLayers.SelectedItem);if (null = pFeatureLayer)MessageBox.Show(“图层“ + (string)cboLayers.SelectedItem + “不存在!rn“);return;/获取一个geoprocessor的实例Geoproce

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 商业/管理/HR > 企业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号