C#不用ArcEngine,生成Shp文件(二)---------读取.shp文件格式

本文介绍如何在C#中读取.shp文件,以面文件为例,通过代码演示读取过程,包括文件长度、坐标、几何类型等关键信息的解析,并提供了位序转换函数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

上一篇介绍了Shape files文件结构,在这一篇,以面文件为例,写一下如何读取.shp文件,以面文件为例。

首先在ArcMap里面新建一个名为  三角形面   的 shp文件,用做测试数据。如下

测试数据下载地址为:http://download.youkuaiyun.com/detail/gis0911178/9650967

在Arcmap中显示如下

测试数据准备好之后,就可以在C#里面写代码来读取这个shp文件;代码如下

private void button1_Click(object sender, EventArgs e)
        {
            string shpfilepath = "";
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.Filter = "shapefile(*.shp)|*.shp|All files(*.*)|*.*"; //打开文件路径
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                shpfilepath = openFileDialog1.FileName;
                BinaryReader br = new BinaryReader(openFileDialog1.OpenFile());


                //读取文件过程
                br.ReadBytes(24);
                int FileLength = br.ReadInt32();
                Console.WriteLine("文件长度:" + ChangeByteOrder(FileLength));
                int FileBanben = br.ReadInt32();
                ShapeType = br.ReadInt32();
                xmin = br.ReadDouble();
                ymin = br.ReadDouble();
                xmax = br.ReadDouble();
                ymax = br.ReadDouble();
                Console.WriteLine("Xmin:" + xmin);
                Console.WriteLine("Ymin:" + ymin);
                Console.WriteLine("Xmax:" + xmax);
                Console.WriteLine("Ymax:" + ymax);
                double width = xmax - xmin;
                double height = ymax - ymin;
                n1 = (float)(this.panel1.Width * 0.9 / width);//x轴放大倍数
                n2 = (float)(this.panel1.Height * 0.9 / height);//y轴放大倍数
                br.ReadBytes(32);


                switch (ShapeType)
                {
                    case 1:
                        points.Clear();
                        while (br.PeekChar() != -1)
                        {
                            Poi

评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值