Esempio n. 1
0
 /// <summary>
 /// 读取record数据
 /// 当读取时文件流位置在第一个记录处
 /// </summary>
 /// <param name="reader">shx文件流</param>
 public void Read(BinaryReader reader)
 {
     //如果header为空先读取header shp和shx的文件头一样
     if (mHeader == null)
     {
         mHeader.Read(reader);
     }
     if (mRecordDic != null)
     {
         mRecordDic.Clear();
     }
     else
     {
         mRecordDic = new Dictionary <ulong, ShxData>();
     }
     if (reader.BaseStream.Position == 0)
     {
         reader.BaseStream.Seek(100, SeekOrigin.Begin);//跳过文件头
     }
     while (reader.PeekChar() != -1)
     {
         ShxData item           = new ShxData();
         int     Offset         = reader.ReadInt32();
         int     ContentLength  = reader.ReadInt32();
         ulong   uOffset        = ByteTransUtil.big2little(Offset);        //
         ulong   uContentLength = ByteTransUtil.big2little(ContentLength); //
         item.Offset        = (int)uOffset;                                //
         item.ContentLength = (int)uContentLength;
         mRecordDic.Add((ulong)(mRecordDic.Count + 1), item);              //key值从1开始
     }
 }
Esempio n. 2
0
        /// <summary>
        /// 读取header数据
        /// 确定读取时文件流位置在开始处
        /// 当读取完成文件流位置在第一个记录处
        /// </summary>
        /// <param name="reader"></param>
        public void Read(BinaryReader reader)
        {
            // type of reader.

            mFileCode = reader.ReadInt32();
            mFileCode = (int)ByteTransUtil.big2little(mFileCode);
            reader.ReadBytes(20);                                     //预留5个inter
            mFileLength = reader.ReadInt32();
            mFileLength = (int)ByteTransUtil.big2little(mFileLength); //以字为单位,一字等于2字节,等于16位

            mVersion = reader.ReadInt32();
            int typeTemp = reader.ReadInt32();

            mGeoType = (ShapeType)typeTemp;//目前考虑点 线 面三种
            mXmin    = reader.ReadDouble();
            mYmin    = reader.ReadDouble();
            mXmax    = reader.ReadDouble();
            mYmax    = reader.ReadDouble();
            mZmin    = reader.ReadDouble();
            mZmax    = reader.ReadDouble();
            mMmin    = reader.ReadDouble();
            mMmax    = reader.ReadDouble();
        }
Esempio n. 3
0
        /// <summary>
        /// 读取record数据
        /// 当读取时文件流位置在第一个记录处
        /// </summary>
        /// <param name="reader"></param>
        public void Read(BinaryReader reader)
        {
            //如果header为空先读取header
            if (mHeader == null)
            {
                mHeader.Read(reader);
            }
            if (mRecordDic != null)
            {
                mRecordDic.Clear();
            }
            else
            {
                mRecordDic = new Dictionary <ulong, ShpData>();
            }
            //目前只考虑点线面三种类型
            switch (mHeader.GeoType)
            {
            case ShapeType.Point:
                while (reader.PeekChar() != -1)
                {
                    EVPoint point      = new EVPoint();
                    uint    RecordNum  = reader.ReadUInt32();
                    int     DataLength = reader.ReadInt32();
                    ulong   uRecordNum = ByteTransUtil.big2little((int)RecordNum); //读取第i个记录
                    //每一条的记录长度没有考虑RecordNum、DataLength 所以比实际长度少4字
                    int uDataLength = (int)ByteTransUtil.big2little(DataLength);   //以字为单位,一字等于2字节,等于16位 长度不包括uRecordNum和uDataLength
                    int geoType     = reader.ReadInt32();                          //每一个对象的类型 没有用!
                    point.RecordNum  = uRecordNum;
                    point.DataLength = uDataLength;                                //固定10字 没有考虑RecordNum、DataLength 比实际长度少4字
                    point.GeoType    = ShapeType.Point;

                    point.X = reader.ReadDouble();
                    point.Y = reader.ReadDouble();    //
                    ShpData item = new ShpData();
                    item.GeoShape = point;
                    mRecordDic.Add(uRecordNum, item);
                }
                break;

            case ShapeType.PolyLine:
                while (reader.PeekChar() != -1)
                {
                    EVPolyLine polyline = new EVPolyLine();
                    polyline.Parts  = new ArrayList();
                    polyline.Points = new ArrayList();

                    uint  RecordNum  = reader.ReadUInt32(); //读取第i个记录 从1开始算
                    ulong uRecordNum = ByteTransUtil.big2little((int)RecordNum);
                    int   DataLength = reader.ReadInt32();  //以字为单位,一字等于2字节,等于16位
                    //每一条的记录长度没有考虑RecordNum、DataLength 所以比实际长度少4字
                    int uDataLength = (int)ByteTransUtil.big2little(DataLength);
                    int geoType     = reader.ReadInt32();//每一个对象的类型 没有用

                    polyline.RecordNum  = uRecordNum;
                    polyline.DataLength = uDataLength;    //没有考虑RecordNum、DataLength 比实际长度少4字
                    polyline.GeoType    = ShapeType.PolyLine;

                    polyline.Xmin      = reader.ReadDouble();
                    polyline.Ymin      = reader.ReadDouble();
                    polyline.Xmax      = reader.ReadDouble();
                    polyline.Ymax      = reader.ReadDouble();
                    polyline.NumParts  = reader.ReadInt32();
                    polyline.NumPoints = reader.ReadInt32();
                    for (int i = 0; i < polyline.NumParts; i++)
                    {
                        int parts = new int();
                        parts = reader.ReadInt32();
                        polyline.Parts.Add(parts);
                    }
                    for (int j = 0; j < polyline.NumPoints; j++)
                    {
                        EVPoint pointtemp = new EVPoint();
                        pointtemp.X = reader.ReadDouble();
                        pointtemp.Y = reader.ReadDouble();
                        polyline.Points.Add(pointtemp);
                    }
                    ShpData item = new ShpData();
                    item.GeoShape = polyline;
                    mRecordDic.Add(uRecordNum, item);
                }
                break;

            case ShapeType.Polygon:
                while (reader.PeekChar() != -1)
                {
                    EVPolygon polygon = new EVPolygon();
                    polygon.Parts  = new ArrayList();
                    polygon.Points = new ArrayList();

                    uint  RecordNum  = reader.ReadUInt32();
                    int   DataLength = reader.ReadInt32();
                    ulong uRecordNum = ByteTransUtil.big2little((int)RecordNum);    //读取第i个记录
                    //每一条的记录长度没有考虑RecordNum、DataLength 所以比实际长度少4字
                    //以字为单位,一字等于2字节,等于16位
                    int uDataLength = (int)ByteTransUtil.big2little(DataLength);
                    int geoType     = reader.ReadInt32();

                    polygon.RecordNum  = uRecordNum;
                    polygon.DataLength = uDataLength;
                    polygon.GeoType    = ShapeType.Polygon;
                    polygon.Xmin       = reader.ReadDouble();
                    polygon.Ymin       = reader.ReadDouble();
                    polygon.Xmax       = reader.ReadDouble();
                    polygon.Ymax       = reader.ReadDouble();
                    polygon.NumParts   = reader.ReadInt32();
                    polygon.NumPoints  = reader.ReadInt32();
                    for (int j = 0; j < polygon.NumParts; j++)
                    {
                        int parts = new int();
                        parts = reader.ReadInt32();
                        polygon.Parts.Add(parts);
                    }
                    for (int j = 0; j < polygon.NumPoints; j++)
                    {
                        EVPoint pointtemp = new EVPoint();
                        pointtemp.X = reader.ReadDouble();
                        pointtemp.Y = reader.ReadDouble();
                        polygon.Points.Add(pointtemp);
                    }
                    ShpData item = new ShpData();
                    item.GeoShape = polygon;
                    mRecordDic.Add(uRecordNum, item);
                }
                break;
            }
        }