3DIdentify查询

在mousedown事件添加如下代码:

private void axSceneControl1_OnMouseDown_1(object sender, ISceneControlEvents_OnMouseDownEvent e) { try { IHit3DSet pHit3DSet; switch (str3DAction) { case "strIdentify": //三维查询 axSceneControl1.SceneGraph.IsNavigating = false; axSceneControl1.SceneGraph.LocateMultiple(axSceneControl1.SceneGraph.ActiveViewer, e.x, e.y, esriScenePickMode.esriScenePickAll, false, out pHit3DSet); //获取Feature,保存在pHit3DSet中 if (pHit3DSet == null) return; pHit3DSet.OnePerLayer(); if (pHit3DSet.Hits.Count == 0) { MessageBox.Show("当前点未能查找到任何要素"); return; } IDisplay3D pDisplay3D = (IDisplay3D)axSceneControl1.Scene.SceneGraph;//用于高亮显示要素 //显示信息窗体 if (m_frmIdentify == null) { m_frmIdentify = new frm3DIdentify(this); m_frmIdentify.pHit3DSet = pHit3DSet; m_frmIdentify.pDisplay3D = pDisplay3D; m_frmIdentify.InitData(); m_frmIdentify.Location = System.Windows.Forms.Cursor.Position; //窗体的左上角坐标为当前鼠标的屏幕坐标 m_frmIdentify.ShowDialog(); // m_frmIdentify.Focus();获得焦点 } else { m_frmIdentify.Activate(); } break; } } catch(Exception ee) {} } 

新建frm3DIdentify窗体,代码如下:

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using ESRI.ArcGIS.Analyst3D; using ESRI.ArcGIS.Geodatabase; using ESRI.ArcGIS.Geometry; using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Display; namespace DXGXGIS.MainGIS { public partial class frm3DIdentify : Form { public IHit3DSet pHit3DSet; public IDisplay3D pDisplay3D; frm3DAnalyst frm3Danalyst = new frm3DAnalyst(); public frm3DIdentify(frm3DAnalyst frm) { InitializeComponent(); frm3Danalyst = frm; } public frm3DIdentify() { InitializeComponent(); } private void frm3DIdentify_Load(object sender, EventArgs e) { } private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { listView1.Items.Clear();//消除 listView1 的内容 if (pHit3DSet == null) return; if (listBox1.SelectedIndex == -1) return; IHit3D pHit3D = (IHit3D)pHit3DSet.Hits.get_Element(listBox1.SelectedIndex); IFeature pFeature = (IFeature)pHit3D.Object; for (int j = 0; j < pFeature.Fields.FieldCount; j++) { ListViewItem li = new ListViewItem(); li.SubItems.Clear(); li.SubItems[0].Text = pFeature.Fields.get_Field(j).Name; li.SubItems.Add(pFeature.get_Value(j).ToString()); listView1.Items.Add(li); } //pDisplay3D.AddFlashFeature(pFeature.Shape); pDisplay3D.FlashGeometry(pHit3D.Owner, pHit3D.Object); } //自己添加的方法,用以初始化窗体。 public void InitData() { listBox1.Items.Clear(); //清除 listBox1 的内容 listView1.Items.Clear(); //清除 listView1 的内容 if (pHit3DSet == null) return; IHit3D pHit3D; IFeature pFeature; for (int i = 0; i < pHit3DSet.Hits.Count; ) { pHit3D = (IHit3D)pHit3DSet.Hits.get_Element(i); IPoint pPoint = pHit3D.Point; ILayer pLayer = (ILayer)pHit3D.Owner; //判断是否为要素图层 if (pLayer is IFeatureLayer) { pFeature = (IFeature)pHit3D.Object; listBox1.Items.Add(pLayer.Name);//在列表中添加图层名 //for (int j = 0; j < pFeature.Fields.FieldCount; j++) // strHits += "/n :" + pFeature.Fields.get_Field(j).Name + pFeature.get_Value(j).ToString(); pDisplay3D.AddFlashFeature(pFeature.Shape); i++; //计数i加1 } else { //不是要素层就从pHit3DSet中删去,因删除后总数减1,计数i不加1 pHit3DSet.Hits.Remove(i); } } pDisplay3D.FlashFeatures(); } private void frm3DIdentify_FormClosed(object sender, FormClosedEventArgs e) { frm3Danalyst.m_frmIdentify = null; } } }  

你可能感兴趣的:(exception,object,ListView,null,Class)