?? mitab_tabfile.cpp
字號:
delete m_poMAPFile; m_poMAPFile = NULL; } if (m_poDATFile) { m_poDATFile->Close(); delete m_poDATFile; m_poDATFile = NULL; } if (m_poINDFile) { m_poINDFile->Close(); delete m_poINDFile; m_poINDFile = NULL; } if (m_poCurFeature) { delete m_poCurFeature; m_poCurFeature = NULL; } /*----------------------------------------------------------------- * Note: we have to check the reference count before deleting * m_poSpatialRef and m_poDefn *----------------------------------------------------------------*/ if (m_poDefn ) { int nRefCount = m_poDefn->Dereference(); CPLAssert( nRefCount >= 0 ); if( nRefCount == 0 ) delete m_poDefn; m_poDefn = NULL; } if (m_poSpatialRef && m_poSpatialRef->Dereference() == 0) delete m_poSpatialRef; m_poSpatialRef = NULL; CSLDestroy(m_papszTABFile); m_papszTABFile = NULL; CPLFree(m_pszFname); m_pszFname = NULL; CPLFree(m_pszCharset); m_pszCharset = NULL; CPLFree(m_panIndexNo); m_panIndexNo = NULL; return 0;}/********************************************************************** * TABFile::GetNextFeatureId() * * Returns feature id that follows nPrevId, or -1 if it is the * last feature id. Pass nPrevId=-1 to fetch the first valid feature id. **********************************************************************/int TABFile::GetNextFeatureId(int nPrevId){ if (m_eAccessMode != TABRead) { CPLError(CE_Failure, CPLE_NotSupported, "GetNextFeatureId() can be used only with Read access."); return -1; } /*----------------------------------------------------------------- * Are we using spatial rather than .ID based traversal? *----------------------------------------------------------------*/ if( bUseSpatialTraversal ) return m_poMAPFile->GetNextFeatureId( nPrevId ); /*----------------------------------------------------------------- * Establish what the next logical feature ID should be *----------------------------------------------------------------*/ int nFeatureId = -1; if (nPrevId <= 0 && m_nLastFeatureId > 0) nFeatureId = 1; // Feature Ids start at 1 else if (nPrevId > 0 && nPrevId < m_nLastFeatureId) nFeatureId = nPrevId + 1; else { // This was the last feature return OGRNullFID; } /*----------------------------------------------------------------- * Skip any feature with NONE geometry and a deleted attribute record *----------------------------------------------------------------*/ while(nFeatureId <= m_nLastFeatureId) { if ( m_poMAPFile->MoveToObjId(nFeatureId) != 0 || m_poDATFile->GetRecordBlock(nFeatureId) == NULL ) { CPLError(CE_Failure, CPLE_IllegalArg, "GetNextFeatureId() failed: unable to set read pointer " "to feature id %d", nFeatureId); return -1; }// __TODO__ Add a test here to check if object is deleted, // i.e. 0x40 set on object_id in object block if (m_poMAPFile->GetCurObjType() != TAB_GEOM_NONE || m_poDATFile->IsCurrentRecordDeleted() == FALSE) { // This feature contains at least a geometry or some attributes... // return its id. return nFeatureId; } nFeatureId++; } // If we reached this point, then we kept skipping deleted features // and stopped when EOF was reached. return -1;}/********************************************************************** * TABFile::GetNextFeatureId_Spatial() * * Returns feature id that follows nPrevId, or -1 if it is the * last feature id, but by traversing the spatial tree instead of the * direct object index. Generally speaking the feature id's will be * returned in an unordered fashion. **********************************************************************/int TABFile::GetNextFeatureId_Spatial(int nPrevId){ if (m_eAccessMode != TABRead) { CPLError(CE_Failure, CPLE_NotSupported, "GetNextFeatureId_Spatial() can be used only with Read access."); return -1; } if( m_poMAPFile == NULL ) { CPLError(CE_Failure, CPLE_NotSupported, "GetNextFeatureId_Spatial() requires availability of .MAP file." ); return -1; } return m_poMAPFile->GetNextFeatureId( nPrevId );}/********************************************************************** * TABFile::GetFeatureRef() * * Fill and return a TABFeature object for the specified feature id. * * The retruned pointer is a reference to an object owned and maintained * by this TABFile object. It should not be altered or freed by the * caller and its contents is guaranteed to be valid only until the next * call to GetFeatureRef() or Close(). * * Returns NULL if the specified feature id does not exist of if an * error happened. In any case, CPLError() will have been called to * report the reason of the failure. * * If an unsupported object type is encountered (likely from a newer version * of MapInfo) then a valid feature will be returned with a NONE geometry, * and a warning will be produced with code TAB_WarningFeatureTypeNotSupported * CPLGetLastErrorNo() should be used to detect that case. **********************************************************************/TABFeature *TABFile::GetFeatureRef(int nFeatureId){ CPLErrorReset(); if (m_eAccessMode != TABRead) { CPLError(CE_Failure, CPLE_NotSupported, "GetFeatureRef() can be used only with Read access."); return NULL; } /*----------------------------------------------------------------- * Make sure file is opened and Validate feature id by positioning * the read pointers for the .MAP and .DAT files to this feature id. *----------------------------------------------------------------*/ if (m_poMAPFile == NULL) { CPLError(CE_Failure, CPLE_IllegalArg, "GetFeatureRef() failed: file is not opened!"); return NULL; } if (nFeatureId <= 0 || nFeatureId > m_nLastFeatureId || m_poMAPFile->MoveToObjId(nFeatureId) != 0 || m_poDATFile->GetRecordBlock(nFeatureId) == NULL ) { // CPLError(CE_Failure, CPLE_IllegalArg, // "GetFeatureRef() failed: invalid feature id %d", // nFeatureId); return NULL; } /*----------------------------------------------------------------- * Flush current feature object * __TODO__ try to reuse if it is already of the right type *----------------------------------------------------------------*/ if (m_poCurFeature) { delete m_poCurFeature; m_poCurFeature = NULL; } /*----------------------------------------------------------------- * Create new feature object of the right type *----------------------------------------------------------------*/ switch(m_poMAPFile->GetCurObjType()) { case TAB_GEOM_NONE: m_poCurFeature = new TABFeature(m_poDefn); break; case TAB_GEOM_SYMBOL_C: case TAB_GEOM_SYMBOL: m_poCurFeature = new TABPoint(m_poDefn); break; case TAB_GEOM_FONTSYMBOL_C: case TAB_GEOM_FONTSYMBOL: m_poCurFeature = new TABFontPoint(m_poDefn); break; case TAB_GEOM_CUSTOMSYMBOL_C: case TAB_GEOM_CUSTOMSYMBOL: m_poCurFeature = new TABCustomPoint(m_poDefn); break; case TAB_GEOM_LINE_C: case TAB_GEOM_LINE: case TAB_GEOM_PLINE_C: case TAB_GEOM_PLINE: case TAB_GEOM_MULTIPLINE_C: case TAB_GEOM_MULTIPLINE: case TAB_GEOM_V450_MULTIPLINE_C: case TAB_GEOM_V450_MULTIPLINE: m_poCurFeature = new TABPolyline(m_poDefn); break; case TAB_GEOM_ARC_C: case TAB_GEOM_ARC: m_poCurFeature = new TABArc(m_poDefn); break; case TAB_GEOM_REGION_C: case TAB_GEOM_REGION: case TAB_GEOM_V450_REGION_C: case TAB_GEOM_V450_REGION: m_poCurFeature = new TABRegion(m_poDefn); break; case TAB_GEOM_RECT_C: case TAB_GEOM_RECT: case TAB_GEOM_ROUNDRECT_C: case TAB_GEOM_ROUNDRECT: m_poCurFeature = new TABRectangle(m_poDefn); break; case TAB_GEOM_ELLIPSE_C: case TAB_GEOM_ELLIPSE: m_poCurFeature = new TABEllipse(m_poDefn); break; case TAB_GEOM_TEXT_C: case TAB_GEOM_TEXT: m_poCurFeature = new TABText(m_poDefn); break; case TAB_GEOM_MULTIPOINT_C: case TAB_GEOM_MULTIPOINT: m_poCurFeature = new TABMultiPoint(m_poDefn); break; case TAB_GEOM_COLLECTION_C: case TAB_GEOM_COLLECTION: m_poCurFeature = new TABCollection(m_poDefn); break; default: /*------------------------------------------------------------- * Unsupported feature type... we still return a valid feature * with NONE geometry after producing a Warning. * Callers can trap that case by checking CPLGetLastErrorNo() * against TAB_WarningFeatureTypeNotSupported *------------------------------------------------------------*/// m_poCurFeature = new TABDebugFeature(m_poDefn); m_poCurFeature = new TABFeature(m_poDefn); CPLError(CE_Warning, TAB_WarningFeatureTypeNotSupported, "Unsupported object type %d (0x%2.2x). Feature will be " "returned with NONE geometry.", m_poMAPFile->GetCurObjType(), m_poMAPFile->GetCurObjType() ); } /*----------------------------------------------------------------- * Read fields from the .DAT file * GetRecordBlock() has already been called above... *----------------------------------------------------------------*/ if (m_poCurFeature->ReadRecordFromDATFile(m_poDATFile) != 0) { delete m_poCurFeature; m_poCurFeature = NULL; return NULL; } /*----------------------------------------------------------------- * Read geometry from the .MAP file * MoveToObjId() has already been called above... *----------------------------------------------------------------*/ TABMAPObjHdr *poObjHdr = TABMAPObjHdr::NewObj(m_poMAPFile->GetCurObjType(), m_poMAPFile->GetCurObjId()); // Note that poObjHdr==NULL is a valid case if geometry type is NONE if ((poObjHdr && poObjHdr->ReadObj(m_poMAPFile->GetCurObjBlock()) != 0) || m_poCurFeature->ReadGeometryFromMAPFile(m_poMAPFile, poObjHdr) != 0) { delete m_poCurFeature; m_poCurFeature = NULL; if (poObjHdr) delete poObjHdr; return NULL; } if (poObjHdr) // May be NULL if feature geometry type is NONE delete poObjHdr; m_nCurFeatureId = nFeatureId; m_poCurFeature->SetFID(m_nCurFeatureId); m_poCurFeature->SetRecordDeleted(m_poDATFile->IsCurrentRecordDeleted()); return m_poCurFeature;}/********************************************************************** * TABFile::SetFeature() * * Write a feature to this dataset. * * For now only sequential writes are supported (i.e. with nFeatureId=-1) * but eventually we should be able to do random access by specifying * a value through nFeatureId. * * Returns the new featureId (> 0) on success, or -1 if an * error happened in which case, CPLError() will have been called to * report the reason of the failure. **********************************************************************/int TABFile::SetFeature(TABFeature *poFeature, int nFeatureId /*=-1*/){ if (m_eAccessMode != TABWrite)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -