📄 tabmapheaderblock.cpp
字号:
}/********************************************************************** * TABMAPHeaderBlock::SetCoordsysBounds() * * Take projection coordinates bounds of the newly created dataset and * compute new values for the X/Y Scales and X/Y displacement. * * This function must be called after creating a new dataset and before any * of the coordinates conversion functions can be used. * * Returns 0 on success, -1 on error. **********************************************************************/int TABMAPHeaderBlock::SetCoordsysBounds(double dXMin, double dYMin, double dXMax, double dYMax){//printf("SetCoordsysBounds(%10g, %10g, %10g, %10g)\n", dXMin, dYMin, dXMax, dYMax); /*----------------------------------------------------------------- * Check for 0-width or 0-height bounds *----------------------------------------------------------------*/ if (dXMax == dXMin) { dXMin -= 1.0; dXMax += 1.0; } if (dYMax == dYMin) { dYMin -= 1.0; dYMax += 1.0; } /*----------------------------------------------------------------- * X and Y scales are used to map coordsys coordinates to integer * internal coordinates. We want to find the scale and displacement * values that will result in an integer coordinate range of * (-1e9, -1e9) - (1e9, 1e9) * * Note that we ALWAYS generate datasets with the OriginQuadrant = 1 * so that we avoid reverted X/Y axis complications, etc. *----------------------------------------------------------------*/ m_XScale = 2e9 / (dXMax - dXMin); m_YScale = 2e9 / (dYMax - dYMin); m_XDispl = -1.0 * m_XScale * (dXMax + dXMin) / 2; m_YDispl = -1.0 * m_YScale * (dYMax + dYMin) / 2; m_nXMin = -1000000000; m_nYMin = -1000000000; m_nXMax = 1000000000; m_nYMax = 1000000000; return 0;}/********************************************************************** * TABMAPHeaderBlock::GetMapObjectSize() * * Return the size of the object body for the specified object type. * The value is looked up in the first 256 bytes of the header. **********************************************************************/int TABMAPHeaderBlock::GetMapObjectSize(int nObjType){ if (m_pabyBuf == NULL) { UGKError(ET_Failure, UGKErr_AssertionFailed, "Block has not been initialized yet!"); return -1; } if (nObjType < 0 || nObjType > 255) { UGKError(ET_Failure, UGKErr_IllegalArg, "Invalid object type %d", nObjType); return -1; } // Byte 0x80 is set for objects that have coordinates inside type 3 blocks return (m_pabyBuf[nObjType] & 0x7f);}/********************************************************************** * TABMAPHeaderBlock::MapObjectUsesCoordBlock() * * Return TRUE if the specified map object type has coordinates stored * inside type 3 coordinate blocks. * The info is looked up in the first 256 bytes of the header. **********************************************************************/UGKBool TABMAPHeaderBlock::MapObjectUsesCoordBlock(int nObjType){ if (m_pabyBuf == NULL) { UGKError(ET_Failure, UGKErr_AssertionFailed, "Block has not been initialized yet!"); return FALSE; } if (nObjType < 0 || nObjType > 255) { UGKError(ET_Failure, UGKErr_IllegalArg, "Invalid object type %d", nObjType); return FALSE; } // Byte 0x80 is set for objects that have coordinates inside type 3 blocks return ((m_pabyBuf[nObjType] & 0x80) != 0) ? TRUE: FALSE;}/********************************************************************** * TABMAPHeaderBlock::GetProjInfo() * * Fill the psProjInfo structure with the projection parameters previously * read from this header block. * * Returns 0 on success, -1 on error. **********************************************************************/int TABMAPHeaderBlock::GetProjInfo(TABProjInfo *psProjInfo){ if (m_pabyBuf == NULL) { UGKError(ET_Failure, UGKErr_AssertionFailed, "Block has not been initialized yet!"); return -1; } if (psProjInfo) *psProjInfo = m_sProj; return 0;}/********************************************************************** * TABMAPHeaderBlock::SetProjInfo() * * Set the projection parameters for this dataset. * * Returns 0 on success, -1 on error. **********************************************************************/int TABMAPHeaderBlock::SetProjInfo(TABProjInfo *psProjInfo){ if (m_pabyBuf == NULL) { UGKError(ET_Failure, UGKErr_AssertionFailed, "Block has not been initialized yet!"); return -1; } if (psProjInfo) m_sProj = *psProjInfo; return 0;}/********************************************************************** * TABMAPHeaderBlock::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 header * block buffer 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 * UGKError() will have been called. **********************************************************************/int TABMAPHeaderBlock::CommitToFile(){ int i, nStatus = 0; if ( m_pabyBuf == NULL || m_nBlockSize != HDR_DATA_BLOCK_SIZE ) { UGKError(ET_Failure, UGKErr_AssertionFailed, "TABRawBinBlock::CommitToFile(): Block has not been initialized yet!"); return -1; } /*----------------------------------------------------------------- * Reconstruct header to make sure it is in sync with members variables. *----------------------------------------------------------------*/ GotoByteInBlock(0x000); WriteBytes(HDR_OBJ_LEN_ARRAY_SIZE, gabyObjLenArray); m_nMaxObjLenArrayId = HDR_OBJ_LEN_ARRAY_SIZE-1; GotoByteInBlock(0x100); WriteInt32(HDR_MAGIC_COOKIE); WriteInt16(m_nMAPVersionNumber); WriteInt16(HDR_DATA_BLOCK_SIZE); WriteDouble(m_dCoordsys2DistUnits); WriteInt32(m_nXMin); WriteInt32(m_nYMin); WriteInt32(m_nXMax); WriteInt32(m_nYMax); WriteZeros(16); // ??? WriteInt32(m_nFirstIndexBlock); WriteInt32(m_nFirstGarbageBlock); WriteInt32(m_nFirstToolBlock); WriteInt32(m_numPointObjects); WriteInt32(m_numLineObjects); WriteInt32(m_numRegionObjects); WriteInt32(m_numTextObjects); WriteInt32(m_nMaxCoordBufSize); WriteZeros(14); // ??? WriteByte(m_nDistUnitsCode); WriteByte(m_nMaxSpIndexDepth); WriteByte(m_nCoordPrecision); WriteByte(m_nCoordOriginQuadrant); WriteByte(m_nReflectXAxisCoord); WriteByte(m_nMaxObjLenArrayId); // See gabyObjLenArray[] WriteByte(m_numPenDefs); WriteByte(m_numBrushDefs); WriteByte(m_numSymbolDefs); WriteByte(m_numFontDefs); WriteInt16(m_numMapToolBlocks); WriteZeros(3); // ??? WriteByte(m_sProj.nProjId); WriteByte(m_sProj.nEllipsoidId); WriteByte(m_sProj.nUnitsId); WriteDouble(m_XScale); WriteDouble(m_YScale); WriteDouble(m_XDispl); WriteDouble(m_YDispl); for(i=0; i<6; i++) WriteDouble(m_sProj.adProjParams[i]); WriteDouble(m_sProj.dDatumShiftX); WriteDouble(m_sProj.dDatumShiftY); WriteDouble(m_sProj.dDatumShiftZ); for(i=0; i<5; i++) WriteDouble(m_sProj.adDatumParams[i]); /*----------------------------------------------------------------- * OK, call the base class to write the block to disk. *----------------------------------------------------------------*/ if (nStatus == 0) nStatus = TABRawBinBlock::CommitToFile(); return nStatus;}/********************************************************************** * TABMAPHeaderBlock::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 * UGKError() will have been called. **********************************************************************/int TABMAPHeaderBlock::InitNewBlock(FILE *fpSrc, int nBlockSize, int nFileOffset /* = 0*/){ int i; /*----------------------------------------------------------------- * Start with the default initialisation *----------------------------------------------------------------*/ if ( TABRawBinBlock::InitNewBlock(fpSrc, nBlockSize, nFileOffset) != 0) return -1; /*----------------------------------------------------------------- * Set acceptable default values for member vars. *----------------------------------------------------------------*/ m_nMAPVersionNumber = HDR_VERSION_NUMBER; m_nBlockSize = HDR_DATA_BLOCK_SIZE; m_dCoordsys2DistUnits = 1.0; m_nXMin = -1000000000; m_nYMin = -1000000000; m_nXMax = 1000000000; m_nYMax = 1000000000; m_nFirstIndexBlock = 0; m_nFirstGarbageBlock = 0; m_nFirstToolBlock = 0; m_numPointObjects = 0; m_numLineObjects = 0; m_numRegionObjects = 0; m_numTextObjects = 0; m_nMaxCoordBufSize = 0; m_nDistUnitsCode = 7; // Meters m_nMaxSpIndexDepth = 0; m_nCoordPrecision = 3; // ??? 3 digits of precision m_nCoordOriginQuadrant = HDR_DEF_UGK_QUADRANT; // ??? N-E quadrant m_nReflectXAxisCoord = HDR_DEF_REFLECTXAXIS; m_nMaxObjLenArrayId = HDR_OBJ_LEN_ARRAY_SIZE-1; // See gabyObjLenArray[] m_numPenDefs = 0; m_numBrushDefs = 0; m_numSymbolDefs = 0; m_numFontDefs = 0; m_numMapToolBlocks = 0; m_sProj.nProjId = 0; m_sProj.nEllipsoidId = 0; m_sProj.nUnitsId = 7; m_XScale = 1000.0; // Default coord range (before SetCoordSysBounds()) m_YScale = 1000.0; // will be [-1000000.000 .. 1000000.000] m_XDispl = 0.0; m_YDispl = 0.0; for(i=0; i<6; i++) m_sProj.adProjParams[i] = 0.0; m_sProj.dDatumShiftX = 0.0; m_sProj.dDatumShiftY = 0.0; m_sProj.dDatumShiftZ = 0.0; for(i=0; i<5; i++) m_sProj.adDatumParams[i] = 0.0; /*----------------------------------------------------------------- * And Set the map object length array in the buffer... *----------------------------------------------------------------*/ if (m_eAccess != TABRead) { GotoByteInBlock(0x000); WriteBytes(HDR_OBJ_LEN_ARRAY_SIZE, gabyObjLenArray); } if (UGKGetLastErrorNo() != 0) return -1; return 0;}/********************************************************************** * TABMAPHeaderBlock::Dump() * * Dump block contents... available only in DEBUG mode. **********************************************************************/void TABMAPHeaderBlock::Dump(FILE *fpOut /*=NULL*/){ int i; if (fpOut == NULL) fpOut = stdout; fprintf(fpOut, "----- TABMAPHeaderBlock::Dump() -----\n"); if (m_pabyBuf == NULL) { fprintf(fpOut, "Block has not been initialized yet."); } else { fprintf(fpOut,"Version %d header block.\n", m_nMAPVersionNumber); fprintf(fpOut," m_nBlockSize = %d\n", m_nBlockSize); fprintf(fpOut," m_nFirstIndexBlock = %d\n", m_nFirstIndexBlock); fprintf(fpOut," m_nFirstGarbageBlock = %d\n", m_nFirstGarbageBlock); fprintf(fpOut," m_nFirstToolBlock = %d\n", m_nFirstToolBlock); fprintf(fpOut," m_numPointObjects = %d\n", m_numPointObjects); fprintf(fpOut," m_numLineObjects = %d\n", m_numLineObjects); fprintf(fpOut," m_numRegionObjects = %d\n", m_numRegionObjects); fprintf(fpOut," m_numTextObjects = %d\n", m_numTextObjects); fprintf(fpOut," m_nMaxCoordBufSize = %d\n", m_nMaxCoordBufSize); fprintf(fpOut,"\n"); fprintf(fpOut," m_dCoordsys2DistUnits = %g\n", m_dCoordsys2DistUnits); fprintf(fpOut," m_nXMin = %d\n", m_nXMin); fprintf(fpOut," m_nYMin = %d\n", m_nYMin); fprintf(fpOut," m_nXMax = %d\n", m_nXMax); fprintf(fpOut," m_nYMax = %d\n", m_nYMax); fprintf(fpOut," m_XScale = %g\n", m_XScale); fprintf(fpOut," m_YScale = %g\n", m_YScale); fprintf(fpOut," m_XDispl = %g\n", m_XDispl); fprintf(fpOut," m_YDispl = %g\n", m_YDispl); fprintf(fpOut,"\n"); fprintf(fpOut," m_nDistUnistCode = %d\n", m_nDistUnitsCode); fprintf(fpOut," m_nMaxSpIndexDepth = %d\n", m_nMaxSpIndexDepth); fprintf(fpOut," m_nCoordPrecision = %d\n", m_nCoordPrecision); fprintf(fpOut," m_nCoordOriginQuadrant= %d\n",m_nCoordOriginQuadrant); fprintf(fpOut," m_nReflecXAxisCoord = %d\n", m_nReflectXAxisCoord); fprintf(fpOut," m_nMaxObjLenArrayId = %d\n", m_nMaxObjLenArrayId); fprintf(fpOut," m_numPenDefs = %d\n", m_numPenDefs); fprintf(fpOut," m_numBrushDefs = %d\n", m_numBrushDefs); fprintf(fpOut," m_numSymbolDefs = %d\n", m_numSymbolDefs); fprintf(fpOut," m_numFontDefs = %d\n", m_numFontDefs); fprintf(fpOut," m_numMapToolBlocks = %d\n", m_numMapToolBlocks); fprintf(fpOut,"\n"); fprintf(fpOut," m_sProj.nProjId = %d\n", (int)m_sProj.nProjId); fprintf(fpOut," m_sProj.nEllipsoidId = %d\n", (int)m_sProj.nEllipsoidId); fprintf(fpOut," m_sProj.nUnitsId = %d\n", (int)m_sProj.nUnitsId); fprintf(fpOut," m_sProj.adProjParams ="); for(i=0; i<6; i++) fprintf(fpOut, " %g", m_sProj.adProjParams[i]); fprintf(fpOut,"\n"); fprintf(fpOut," m_sProj.dDatumShiftX = %.15g\n", m_sProj.dDatumShiftX); fprintf(fpOut," m_sProj.dDatumShiftY = %.15g\n", m_sProj.dDatumShiftY); fprintf(fpOut," m_sProj.dDatumShiftZ = %.15g\n", m_sProj.dDatumShiftZ); fprintf(fpOut," m_sProj.adDatumParams ="); for(i=0; i<5; i++) fprintf(fpOut, " %.15g", m_sProj.adDatumParams[i]); fprintf(fpOut,"\n"); // Dump array of map object lengths... optional if (FALSE) { fprintf(fpOut, "-- Header bytes 00-FF: Array of map object lenghts --\n"); for(i=0; i<256; i++) { fprintf(fpOut, "0x%2.2x", (int)m_pabyBuf[i]); if (i != 255) fprintf(fpOut, ","); if ((i+1)%16 == 0) fprintf(fpOut, "\n"); } } } fflush(fpOut);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -