📄 mitab_mapobjectblock.cpp
字号:
**********************************************************************/
int TABMAPObjText::WriteObj(TABMAPObjectBlock *poObjBlock)
{
// Write object type and id
TABMAPObjHdr::WriteObjTypeAndId(poObjBlock);
poObjBlock->WriteInt32(m_nCoordBlockPtr); // String position
poObjBlock->WriteInt16(m_nCoordDataSize); // String length
poObjBlock->WriteInt16(m_nTextAlignment); // just./spacing/arrow
poObjBlock->WriteInt16(m_nAngle); // Tenths of degree
poObjBlock->WriteInt16(m_nFontStyle); // Font style/effect
poObjBlock->WriteByte(m_nFGColorR );
poObjBlock->WriteByte(m_nFGColorG );
poObjBlock->WriteByte(m_nFGColorB );
poObjBlock->WriteByte(m_nBGColorR );
poObjBlock->WriteByte(m_nBGColorG );
poObjBlock->WriteByte(m_nBGColorB );
// Label line end point
poObjBlock->WriteIntCoord(m_nLineEndX, m_nLineEndY, IsCompressedType());
// Text Height
if (IsCompressedType())
poObjBlock->WriteInt16(m_nHeight);
else
poObjBlock->WriteInt32(m_nHeight);
// Font name
poObjBlock->WriteByte(m_nFontId); // Font name index
// MBR after rotation
poObjBlock->WriteIntMBRCoord(m_nMinX, m_nMinY, m_nMaxX, m_nMaxY,
IsCompressedType());
poObjBlock->WriteByte(m_nPenId); // Pen index
if (CPLGetLastErrorNo() != 0)
return -1;
return 0;
}
/**********************************************************************
* class TABMAPObjMultiPoint
*
* Applies to PLINE, MULTIPLINE and REGION object types
**********************************************************************/
/**********************************************************************
* TABMAPObjMultiPoint::ReadObj()
*
* Read Object information starting after the object id which should
* have been read by TABMAPObjHdr::ReadNextObj() already.
* This function should be called only by TABMAPObjHdr::ReadNextObj().
*
* Returns 0 on success, -1 on error.
**********************************************************************/
int TABMAPObjMultiPoint::ReadObj(TABMAPObjectBlock *poObjBlock)
{
m_nCoordBlockPtr = poObjBlock->ReadInt32();
m_nNumPoints = poObjBlock->ReadInt32();
if (IsCompressedType())
{
m_nCoordDataSize = m_nNumPoints * 2 * 2;
}
else
{
m_nCoordDataSize = m_nNumPoints * 2 * 4;
}
#ifdef TABDUMP
printf("MULTIPOINT: id=%d, type=%d, "
"CoordBlockPtr=%d, CoordDataSize=%d, numPoints=%d\n",
m_nId, m_nType, m_nCoordBlockPtr, m_nCoordDataSize, m_nNumPoints);
#endif
// ?????
poObjBlock->ReadInt32();
poObjBlock->ReadInt32();
poObjBlock->ReadInt32();
poObjBlock->ReadByte();
poObjBlock->ReadByte();
poObjBlock->ReadByte();
if (m_nType == TAB_GEOM_V800_MULTIPOINT ||
m_nType == TAB_GEOM_V800_MULTIPOINT_C )
{
/* V800 MULTIPOINTS have another 33 unknown bytes... all zeros */
poObjBlock->ReadInt32();
poObjBlock->ReadInt32();
poObjBlock->ReadInt32();
poObjBlock->ReadInt32();
poObjBlock->ReadInt32();
poObjBlock->ReadInt32();
poObjBlock->ReadInt32();
poObjBlock->ReadInt32();
poObjBlock->ReadByte();
}
m_nSymbolId = poObjBlock->ReadByte();
// ?????
poObjBlock->ReadByte();
if (IsCompressedType())
{
// Region center/label point, relative to compr. coord. origin
// No it's not relative to the Object block center
m_nLabelX = poObjBlock->ReadInt16();
m_nLabelY = poObjBlock->ReadInt16();
// Compressed coordinate origin
m_nComprOrgX = poObjBlock->ReadInt32();
m_nComprOrgY = poObjBlock->ReadInt32();
m_nLabelX += m_nComprOrgX;
m_nLabelY += m_nComprOrgY;
m_nMinX = m_nComprOrgX + poObjBlock->ReadInt16(); // Read MBR
m_nMinY = m_nComprOrgY + poObjBlock->ReadInt16();
m_nMaxX = m_nComprOrgX + poObjBlock->ReadInt16();
m_nMaxY = m_nComprOrgY + poObjBlock->ReadInt16();
}
else
{
// Region center/label point
m_nLabelX = poObjBlock->ReadInt32();
m_nLabelY = poObjBlock->ReadInt32();
m_nMinX = poObjBlock->ReadInt32(); // Read MBR
m_nMinY = poObjBlock->ReadInt32();
m_nMaxX = poObjBlock->ReadInt32();
m_nMaxY = poObjBlock->ReadInt32();
// Init. Compr. Origin to a default value in case type is ever changed
m_nComprOrgX = (m_nMinX + m_nMaxX) / 2;
m_nComprOrgY = (m_nMinY + m_nMaxY) / 2;
}
if (CPLGetLastErrorNo() != 0)
return -1;
return 0;
}
/**********************************************************************
* TABMAPObjMultiPoint::WriteObj()
*
* Write Object information with the type+object id
*
* Returns 0 on success, -1 on error.
**********************************************************************/
int TABMAPObjMultiPoint::WriteObj(TABMAPObjectBlock *poObjBlock)
{
// Write object type and id
TABMAPObjHdr::WriteObjTypeAndId(poObjBlock);
poObjBlock->WriteInt32(m_nCoordBlockPtr);
// Number of points
poObjBlock->WriteInt32(m_nNumPoints);
// unknown bytes
poObjBlock->WriteZeros(15);
if (m_nType == TAB_GEOM_V800_MULTIPOINT ||
m_nType == TAB_GEOM_V800_MULTIPOINT_C )
{
/* V800 MULTIPOINTS have another 33 unknown bytes... all zeros */
poObjBlock->WriteZeros(33);
}
// Symbol Id
poObjBlock->WriteByte(m_nSymbolId);
// ????
poObjBlock->WriteByte(0);
// MBR
if (IsCompressedType())
{
// Region center/label point, relative to compr. coord. origin
// No it's not relative to the Object block center
poObjBlock->WriteInt16(m_nLabelX - m_nComprOrgX);
poObjBlock->WriteInt16(m_nLabelY - m_nComprOrgY);
poObjBlock->WriteInt32(m_nComprOrgX);
poObjBlock->WriteInt32(m_nComprOrgY);
// MBR relative to object origin (and not object block center)
poObjBlock->WriteInt16(m_nMinX - m_nComprOrgX);
poObjBlock->WriteInt16(m_nMinY - m_nComprOrgY);
poObjBlock->WriteInt16(m_nMaxX - m_nComprOrgX);
poObjBlock->WriteInt16(m_nMaxY - m_nComprOrgY);
}
else
{
// Region center/label point
poObjBlock->WriteInt32(m_nLabelX);
poObjBlock->WriteInt32(m_nLabelY);
poObjBlock->WriteInt32(m_nMinX);
poObjBlock->WriteInt32(m_nMinY);
poObjBlock->WriteInt32(m_nMaxX);
poObjBlock->WriteInt32(m_nMaxY);
}
if (CPLGetLastErrorNo() != 0)
return -1;
return 0;
}
/**********************************************************************
* class TABMAPObjCollection
*
**********************************************************************/
/**********************************************************************
* TABMAPObjCollection::ReadObj()
*
* Read Object information starting after the object id which should
* have been read by TABMAPObjHdr::ReadNextObj() already.
* This function should be called only by TABMAPObjHdr::ReadNextObj().
*
* Returns 0 on success, -1 on error.
**********************************************************************/
int TABMAPObjCollection::ReadObj(TABMAPObjectBlock *poObjBlock)
{
int SIZE_OF_REGION_PLINE_MINI_HDR = 24, SIZE_OF_MPOINT_MINI_HDR = 24;
int nVersion = TAB_GEOM_GET_VERSION(m_nType);
/* Figure the size of the mini-header that we find for each of the
* 3 optional components (center x,y and mbr)
*/
if (IsCompressedType())
{
/* 6 * int16 */
SIZE_OF_REGION_PLINE_MINI_HDR = SIZE_OF_MPOINT_MINI_HDR = 12;
}
else
{
/* 6 * int32 */
SIZE_OF_REGION_PLINE_MINI_HDR = SIZE_OF_MPOINT_MINI_HDR = 24;
}
if (nVersion >= 800)
{
/* extra 4 bytes for num_segments in Region/Pline mini-headers */
SIZE_OF_REGION_PLINE_MINI_HDR += 4;
}
m_nCoordBlockPtr = poObjBlock->ReadInt32(); // pointer into coord block
m_nNumMultiPoints = poObjBlock->ReadInt32(); // no. points in multi point
m_nRegionDataSize = poObjBlock->ReadInt32(); // size of region data inc. section hdrs
m_nPolylineDataSize = poObjBlock->ReadInt32(); // size of multipline data inc. section hdrs
if (nVersion < 800)
{
// Num Region/Pline section headers (int16 in V650)
m_nNumRegSections = poObjBlock->ReadInt16();
m_nNumPLineSections = poObjBlock->ReadInt16();
}
else
{
// Num Region/Pline section headers (int32 in V800)
m_nNumRegSections = poObjBlock->ReadInt32();
m_nNumPLineSections = poObjBlock->ReadInt32();
}
if (IsCompressedType())
{
m_nMPointDataSize = m_nNumMultiPoints * 2 * 2;
}
else
{
m_nMPointDataSize = m_nNumMultiPoints * 2 * 4;
}
/* NB. MapInfo counts 2 extra bytes per Region and Pline section header
* in the RegionDataSize and PolylineDataSize values but those 2 extra
* bytes are not present in the section hdr (possibly due to an alignment
* to a 4 byte boundary in memory in MapInfo?). The real data size in
* the CoordBlock is actually 2 bytes shorter per section header than
* what is written in RegionDataSize and PolylineDataSize values.
*
* We'll adjust the values in memory to be the corrected values.
*/
m_nRegionDataSize = m_nRegionDataSize - (2 * m_nNumRegSections);
m_nPolylineDataSize = m_nPolylineDataSize - (2 * m_nNumPLineSections);
/* Compute total coord block data size, required when splitting blocks */
m_nCoordDataSize = 0;
if(m_nNumRegSections > 0)
{
m_nCoordDataSize += SIZE_OF_REGION_PLINE_MINI_HDR + m_nRegionDataSize;
}
if(m_nNumPLineSections > 0)
{
m_nCoordDataSize += SIZE_OF_REGION_PLINE_MINI_HDR + m_nPolylineDataSize;
}
if(m_nNumMultiPoints > 0)
{
m_nCoordDataSize += SIZE_OF_MPOINT_MINI_HDR + m_nMPointDataSize;
}
#ifdef TABDUMP
printf("COLLECTION: id=%d, type=%d (0x%x), "
"CoordBlockPtr=%d, numRegionSections=%d (size=%d+%d), "
"numPlineSections=%d (size=%d+%d), numPoints=%d (size=%d+%d)\n",
m_nId, m_nType, m_nType, m_nCoordBlockPtr,
m_nNumRegSections, m_nRegionDataSize, SIZE_OF_REGION_PLINE_MINI_HDR,
m_nNumPLineSections, m_nPolylineDataSize, SIZE_OF_REGION_PLINE_MINI_HDR,
m_nNumMultiPoints, m_nMPointDataSize, SIZE_OF_MPOINT_MINI_HDR);
#endif
if (nVersion >= 800)
{
// Extra byte in V800 files... value always 4???
int nValue = poObjBlock->ReadByte();
if (nValue != 4)
{
CPLError(CE_Failure, CPLE_AssertionFailed,
"TABMAPObjCollection::ReadObj(): Byte 29 in Collection "
"object header not equal to 4 as expected. Value is %d. "
"Please report this error to the MITAB list so that "
"MITAB can be extended to support this case.",
nValue);
// We don't return right away, the error should be caught at the
// end of this function.
}
}
// ??? All zeros ???
poObjBlock->ReadInt32();
poObjBlock->ReadInt32();
poObjBlock->ReadInt32();
poObjBlock->ReadByte();
poObjBlock->ReadByte();
poObjBlock->ReadByte();
m_nMultiPointSymbolId = poObjBlock->ReadByte();
poObjBlock->ReadByte(); // ???
m_nRegionPenId = poObjBlock->ReadByte();
m_nPolylinePenId = poObjBlock->ReadByte();
m_nRegionBrushId = poObjBlock->ReadByte();
if (IsCompressedType())
{
#ifdef TABDUMP
printf("COLLECTION: READING ComprOrg @ %d\n",
poObjBlock->GetCurAddress());
#endif
// Compressed coordinate origin
m_nComprOrgX = poObjBlock->ReadInt32();
m_nComprOrgY = poObjBlock->ReadInt32();
m_nMinX = m_nComprOrgX + poObjBlock->ReadInt16(); // Read MBR
m_nMinY = m_nComprOrgY + poObjBlock->ReadInt16();
m_nMaxX = m_nComprOrgX + poObjBlock->ReadInt16();
m_nMaxY = m_nComprOrgY + poObjBlock->ReadInt16();
#ifdef TABDUMP
printf("COLLECTION: ComprOrgX,Y= (%d,%d)\n",
m_nComprOrgX, m_nComprOrgY);
#endif
}
else
{
m_nMinX = poObjBlock->ReadI
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -