属性信息.cs
上传用户:xianghe012
上传日期:2022-07-02
资源大小:77k
文件大小:3k
源码类别:

GIS编程

开发平台:

C#

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using ESRI.ArcGIS.esriSystem;
  9. using ESRI.ArcGIS.SystemUI;
  10. using ESRI.ArcGIS.Geometry;
  11. using ESRI.ArcGIS.Display;
  12. using ESRI.ArcGIS.Geodatabase;
  13. using ESRI.ArcGIS.Carto;
  14. using ESRI.ArcGIS.Controls;
  15. namespace ArcMap
  16. {
  17.     public partial class frmProperty : Form
  18.     {
  19.         public IMapControl2 pMapControl;
  20.         public IEnvelope pEnvelop;
  21.         public frmProperty(IMapControl2 pFMapControl, IEnvelope pFEnvelop)
  22.         {
  23.             InitializeComponent();
  24.             pMapControl = pFMapControl;
  25.             pEnvelop = pFEnvelop;
  26.         }
  27.         public void SelectPropertyViaFeature()
  28.         {
  29.             trViewProperty.Nodes.Clear();
  30.             for (int i = 0; i < pMapControl.Map.LayerCount; i++)
  31.             {
  32.                 IFeatureLayer pFeatureLayer = (IFeatureLayer)pMapControl.Map.get_Layer(i);
  33.                 IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
  34.                 ISpatialFilter pSpatialFilter = new SpatialFilterClass();
  35.                 pSpatialFilter.Geometry = pEnvelop;
  36.                 pSpatialFilter.GeometryField = pFeatureClass.ShapeFieldName;
  37.                 pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
  38.                 IFields pFields = pFeatureClass.Fields;
  39.                 IFeatureCursor pFeatureCursor = pFeatureClass.Search(pSpatialFilter, false);
  40.                 TreeNode nodeParent;
  41.                 IFeature pFeature;
  42.                 pFeature = pFeatureCursor.NextFeature();
  43.                 if (pFeature != null)
  44.                 {
  45.                     nodeParent = trViewProperty.Nodes.Add(pFeatureLayer.Name.ToString());
  46.                     while (pFeature != null)
  47.                     {
  48.                         TreeNode nodeSon;
  49.                         for (int j = 0; j < pFields.FieldCount; j++)
  50.                         {
  51.                             string fldValue;
  52.                             string fldName;
  53.                             fldName = pFields.get_Field(j).Name;
  54.                             if (fldName == "Shape")
  55.                             {
  56.                                 fldValue = Convert.ToString(pFeature.Shape.GeometryType);
  57.                             }
  58.                             else
  59.                                 fldValue = Convert.ToString(pFeature.get_Value(j));
  60.                             //if (j == 0)
  61.                             //{
  62.                                 nodeSon = nodeParent.Nodes.Add(fldValue);
  63.                             //}
  64.                             //else
  65.                             //    nodeSon.Nodes.Add(fldValue);
  66.                         }
  67.                         pMapControl.Map.SelectFeature(pFeatureLayer, pFeature);
  68.                         pFeature = pFeatureCursor.NextFeature();
  69.                     }
  70.                 }
  71.             }
  72.             IActiveView pActiveView;
  73.             pActiveView = (IActiveView)pMapControl.Map;
  74.             pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
  75.         }
  76.         private void frmProperty_Load(object sender, EventArgs e)
  77.         {
  78.             SelectPropertyViaFeature();
  79.         }
  80.     }
  81. }