(续)AE中读取所打开shp的属性表

本文详细介绍了如何使用ArcGIS框架处理.shp文件,包括关联图层和要素类,以及如何进行数据的拆箱和装载,最终在dataGridView控件中展示属性数据。
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.Controls;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geodatabase;
namespace addshp
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();            
        }
        private AxMapControl m_MapCtl;
        public Form2(AxMapControl pMapCtl)
        {
            InitializeComponent();
            m_MapCtl = pMapCtl;
        }


        //private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        //{


        //}


        private void Form2_Load(object sender, EventArgs e)
        {
            ILayer PLayer = m_MapCtl.get_Layer(0);
            IFeatureLayer pFLay = PLayer as IFeatureLayer;
            IFeatureClass pFC = pFLay.FeatureClass;
            //关联图层和要素类
            //shp 的拆箱过程(自定义)


            IFeatureCursor pFcursor = pFC.Search(null, false);
            IFeature pFeature = pFcursor.NextFeature();
            //定义属性表一个指针
            //指针指向第一条记录


            DataTable pTable = new DataTable();
            DataColumn colName = new DataColumn("Name");
            colName.DataType = System.Type.GetType("System.String");
            pTable.Columns.Add(colName);
            //创建Column1(字段名、属性)


            DataTable pTable2 = new DataTable();
            DataColumn colName2 = new DataColumn("Area");
            colName.DataType = System.Type.GetType("System.String");
            pTable.Columns.Add(colName2);
            //创建Column2(字段名、属性)


            int indexofName = pFC.FindField("Name");
            int indexofName2 = pFC.FindField("Area");


            while (pFeature != null)
            {
                string name = pFeature.get_Value(indexofName).ToString();
                string name2 = pFeature.get_Value(indexofName2).ToString();


                DataRow pRow = pTable.NewRow();
                pRow[0] = name;
                pRow[1] = name2;
                pTable.Rows.Add(pRow);
                //新建行
                //装入数据
                //完成装载,把新行Add入数据表


                pFeature = pFcursor.NextFeature();
                //指针下移,直到遍历所有记录
            }
            dataGridView1.DataSource = pTable;
            //在dataGridView中显示pTable
        }
    }
}
转载于AE入门基础教程示例

评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值