DXF文件的点、线读取

#region DXF输入
        private FileStream fs;
        private StreamReader sr;
        private string[] str = new string[2];
        public List<PointD> pointList=new List<PointD> ();
        public List<PointD[]> linePointList = new List<PointD[]>();
        public void ReadDXF(string inputDXFPath)
        {
            fs = new FileStream(inputDXFPath, FileMode.Open, FileAccess.Read);
            sr = new StreamReader(fs);
            Read();
        }
        //读取编码与值
        private string[] ReadPair()
        {
            string[] result = new string[2];
            result[0] = sr.ReadLine().Trim();
            result[1] = sr.ReadLine().Trim();
            return result;
        }

        private void Read()
        {
            while (sr.Peek()!=-1)
            {
                str = ReadPair();
                if (str[1]=="SECTION")
                {
                    str = ReadPair();
                    switch (str[1])
                    {
                        case "ENTITIES": ReadEntities();
                            break;
                        default:
                            break;
                    }
                }
            }
            sr.Close();
            fs.Close();
        }
        //读取实体
        private void ReadEntities()
        {
            while (str[1]!="ENDSEC")
            {
                switch (str[1])
                {
                    case "LINE": ReadLINE();
                        break;
                    case "POINT": ReadPoint();
                        break;
                    default: str = ReadPair();
                        break;
                }
            }
        }

        //读取LINE
        private void ReadLINE()
        {
            PointD[] line = new PointD[2];
            line[0] = new PointD();
            line[1] = new PointD();
            str = ReadPair();
            while (str[0]!="0")
            {
                str = ReadPair();
                switch (str[0])
                {
                    case "10": line[0].distance = Convert.ToDouble(str[1]);
                        break;
                    case "20": line[0].elev = Convert.ToDouble(str[1]);
                        break;
                    case "11": line[1].distance = Convert.ToDouble(str[1]);
                        break;
                    case "21": line[1].elev = Convert.ToDouble(str[1]);
                        break;
                    default:
                        break;
                }
            }
            linePointList.Add(line);
        }

        //读取POINT
        private void ReadPoint()
        {
            PointD point = new PointD();
            str = ReadPair();
            while (str[0] != "0")
            {
                str = ReadPair();
                switch (str[0])
                {
                    case "10": point.distance = Convert.ToDouble(str[1]);
                        break;
                    case "20": point.elev = Convert.ToDouble(str[1]);
                        break;
                    default:
                        break;
                }
            }
            pointList.Add(point);
        }
        #endregion


    }

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值