?? mitab_feature.cpp
字號:
*
* Return the values for the MBR corners for this feature.
**********************************************************************/
void TABFeature::GetMBR(double &dXMin, double &dYMin,
double &dXMax, double &dYMax)
{
dXMin = m_dXMin;
dYMin = m_dYMin;
dXMax = m_dXMax;
dYMax = m_dYMax;
}
/**********************************************************************
* TABFeature::SetIntMBR()
*
* Set the integer coordinates values of the MBR of this feature.
**********************************************************************/
void TABFeature::SetIntMBR(GInt32 nXMin, GInt32 nYMin,
GInt32 nXMax, GInt32 nYMax)
{
m_nXMin = nXMin;
m_nYMin = nYMin;
m_nXMax = nXMax;
m_nYMax = nYMax;
}
/**********************************************************************
* TABFeature::GetIntMBR()
*
* Return the integer coordinates values of the MBR of this feature.
**********************************************************************/
void TABFeature::GetIntMBR(GInt32 &nXMin, GInt32 &nYMin,
GInt32 &nXMax, GInt32 &nYMax)
{
nXMin = m_nXMin;
nYMin = m_nYMin;
nXMax = m_nXMax;
nYMax = m_nYMax;
}
/**********************************************************************
* TABFeature::ReadRecordFromDATFile()
*
* Fill the fields part of the feature from the contents of the
* table record pointed to by poDATFile.
*
* It is assumed that poDATFile currently points to the beginning of
* the table record and that this feature's OGRFeatureDefn has been
* properly initialized for this table.
**********************************************************************/
int TABFeature::ReadRecordFromDATFile(TABDATFile *poDATFile)
{
int iField, numFields, nValue;
double dValue;
const char *pszValue;
CPLAssert(poDATFile);
numFields = poDATFile->GetNumFields();
for(iField=0; iField<numFields; iField++)
{
switch(poDATFile->GetFieldType(iField))
{
case TABFChar:
pszValue = poDATFile->ReadCharField(poDATFile->
GetFieldWidth(iField));
SetField(iField, pszValue);
break;
case TABFDecimal:
dValue = poDATFile->ReadDecimalField(poDATFile->
GetFieldWidth(iField));
SetField(iField, dValue);
break;
case TABFInteger:
nValue = poDATFile->ReadIntegerField(poDATFile->
GetFieldWidth(iField));
SetField(iField, nValue);
break;
case TABFSmallInt:
nValue = poDATFile->ReadSmallIntField(poDATFile->
GetFieldWidth(iField));
SetField(iField, nValue);
break;
case TABFFloat:
dValue = poDATFile->ReadFloatField(poDATFile->
GetFieldWidth(iField));
SetField(iField, dValue);
break;
case TABFLogical:
pszValue = poDATFile->ReadLogicalField(poDATFile->
GetFieldWidth(iField));
SetField(iField, pszValue);
break;
case TABFDate:
pszValue = poDATFile->ReadDateField(poDATFile->
GetFieldWidth(iField));
SetField(iField, pszValue);
break;
case TABFTime:
pszValue = poDATFile->ReadTimeField(poDATFile->
GetFieldWidth(iField));
SetField(iField, pszValue);
break;
case TABFDateTime:
pszValue = poDATFile->ReadDateTimeField(poDATFile->
GetFieldWidth(iField));
SetField(iField, pszValue);
break;
default:
// Other type??? Impossible!
CPLError(CE_Failure, CPLE_AssertionFailed,
"Unsupported field type!");
}
}
return 0;
}
/**********************************************************************
* TABFeature::WriteRecordToDATFile()
*
* Write the attribute part of the feature to the .DAT file.
*
* It is assumed that poDATFile currently points to the beginning of
* the table record and that this feature's OGRFeatureDefn has been
* properly initialized for this table.
*
* Returns 0 on success, -1 on error.
**********************************************************************/
int TABFeature::WriteRecordToDATFile(TABDATFile *poDATFile,
TABINDFile *poINDFile, int *panIndexNo)
{
int iField, numFields, nStatus=0;
CPLAssert(poDATFile);
CPLAssert(panIndexNo || GetDefnRef()->GetFieldCount() == 0);
numFields = poDATFile->GetNumFields();
for(iField=0; nStatus == 0 && iField<numFields; iField++)
{
// Hack for "extra" introduced field.
if( iField >= GetDefnRef()->GetFieldCount() )
{
CPLAssert( poDATFile->GetFieldType(iField) == TABFInteger
&& iField == 0 );
nStatus = poDATFile->WriteIntegerField( GetFID(), poINDFile, 0 );
continue;
}
switch(poDATFile->GetFieldType(iField))
{
case TABFChar:
nStatus = poDATFile->WriteCharField(GetFieldAsString(iField),
poDATFile->GetFieldWidth(iField),
poINDFile, panIndexNo[iField]);
break;
case TABFDecimal:
nStatus = poDATFile->WriteDecimalField(GetFieldAsDouble(iField),
poDATFile->GetFieldWidth(iField),
poDATFile->GetFieldPrecision(iField),
poINDFile, panIndexNo[iField]);
break;
case TABFInteger:
nStatus = poDATFile->WriteIntegerField(GetFieldAsInteger(iField),
poINDFile, panIndexNo[iField]);
break;
case TABFSmallInt:
nStatus = poDATFile->WriteSmallIntField(GetFieldAsInteger(iField),
poINDFile, panIndexNo[iField]);
break;
case TABFFloat:
nStatus = poDATFile->WriteFloatField(GetFieldAsDouble(iField),
poINDFile, panIndexNo[iField]);
break;
case TABFLogical:
nStatus = poDATFile->WriteLogicalField(GetFieldAsString(iField),
poINDFile, panIndexNo[iField]);
break;
case TABFDate:
nStatus = poDATFile->WriteDateField(GetFieldAsString(iField),
poINDFile, panIndexNo[iField]);
break;
case TABFTime:
nStatus = poDATFile->WriteTimeField(GetFieldAsString(iField),
poINDFile, panIndexNo[iField]);
break;
case TABFDateTime:
nStatus = poDATFile->WriteDateTimeField(GetFieldAsString(iField),
poINDFile, panIndexNo[iField]);
break;
default:
// Other type??? Impossible!
CPLError(CE_Failure, CPLE_AssertionFailed,
"Unsupported field type!");
}
}
if (poDATFile->CommitRecordToFile() != 0)
return -1;
return 0;
}
/**********************************************************************
* TABFeature::ReadGeometryFromMAPFile()
*
* In derived classes, this method should be reimplemented to
* fill the geometry and representation (color, etc...) part of the
* feature from the contents of the .MAP object pointed to by poMAPFile.
*
* It is assumed that before calling ReadGeometryFromMAPFile(), poMAPFile
* currently points to the beginning of a map object.
*
* bCoordBlockDataOnly=TRUE is used when this method is called to copy only
* the CoordBlock data during splitting of object blocks. In this case we
* need to process only the information related to the CoordBlock. One
* important thing to avoid is reading/writing pen/brush/symbol definitions
* as that would screw up their ref counters.
*
* ppoCoordBlock is used by TABCollection and by index splitting code
* to provide a CoordBlock to use instead of the one from the poMAPFile and
* return the current pointer at the end of the call.
*
* The current implementation does nothing since instances of TABFeature
* objects contain no geometry (i.e. TAB_GEOM_NONE).
*
* Returns 0 on success, -1 on error, in which case CPLError() will have
* been called.
**********************************************************************/
int TABFeature::ReadGeometryFromMAPFile(TABMAPFile * /*poMapFile*/,
TABMAPObjHdr * /*poObjHdr*/,
GBool /*bCoordBlockDataOnly=FALSE*/,
TABMAPCoordBlock ** /*ppoCoordBlock=NULL*/)
{
/*-----------------------------------------------------------------
* Nothing to do... instances of TABFeature objects contain no geometry.
*----------------------------------------------------------------*/
return 0;
}
/**********************************************************************
* TABFeature::UpdateMBR()
*
* Fetch envelope of poGeom and update MBR.
* Integer coord MBR is updated only if poMapFile is not NULL.
*
* Returns 0 on success, or -1 if there is no geometry in object
**********************************************************************/
int TABFeature::UpdateMBR(TABMAPFile * poMapFile /*=NULL*/)
{
OGRGeometry *poGeom;
poGeom = GetGeometryRef();
if (poGeom)
{
OGREnvelope oEnv;
poGeom->getEnvelope(&oEnv);
m_dXMin = oEnv.MinX;
m_dYMin = oEnv.MinY;
m_dXMax = oEnv.MaxX;
m_dYMax = oEnv.MaxY;
if (poMapFile)
{
poMapFile->Coordsys2Int(oEnv.MinX, oEnv.MinY, m_nXMin, m_nYMin);
poMapFile->Coordsys2Int(oEnv.MaxX, oEnv.MaxY, m_nXMax, m_nYMax);
}
return 0;
}
return -1;
}
/**********************************************************************
* TABFeature::ValidateCoordType()
*
* Checks the feature envelope to establish if the feature should be
* written using Compressed coordinates or not and adjust m_nMapInfoType
* accordingly. Calling this method also sets (initializes) m_nXMin, m_nYMin,
* m_nXMax, m_nYMax
*
* This function should be used only by the ValidateMapInfoType()
* implementations.
*
* Returns TRUE if coord. should be compressed, FALSE otherwise
**********************************************************************/
GBool TABFeature::ValidateCoordType(TABMAPFile * poMapFile)
{
GBool bCompr = FALSE;
/*-------------------------------------------------------------
* Decide if coordinates should be compressed or not.
*------------------------------------------------------------*/
if (UpdateMBR(poMapFile) == 0)
{
/* Test for max range < 65535 here instead of < 65536 to avoid
* compressed coordinate overflows in some boundary situations
*/
if ((m_nXMax - m_nXMin) < 65535 && (m_nYMax-m_nYMin) < 65535)
{
bCompr = TRUE;
}
m_nComprOrgX = (m_nXMin + m_nXMax) / 2;
m_nComprOrgY = (m_nYMin + m_nYMax) / 2;
}
/*-------------------------------------------------------------
* Adjust native type
*------------------------------------------------------------*/
if (bCompr && ((m_nMapInfoType%3) == 2))
m_nMapInfoType--; // compr = 1, 4, 7, ...
else if (!bCompr && ((m_nMapInfoType%3) == 1))
m_nMapInfoType++; // non-compr = 2, 5, 8, ...
return bCompr;
}
/**********************************************************************
* TABFeature::ForceCoordTypeAndOrigin()
*
* This function is used by TABCollection::ValidateMapInfoType() to force
* the coord type and compressed origin of all members of a collection
* to be the same. (A replacement for ValidateCoordType() for this
* specific case)
**********************************************************************/
void TABFeature::ForceCoordTypeAndOrigin(int nMapInfoType, GBool bCompr,
GInt32 nComprOrgX, GInt32 nComprOrgY,
GInt32 nXMin, GInt32 nYMin,
GInt32 nXMax, GInt32 nYMax)
{
/*-------------------------------------------------------------
* Set Compressed Origin and adjust native type
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -