




已阅读5页,还剩2页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
首先新建一个WInForm,然后向其中添加一个combobox,一个DataGridView,以及label、statusbar等(界面使用第三方控件制作而成),combobox用于显示所有的图层,statusbar显示查询到的要素的字段个数以及鼠标点击处的坐标。 代码如下:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using ESRI.ArcGIS.esriSystem;using ESRI.ArcGIS.Carto;using ESRI.ArcGIS.Geometry;using ESRI.ArcGIS.Controls;using ESRI.ArcGIS.Display;using ESRI.ArcGIS.SystemUI;using ESRI.ArcGIS.Geodatabase;using ESRI.ArcGIS.DataSourcesRaster;namespace Tools public partial class frmIdentify : Form AxMapControl axMapControl = null; IFeature pFeature; int selectedIndex = 0; public frmIdentify(ESRI.ArcGIS.Controls.AxMapControl axmapcontrol) InitializeComponent(); this.axMapControl = axmapcontrol; /设置axmapcontrol的CurrentTool属性为空,更改鼠标样式 axmapcontrol.CurrentTool = null; axmapcontrol.MousePointer = ESRI.ArcGIS.Controls.esriControlsMousePointer.esriPointerIdentify; private void frmIdentify_Load(object sender, EventArgs e) for (int i = 0; i axMapControl.LayerCount; i+) comboBox1.Items.Add(axMapControl.get_Layer(i).Name.ToString(); /设置dataGridView1的列数和列头 dataGridView1.ColumnCount = 2; dataGridView1.RowHeadersWidth = 60; dataGridView1.TopLeftHeaderCell.Value = 属性表; dataGridView1.Columns0.HeaderText = 字段; dataGridView1.Columns1.HeaderText = 属性值; comboBox1.SelectedIndex = 0; dataGridView1.Columns1.Width = dataGridView1.Width - dataGridView1.Columns0.Width - 63; /设置dataGridView1 、textBox1不可编辑 dataGridView1.ReadOnly = true; public void OnMouseDown(int button, double x, double y) if (axMapControl.get_Layer(selectedIndex) is IRasterLayer) IPoint pMouseDownPoint; pMouseDownPoint = new PointClass(); pMouseDownPoint.PutCoords(x, y); pMouseDownPoint.SpatialReference = axMapControl.Map.SpatialReference; ExcuteIdentifyByPoint(pMouseDownPoint); else dataGridView1.Refresh(); uiStatusBar1.Refresh(); IEnvelope pEnvelope = null; pEnvelope = axMapControl.TrackRectangle(); /当仅点击鼠标,没有拖动时 if (pEnvelope.IsEmpty = true) IPoint pMouseDownPoint; pMouseDownPoint = new PointClass(); pMouseDownPoint.PutCoords(x, y); pMouseDownPoint.SpatialReference = axMapControl.Map.SpatialReference; IGeometry bufGeo; ITopologicalOperator bufferPoint = pMouseDownPoint as ITopologicalOperator; bufGeo = bufferPoint.Buffer(axMapControl.ActiveView.Extent.Width / 250); pEnvelope = bufGeo.Envelope; ExcuteIdentifyByEnvelope(pEnvelope); else ExcuteIdentifyByEnvelope(pEnvelope); ShowLocation(x, y, (int)(axMapControl.MapUnits); # region 显示当前坐标 public void ShowLocation(double x, double y, int unit) string strUnit = null; switch (unit) case 0: strUnit = 未知单位; break; case 1: strUnit = 英尺; break; case 2: strUnit = 像素; break; case 3: strUnit = 步; break; case 4: strUnit = 码; break; case 5: strUnit = 英里; break; case 6: strUnit = 海里; break; case 7: strUnit = 毫米; break; case 8: strUnit = 厘米; break; case 9: strUnit = 米; break; case 10: strUnit = 千米; break; case 11: strUnit = 度; break; case 12: strUnit = 分米; break; case 13: strUnit = esriUnitLast; break; default: strUnit = ; break; /textBox1.Text = X: + x.ToString().Substring(0,x.ToString().LastIndexOf(.)+5) + +strUnit+ , Y: + y.ToString().Substring(0,y.ToString().LastIndexOf(.)+5) + + strUnit; this.uiStatusBar1.Panels1.Text = X: + x.ToString(#.#) + strUnit + , Y: + y.ToString(#.#) + strUnit; # endregion private void uiButton1_Click(object sender, EventArgs e) if (pFeature.Shape.GeometryType = esriGeometryType.esriGeometryPoint) IGeometry bufferGeo; ITopologicalOperator buffer = pFeature.ShapeCopy as ITopologicalOperator; bufferGeo = buffer.Buffer(1000); axMapControl.Extent = bufferGeo.Envelope; else axMapControl.Extent = pFeature.Extent; axMapControl.Refresh(); axMapControl.FlashShape(pFeature.ShapeCopy, 2, 10, null); private void dataGridView1_SizeChanged_1(object sender, EventArgs e) dataGridView1.Columns1.Width = dataGridView1.Width - dataGridView1.Columns0.Width; private void frmIdentify_FormClosed_2(object sender, FormClosedEventArgs e) axMapControl.MousePointer = ESRI.ArcGIS.Controls.esriControlsMousePointer.esriPointerArrow; private void comboBox1_SelectedIndexChanged_1(object sender, EventArgs e) dataGridView1.Rows.Clear(); this.uiStatusBar1.Panels1.Text = 坐标:; this.uiStatusBar1.Panels0.Text = 查询; this.uiStatusBar1.Refresh(); selectedIndex = comboBox1.SelectedIndex; # region 查询 IArray pIDArray; /通过点Envelope进行查询 private void ExcuteIdentifyByEnvelope(IEnvelope identifyenvelope) IIdentify pIdentify; IFeatureIdentifyObj pFeatureIdentifyObj; IIdentifyObj pIdentifyObj; pIdentify = axMapControl.Map.get_Layer(selectedIndex) as IIdentify; pIDArray = pIdentify.Identify(identifyenvelope); /MessageBox.Show(OnMouseDown Method); if (pIDArray != null) pFeatureIdentifyObj = pIDArray.get_Element(0) as IFeatureIdentifyObj; pIdentifyObj = pFeatureIdentifyObj as IIdentifyObj; pIdentifyObj.Flash(axMapControl.ActiveView.ScreenDisplay); pFeature = (pIDArray.get_Element(0) as IRowIdentifyObject).Row as IFeature; ShowAttribute(pFeature); else dataGridView1.Rows.Clear(); this.uiStatusBar1.Panels0.Text = 提示: 没有查询到任何要素!; /通过点进行查询 private void ExcuteIdentifyByPoint(IPoint point) IIdentify pIdentify; IArray pIDArray; IRasterLayer pRasterLayer; IRaster pRaster; pRasterLayer = axMapControl.get_Layer(selectedIndex) as IRasterLayer; pRaster = pRasterLayer.Raster; pIdentify = pRasterLayer as IIdentify; pIDArray = pIdentify.Identify(point); IRasterIdentifyObj pRasterIObj; pRasterIObj = pIDArray.get_Element(0) as IRasterIdentifyObj; dataGridView1.ColumnCount = 2; for (int i = 0; i pIDArray.Count; i+) if (axMapControl.get_Layer(selectedIndex).Name = 自治区遥感底图) dataGridView10, i.Value = 影像象元值; else dataGridView10, i.Value = pRasterLayer.Name.ToString(); dataGridView11, i.Value = pRasterIObj.MapTip.ToString(); # endregion # region ShowAttribute方法 显示属性表 public void ShowAttribute(IFeature feature) int num = feature.Fields.FieldCount; dataGridView1.RowCount = num; for (int i = 0; i num; i+) dataGridView1.Rowsi.HeaderCell.Value = i.ToString(); dataGridView10, i.Value = feature.Fields.get_Field(i).Name.ToString(); if (feature.Fields.get_Field(i).Type = esriFieldType.esriFieldTypeGeometry) string type = feature.Shape.GeometryType.ToString(); switch (type) case esriGeometryPoint: dataGridView11, i.Value = 点; break; case esriGeometryPolyline: dataGridView11, i.Value = 线; break; case esriGeometryPolygon: dataGridView11, i.Value = 面;
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年规划投资专业考试题库及答案
- 2025年广西中小学教师招聘考试教育综合知识试题及答案解析
- 化验员基础考试题及答案
- 芜职美育课考试题及答案
- 东北三省二模考试试题及答案
- 《科目一》机动车驾驶员考试试题与参考答案(2025年)
- 人力六大模块笔试题及答案
- 心力衰竭中医护理试题及答案2025年解析
- 渠道经理笔试题库及答案
- 2025年一建建筑工程真题答案21
- 裂纹损伤容限评估技术
- 居民公约工作总结
- 大学研究生录取分析报告
- 骨科疾病的深度学习研究
- 社区零星维修工程投标方案(技术标)
- 绿植租摆服务投标方案(完整技术标)
- 高考英语典型看图作文(标准范文及高分范文)
- 《流水地貌》教学设计-湘教版必修一
- 矿山安全培训课件-地下矿山开采安全技术
- GB/T 26716-2023钟表防磁手表
- 抑郁病诊断证明书
评论
0/150
提交评论