frmTable.cs
资源名称:arcMAP.rar [点击查看]
上传用户:xianghe012
上传日期:2022-07-02
资源大小:77k
文件大小:4k
源码类别:
GIS编程
开发平台:
C#
- 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.SystemUI;
- using ESRI.ArcGIS.Geometry;
- using ESRI.ArcGIS.Display;
- using ESRI.ArcGIS.Geodatabase;
- using ESRI.ArcGIS.Carto;
- using ESRI.ArcGIS.Controls;
- namespace ArcMap
- {
- public partial class frmTable : Form
- {
- public IMapControl2 pMapControl;
- public IMap pMap;
- public int iLayerIndex;
- public string LayerName;
- public frmTable(IMapControl2 pFMapControl,string LyrName)
- {
- InitializeComponent();
- pMapControl=pFMapControl;
- pMap = pMapControl.Map;
- LayerName = LyrName;
- }
- private void frmTable_Load(object sender, EventArgs e)
- {
- GetAllValues();
- }
- //获取属性表的内容
- public void GetAllValues()
- {
- IFeatureLayer pFeatureLayer;
- for (int i = 0; i <pMap.LayerCount;i++ )
- {
- if (LayerName==pMap.get_Layer(i).Name)
- {
- iLayerIndex = i;
- break;
- }
- }
- pFeatureLayer = (IFeatureLayer)pMap.get_Layer(iLayerIndex);
- IFields pFields;
- pFields = pFeatureLayer.FeatureClass.Fields;
- dtGridView.ColumnCount = pFields.FieldCount;
- for (int i = 0; i < pFields.FieldCount;i++ )
- {
- string fldName;
- fldName = pFields.get_Field(i).Name;
- dtGridView.Columns[i].Name = fldName;
- }
- IFeatureCursor pFeatureCursor;
- pFeatureCursor = pFeatureLayer.FeatureClass.Search(null, false);
- long lTotalRecords=1;
- IFeature pFeature;
- pFeature = pFeatureCursor.NextFeature();
- while (pFeature != null)
- {
- string[] fldValue = new string[pFields.FieldCount];
- for (int i = 0; i < pFields.FieldCount; i++)
- {
- string fldName;
- fldName = pFields.get_Field(i).Name;
- if (fldName=="Shape")
- {
- fldValue[i] = Convert.ToString(pFeature.Shape.GeometryType);
- }
- else
- fldValue[i] = Convert.ToString(pFeature.get_Value(i));
- }
- dtGridView.Rows.Add(fldValue);
- pFeature = pFeatureCursor.NextFeature();
- lTotalRecords++;
- }
- tbarTotalRecords.Text = "共有" + Convert.ToString(lTotalRecords - 1) + "条记录";
- }
- private void dtGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
- {
- string FID;
- FID = dtGridView.Rows[e.RowIndex].Cells[0].Value.ToString();
- if (FID == "")
- return;
- IActiveView pActiveView;
- pActiveView = (IActiveView)pMap;
- pMap.ClearSelection();
- pActiveView.Refresh();
- IQueryFilter pQueryFilter = new QueryFilterClass();
- pQueryFilter.WhereClause = "FID=" + FID;
- IFeatureLayer pFeatureLayer;
- pFeatureLayer =(IFeatureLayer)pMap.get_Layer(iLayerIndex);
- IFeatureCursor pFeatureCursor;
- pFeatureCursor = pFeatureLayer.Search(pQueryFilter, false);
- IFeature pFeature;
- pFeature = pFeatureCursor.NextFeature();
- pMap.SelectFeature(pFeatureLayer, pFeature);
- IPoint pPoint = new PointClass();
- pPoint.X = (pFeature.Extent.XMin + pFeature.Extent.XMax) / 2;
- pPoint.Y = (pFeature.Extent.YMin + pFeature.Extent.YMax) / 2;
- pMapControl.CenterAt(pPoint);
- pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
- }
- }
- }