//显示结果集合 public void refeshView(IHit3DSet pHit3Dset) { //用tree控件显示查询结果 mTreeView.BeginUpdate(); //清空tree控件的内容 mTreeView.Nodes.Clear(); IHit3D pHit3D; int i; //遍历结果集 for (i = 0; i < pHit3Dset.Hits.Count; i++) { pHit3D = pHit3Dset.Hits.get_Element(i) as IHit3D; if (pHit3D.Owner is ILayer) { ILayer pLayer = pHit3D.Owner as ILayer; //将图层的名称和坐标显示在树节点中 TreeNode node = mTreeView.Nodes.Add(pLayer.Name); node.Nodes.Add("X=" + pHit3D.Point.X.ToString()); node.Nodes.Add("Y=" + pHit3D.Point.Y.ToString()); node.Nodes.Add("Z=" + pHit3D.Point.Z.ToString()); //将该图层中的所有元素显示在该树节点的子节点 if (pHit3D.Object != null) { if (pHit3D.Object is IFeature) { IFeature pFeature = pHit3D.Object as IFeature; int j; //显示Feature中的内容 for (j = 0; j < pFeature.Fields.FieldCount; j++) { node.Nodes.Add(pFeature.Fields.get_Field(j).Name + ":" + pFeature.get_Value(j).ToString()); } } } } } mTreeView.EndUpdate(); }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { // TODO: Add ToolEditFeatures.OnMouseDown implementation try { ISceneControl pSceneCtr = (((IToolbarControl)m_hookHelper.Hook).Buddy) as ISceneControl; if (pSceneCtr != null) { IPoint po; object owner, obj; pSceneCtr.SceneGraph.Locate(pSceneCtr.SceneViewer, X, Y, esriScenePickMode.esriScenePickGeography, true, out po, out owner, out obj);//po就是得到的点 //方法2 IHit3DSet pHit3dSet = null; pSceneCtr.SceneGraph.LocateMultiple(pSceneCtr.SceneGraph.ActiveViewer, X, Y, esriScenePickMode.esriScenePickGeography, true, out pHit3dSet); //po = pHit3D.Point;//po就是得到的点 //如果想得到某图层元素,可以看看下面代码 // int index = 2; if (pHit3dSet == null) { return; } pHit3dSet.OnePerLayer(); IHit3D pHit3D = (IHit3D)pHit3dSet.Hits.get_Element(0); IFeature pFeature = (IFeature)pHit3D.Object; if (pFeature == null) { return; } ILayer pLayer = owner as ILayer; if (pLayer == null) { return; } if (pLayer.Name != "Crater" && pLayer.Name != "NonCrater") { return; } IFeatureClass pFeatureClass = ((IFeatureLayer)pLayer).FeatureClass; pSceneCtr.Scene.ClearSelection(); pSceneCtr.Scene.SelectFeature(pLayer, pFeature); IActiveView pActiveView = pSceneCtr.Scene as IActiveView; pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, pLayer, null); IMultiPatch pMP = pFeature.Shape as IMultiPatch; FrmEditFeatures.setXLabel((pMP.Envelope.XMax + pMP.Envelope.XMin) / 2); FrmEditFeatures.setYLabel((pMP.Envelope.YMax + pMP.Envelope.YMin) / 2); } IMapControl2 pMapCtr = (((IToolbarControl)m_hookHelper.Hook).Buddy) as IMapControl2; if (pMapCtr != null) { IMap pMap = pMapCtr.Map; IPoint po = pMapCtr.ToMapPoint(X, Y); ISelectionEnvironment pSelectionEnv = new SelectionEnvironmentClass(); pMap.SelectByShape(po, pSelectionEnv, true); //for (int i = 0; i < pMap.LayerCount; i++ ) //{ // ILayer pLayer = pMap.get_Layer(i); // if (pLayer.Name == "Crater") // { // pMapCtr.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, pLayer, null); // } // if (pLayer.Name =="NonCrater") // { // pMapCtr.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, pLayer, null); // } //} pMapCtr.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); IEnumFeatureSetup pSelectionsetup = pMap.FeatureSelection as IEnumFeatureSetup; pSelectionsetup.AllFields = true;//这里是关键 IEnumFeature pFeatureCollection = pSelectionsetup as IEnumFeature; IFeature pF = pFeatureCollection.Next(); if (pF != null && pF.Shape is IMultiPatch) { IMultiPatch pMP = pF.Shape as IMultiPatch; FrmEditFeatures.setXLabel((pMP.Envelope.XMax + pMP.Envelope.XMin) / 2); FrmEditFeatures.setYLabel((pMP.Envelope.YMax + pMP.Envelope.YMin) / 2); } //ISelection pSelection =pMap.FeatureSelection; ////从Map.FeatureSelection获得ISelection不能读到Feature的其他属性, ////这是因为从axMapControl1.Map.FeatureSelection QI到IEnumFeature 时, ////ArcGIS中FeatureSelection默认的时候只存入Feature 的Shape,而不是整个Feature的字段数据。 ////如果要查看其他数据,必须要进行以下转换才可以: //IEnumFeatureSetup pSelectionsetup = pSelection as IEnumFeatureSetup; //pSelectionsetup.AllFields = true;//这里是关键 //IEnumFeature pFeatureCollection = pSelectionsetup as IEnumFeature; //IFeature pF = pFeatureCollection.Next(); //if (pF != null) //{ // pF.Class //} } } catch (System.Exception ex) { } }