/// <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); }
/// <summary> /// 写入文件 /// </summary> /// <param name="shpStream"></param> /// <param name="shxStream"></param> public void Creat(Stream shpStream, Stream shxStream) { if (mShpFile != null) { Close(); } mShpFile = shpStream; mShxFile = shxStream; mShpFileWriter = 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 mFileCreat = true; if (mShpFile != null) { mIsReadOnly = !mShpFile.CanWrite; mIsForwardOnly = !mShpFile.CanSeek; } //mShxRecord = new ShxRecord(mHeader); mShpRecord = new ShpRecord(mHeader); }