📄 mitab_feature.cpp
字号:
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; 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. * * 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*/){ /*----------------------------------------------------------------- * Nothing to do... instances of TABFeature objects contain no geometry. *----------------------------------------------------------------*/ return 0;}/********************************************************************** * TABFeature::ValidateCoordType() * * Checks the feature envelope to establish if the feature should be * written using Compressed coordinates or not and adjust m_nMapInfoType * accordingly. * * 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; OGRGeometry *poGeom; poGeom = GetGeometryRef(); /*------------------------------------------------------------- * Decide if coordinates should be compressed or not. *------------------------------------------------------------*/ if (poGeom && poMapFile) { OGREnvelope oEnv; poGeom->getEnvelope(&oEnv); poMapFile->Coordsys2Int(oEnv.MinX, oEnv.MinY, m_nXMin, m_nYMin); poMapFile->Coordsys2Int(oEnv.MaxX, oEnv.MaxY, m_nXMax, m_nYMax); if ((m_nXMax - m_nXMin) < 65536 && (m_nYMax-m_nYMin) < 65536) { 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::WriteGeometryToMAPFile() * * * In derived classes, this method should be reimplemented to * write the geometry and representation (color, etc...) part of the * feature to the .MAP object pointed to by poMAPFile. * * It is assumed that before calling WriteGeometryToMAPFile(), poMAPFile * currently points to a valid map object. * * 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::WriteGeometryToMAPFile(TABMAPFile * /* poMapFile*/, TABMAPObjHdr * /*poObjHdr*/){ /*----------------------------------------------------------------- * Nothing to do... instances of TABFeature objects contain no geometry. *----------------------------------------------------------------*/ return 0;}/********************************************************************** * TABFeature::DumpMID() * * Dump feature attributes in a format similar to .MID data records. **********************************************************************/void TABFeature::DumpMID(FILE *fpOut /*=NULL*/){ OGRFeatureDefn *poDefn = GetDefnRef(); if (fpOut == NULL) fpOut = stdout; for( int iField = 0; iField < GetFieldCount(); iField++ ) { OGRFieldDefn *poFDefn = poDefn->GetFieldDefn(iField); fprintf( fpOut, " %s (%s) = %s\n", poFDefn->GetNameRef(), OGRFieldDefn::GetFieldTypeName(poFDefn->GetType()), GetFieldAsString( iField ) ); } fflush(fpOut);}/********************************************************************** * TABFeature::DumpMIF() * * Dump feature geometry in a format similar to .MIF files. **********************************************************************/void TABFeature::DumpMIF(FILE *fpOut /*=NULL*/){ if (fpOut == NULL) fpOut = stdout; /*----------------------------------------------------------------- * Generate output... not much to do, feature contains no geometry. *----------------------------------------------------------------*/ fprintf(fpOut, "NONE\n" ); fflush(fpOut);}/*===================================================================== * class TABPoint *====================================================================*//********************************************************************** * TABPoint::TABPoint() * * Constructor. **********************************************************************/TABPoint::TABPoint(OGRFeatureDefn *poDefnIn): TABFeature(poDefnIn){}/********************************************************************** * TABPoint::~TABPoint() * * Destructor. **********************************************************************/TABPoint::~TABPoint(){}/********************************************************************** * TABPoint::CloneTABFeature() * * Duplicate feature, including stuff specific to each TABFeature type. * * This method calls the generic TABFeature::CloneTABFeature() and * then copies any members specific to its own type. **********************************************************************/TABFeature *TABPoint::CloneTABFeature(OGRFeatureDefn *poNewDefn /*=NULL*/){ /*----------------------------------------------------------------- * Alloc new feature and copy the base stuff *----------------------------------------------------------------*/ TABPoint *poNew = new TABPoint(poNewDefn ? poNewDefn : GetDefnRef()); CopyTABFeatureBase(poNew); /*----------------------------------------------------------------- * And members specific to this class *----------------------------------------------------------------*/ // ITABFeatureSymbol *(poNew->GetSymbolDefRef()) = *GetSymbolDefRef(); return poNew;}/********************************************************************** * TABPoint::ValidateMapInfoType() * * Check the feature's geometry part and return the corresponding * mapinfo object type code. The m_nMapInfoType member will also * be updated for further calls to GetMapInfoType(); * * Returns TAB_GEOM_NONE if the geometry is not compatible with what * is expected for this object class. **********************************************************************/int TABPoint::ValidateMapInfoType(TABMAPFile *poMapFile /*=NULL*/){ OGRGeometry *poGeom; /*----------------------------------------------------------------- * Fetch and validate geometry * __TODO__ For now we always write in uncompressed format (until we * find that this is not correct... note that at this point the * decision to use compressed/uncompressed will likely be based on * the distance between the point and the object block center in * integer coordinates being > 32767 or not... remains to be verified) *----------------------------------------------------------------*/ poGeom = GetGeometryRef(); if (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbPoint) { switch(GetFeatureClass()) { case TABFCFontPoint: m_nMapInfoType = TAB_GEOM_FONTSYMBOL; break; case TABFCCustomPoint: m_nMapInfoType = TAB_GEOM_CUSTOMSYMBOL; break; case TABFCPoint: default: m_nMapInfoType = TAB_GEOM_SYMBOL; break; } } else { CPLError(CE_Failure, CPLE_AssertionFailed, "TABPoint: Missing or Invalid Geometry!"); m_nMapInfoType = TAB_GEOM_NONE; } return m_nMapInfoType;}/********************************************************************** * TABPoint::ReadGeometryFromMAPFile() * * 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 poMAPFile currently points to the beginning of * a map object. * * Returns 0 on success, -1 on error, in which case CPLError() will have * been called. **********************************************************************/int TABPoint::ReadGeometryFromMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *poObjHdr){ GInt32 nX, nY; double dX, dY; OGRGeometry *poGeometry; TABMAPObjectBlock *poObjBlock; GBool bComprCoord; /*----------------------------------------------------------------- * Fetch and validate geometry type *----------------------------------------------------------------*/ m_nMapInfoType = poMapFile->GetCurObjType(); poObjBlock = poMapFile->GetCurObjBlock(); bComprCoord = (m_nMapInfoType == TAB_GEOM_SYMBOL_C); /*----------------------------------------------------------------- * Read object information *----------------------------------------------------------------*/ if (m_nMapInfoType == TAB_GEOM_SYMBOL || m_nMapInfoType == TAB_GEOM_SYMBOL_C ) { poObjBlock->ReadIntCoord(bComprCoord, nX, nY); m_nSymbolDefIndex = poObjBlock->ReadByte(); // Symbol index poMapFile->ReadSymbolDef(m_nSymbolDefIndex, &m_sSymbolDef); } else { CPLError(CE_Failure, CPLE_AssertionFailed,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -