Пример #1
0
        /// <summary>
        /// 打开shp、shx文件流
        /// 读取shp、shx信息时需要首先执行此操作
        /// 同时操作头文件读取和ShxRecord、ShpRecord示例化
        /// </summary>
        /// <param name="ofs"></param>
        public void Open(Stream shpStream, Stream shxStream)
        {
            if (mShpFile != null)
            {
                Close();
            }

            mShpFile       = shpStream;
            mShxFile       = shxStream;
            mShpFileReader = null;
            mShpFileWriter = null;
            mShxFileReader = null;
            mShxFileWriter = null;
            if (mShpFile.CanRead)
            {
                mShpFileReader = new BinaryReader(mShpFile);
            }
            if (mShpFile.CanWrite)
            {
                mShpFileWriter = new BinaryWriter(mShpFile);
            }

            if (mShxFile.CanRead)
            {
                mShxFileReader = new BinaryReader(mShxFile);
            }
            if (mShxFile.CanWrite)
            {
                mShxFileWriter = new BinaryWriter(mShxFile);
            }
            //reset position
            mRecordsReadCount = 0;
            //assume header is not written
            mHeaderWritten = false;

            //read the header
            if (shpStream.CanRead)
            {
                //try to read the header...
                try
                {
                    mHeader.Read(mShpFileReader);
                    mHeaderWritten = true;
                }
                catch (EndOfStreamException)
                {
                    //could not read header, file is empty
                    mHeader        = new ShpHeader();
                    mHeaderWritten = false;
                }
            }
            if (mShpFile != null)
            {
                mIsReadOnly    = !mShpFile.CanWrite;
                mIsForwardOnly = !mShpFile.CanSeek;
            }
            mShxRecord = new ShxRecord(mHeader);
            mShpRecord = new ShpRecord(mHeader);
        }
Пример #2
0
        /// <summary>
        /// 更新header信息 清除(flush)buffers 关闭streams
        /// 在操作完shp文件后必须调用此方法
        /// </summary>
        public void Close()
        {
            //Empty header...
            //--------------------------------
            mHeader        = new ShpHeader();
            mHeaderWritten = false;

            //reset current record index
            //--------------------------------
            mRecordsReadCount = 0;

            //Close streams...
            //--------------------------------
            if (mShpFileWriter != null)
            {
                mShpFileWriter.Flush();
                mShpFileWriter.Close();
            }
            if (mShpFileReader != null)
            {
                mShpFileReader.Close();
            }
            if (mShpFile != null)
            {
                mShpFile.Close();
            }

            if (mShxFileWriter != null)
            {
                mShxFileWriter.Flush();
                mShxFileWriter.Close();
            }
            if (mShxFileReader != null)
            {
                mShxFileReader.Close();
            }
            if (mShxFile != null)
            {
                mShxFile.Close();
            }
            //set streams to null
            //--------------------------------
            mShpFileReader = null;
            mShpFileWriter = null;
            mShpFile       = null;

            mShxFileReader = null;
            mShxFileWriter = null;
            mShxFile       = null;

            mFileName = "";
        }
Пример #3
0
        /// <summary>
        /// 根据RecordDic求header
        /// </summary>
        private void TransHeader()
        {
            if (mHeader == null)
            {
                mHeader = new ShpHeader();
            }

            mHeader.FileCode   = 9994; //固定
            mHeader.FileLength = 50;   //文件头
            foreach (var item in mRecordDic)
            {
                mHeader.FileLength += item.Value.GeoShape.DataLength + 4; //每条记录多出4字
            }
            mHeader.Version = 1000;                                       //固定
            mHeader.GeoType = mRecordDic[1].GeoShape.GeoType;
            GetBorder();                                                  //求包围盒
        }
Пример #4
0
 /// <summary>
 ///
 /// </summary>
 public ShpFile()
 {
     mHeader = new ShpHeader();
 }
Пример #5
0
 /// <summary>
 /// 构造时传入已经实例化的ShpHeader对象
 /// </summary>
 /// <param name="oHeader"></param>
 public ShpRecord(ShpHeader oHeader)
 {
     mHeader = oHeader;
 }