?? mitab_mapcoordblock.cpp
字號(hào):
/********************************************************************** * $Id: mitab_mapcoordblock.cpp,v 1.14 2005/10/06 19:15:31 dmorissette Exp $ * * Name: mitab_mapcoordblock.cpp * Project: MapInfo TAB Read/Write library * Language: C++ * Purpose: Implementation of the TABMAPCoordBlock class used to handle * reading/writing of the .MAP files' coordinate blocks * Author: Daniel Morissette, dmorissette@dmsolutions.ca * ********************************************************************** * Copyright (c) 1999-2001, Daniel Morissette * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. ********************************************************************** * * $Log: mitab_mapcoordblock.cpp,v $ * Revision 1.16 2007/02/23 18:56:44 dmorissette * Fixed another problem writing collections when the header of objects * part of a collection were split on multiple blocks. Fix WriteBytes() * to reload next coord block in TABReadWrite mode if there is one (bug 1663) * * Revision 1.14 2005/10/06 19:15:31 dmorissette * Collections: added support for reading/writing pen/brush/symbol ids and * for writing collection objects to .TAB/.MAP (bug 1126) * * Revision 1.13 2004/06/30 20:29:04 dmorissette * Fixed refs to old address danmo@videotron.ca * * Revision 1.12 2002/08/27 17:18:23 warmerda * improved CPL error testing * * Revision 1.11 2001/11/17 21:54:06 daniel * Made several changes in order to support writing objects in 16 bits coordinate format. * New TABMAPObjHdr-derived classes are used to hold object info in mem until block is full. * * Revision 1.10 2001/05/09 17:45:12 daniel * Support reading and writing data blocks > 512 bytes (for text objects). * * Revision 1.9 2000/10/10 19:05:12 daniel * Fixed ReadBytes() to allow strings overlapping on 2 blocks * * Revision 1.8 2000/02/28 16:58:55 daniel * Added V450 object types with num_points > 32767 and pen width in points * * Revision 1.7 2000/01/15 22:30:44 daniel * Switch to MIT/X-Consortium OpenSource license * * Revision 1.6 1999/11/08 04:29:31 daniel * Fixed problem with compressed coord. offset for regions and multiplines * * Revision 1.5 1999/10/06 15:19:11 daniel * Do not automatically init. curr. feature MBR when block is initialized * * Revision 1.4 1999/10/06 13:18:55 daniel * Fixed uninitialized class members * * Revision 1.3 1999/09/29 04:25:42 daniel * Fixed typo in GetFeatureMBR() * * Revision 1.2 1999/09/26 14:59:36 daniel * Implemented write support * * Revision 1.1 1999/07/12 04:18:24 daniel * Initial checkin * **********************************************************************/#include "mitab.h"/*===================================================================== * class TABMAPCoordBlock *====================================================================*/#define MAP_COORD_HEADER_SIZE 8/********************************************************************** * TABMAPCoordBlock::TABMAPCoordBlock() * * Constructor. **********************************************************************/TABMAPCoordBlock::TABMAPCoordBlock(TABAccess eAccessMode /*= TABRead*/): TABRawBinBlock(eAccessMode, TRUE){ m_nComprOrgX = m_nComprOrgY = m_nNextCoordBlock = m_numDataBytes = 0; m_numBlocksInChain = 1; // Current block counts as 1 m_poBlockManagerRef = NULL; m_nTotalDataSize = 0; m_nFeatureDataSize = 0; m_nFeatureXMin = m_nMinX = 1000000000; m_nFeatureYMin = m_nMinY = 1000000000; m_nFeatureXMax = m_nMaxX = -1000000000; m_nFeatureYMax = m_nMaxY = -1000000000;}/********************************************************************** * TABMAPCoordBlock::~TABMAPCoordBlock() * * Destructor. **********************************************************************/TABMAPCoordBlock::~TABMAPCoordBlock(){}/********************************************************************** * TABMAPCoordBlock::InitBlockFromData() * * Perform some initialization on the block after its binary data has * been set or changed (or loaded from a file). * * Returns 0 if succesful or -1 if an error happened, in which case * CPLError() will have been called. **********************************************************************/int TABMAPCoordBlock::InitBlockFromData(GByte *pabyBuf, int nSize, GBool bMakeCopy /* = TRUE */, FILE *fpSrc /* = NULL */, int nOffset /* = 0 */){ int nStatus; /*----------------------------------------------------------------- * First of all, we must call the base class' InitBlockFromData() *----------------------------------------------------------------*/ nStatus = TABRawBinBlock::InitBlockFromData(pabyBuf, nSize, bMakeCopy, fpSrc, nOffset); if (nStatus != 0) return nStatus; /*----------------------------------------------------------------- * Validate block type *----------------------------------------------------------------*/ if (m_nBlockType != TABMAP_COORD_BLOCK) { CPLError(CE_Failure, CPLE_FileIO, "InitBlockFromData(): Invalid Block Type: got %d expected %d", m_nBlockType, TABMAP_COORD_BLOCK); CPLFree(m_pabyBuf); m_pabyBuf = NULL; return -1; } /*----------------------------------------------------------------- * Init member variables *----------------------------------------------------------------*/ GotoByteInBlock(0x002); m_numDataBytes = ReadInt16(); /* Excluding 8 bytes header */ m_nNextCoordBlock = ReadInt32(); // Set the real SizeUsed based on numDataBytes m_nSizeUsed = m_numDataBytes + MAP_COORD_HEADER_SIZE; /*----------------------------------------------------------------- * The read ptr is now located at the beginning of the data part. *----------------------------------------------------------------*/ GotoByteInBlock(MAP_COORD_HEADER_SIZE); return 0;}/********************************************************************** * TABMAPCoordBlock::CommitToFile() * * Commit the current state of the binary block to the file to which * it has been previously attached. * * This method makes sure all values are properly set in the map object * block header and then calls TABRawBinBlock::CommitToFile() to do * the actual writing to disk. * * Returns 0 if succesful or -1 if an error happened, in which case * CPLError() will have been called. **********************************************************************/int TABMAPCoordBlock::CommitToFile(){ int nStatus = 0; CPLErrorReset(); if ( m_pabyBuf == NULL ) { CPLError(CE_Failure, CPLE_AssertionFailed, "CommitToFile(): Block has not been initialized yet!"); return -1; } /*----------------------------------------------------------------- * Make sure 8 bytes block header is up to date. *----------------------------------------------------------------*/ GotoByteInBlock(0x000); WriteInt16(TABMAP_COORD_BLOCK); // Block type code WriteInt16(m_nSizeUsed - MAP_COORD_HEADER_SIZE); // num. bytes used WriteInt32(m_nNextCoordBlock); if( CPLGetLastErrorType() == CE_Failure ) nStatus = CPLGetLastErrorNo(); /*----------------------------------------------------------------- * OK, call the base class to write the block to disk. *----------------------------------------------------------------*/ if (nStatus == 0) nStatus = TABRawBinBlock::CommitToFile(); return nStatus;}/********************************************************************** * TABMAPCoordBlock::InitNewBlock() * * Initialize a newly created block so that it knows to which file it * is attached, its block size, etc . and then perform any specific * initialization for this block type, including writing a default * block header, etc. and leave the block ready to receive data. * * This is an alternative to calling ReadFromFile() or InitBlockFromData() * that puts the block in a stable state without loading any initial * data in it. * * Returns 0 if succesful or -1 if an error happened, in which case * CPLError() will have been called. **********************************************************************/int TABMAPCoordBlock::InitNewBlock(FILE *fpSrc, int nBlockSize, int nFileOffset /* = 0*/){ CPLErrorReset(); /*----------------------------------------------------------------- * Start with the default initialisation *----------------------------------------------------------------*/ if ( TABRawBinBlock::InitNewBlock(fpSrc, nBlockSize, nFileOffset) != 0) return -1; /*----------------------------------------------------------------- * And then set default values for the block header. * * IMPORTANT: Do not reset m_nComprOrg here because its value needs to be * maintained between blocks in the same chain. *----------------------------------------------------------------*/ m_nNextCoordBlock = 0; m_numDataBytes = 0; // m_nMin/Max are used to keep track of current block MBR // FeatureMin/Max should not be reset here since feature coords can // be split on several blocks m_nMinX = 1000000000; m_nMinY = 1000000000; m_nMaxX = -1000000000; m_nMaxY = -1000000000; if (m_eAccess != TABRead) { GotoByteInBlock(0x000); WriteInt16(TABMAP_COORD_BLOCK); // Block type code WriteInt16(0); // num. bytes used, excluding header WriteInt32(0); // Pointer to next coord block } if (CPLGetLastErrorType() == CE_Failure ) return -1; return 0;}/********************************************************************** * TABMAPObjectBlock::SetNextCoordBlock()
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -