📄 mitab_tabview.cpp
字号:
delete m_poRelation; m_poRelation = NULL; m_bRelFieldsCreated = FALSE; return 0;}/********************************************************************** * TABView::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 TABView::GetNextFeatureId(int nPrevId){ if (m_nMainTableIndex != -1) return m_papoTABFiles[m_nMainTableIndex]->GetNextFeatureId(nPrevId); return -1;}/********************************************************************** * TABView::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 TABView 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. **********************************************************************/TABFeature *TABView::GetFeatureRef(int nFeatureId){ /*----------------------------------------------------------------- * Make sure file is opened *----------------------------------------------------------------*/ if (m_poRelation == NULL) { CPLError(CE_Failure, CPLE_IllegalArg, "GetFeatureRef() failed: file is not opened!"); return NULL; } if(m_poCurFeature) { delete m_poCurFeature; m_poCurFeature = NULL; } m_poCurFeature = m_poRelation->GetFeature(nFeatureId); m_nCurFeatureId = nFeatureId; m_poCurFeature->SetFID(m_nCurFeatureId); return m_poCurFeature;}/********************************************************************** * TABView::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 TABView::SetFeature(TABFeature *poFeature, int nFeatureId /*=-1*/){ if (m_eAccessMode != TABWrite) { CPLError(CE_Failure, CPLE_NotSupported, "SetFeature() can be used only with Write access."); return -1; } if (nFeatureId != -1) { CPLError(CE_Failure, CPLE_NotSupported, "SetFeature(): random access not implemented yet."); return -1; } if (m_poRelation == NULL) { CPLError(CE_Failure, CPLE_IllegalArg, "SetFeature() failed: file is not opened!"); return -1; } /*----------------------------------------------------------------- * If we're about to write the first feature, then we must finish * the initialization of the view first by creating the MI_refnum fields *----------------------------------------------------------------*/ if (!m_bRelFieldsCreated) { if (m_poRelation->CreateRelFields() != 0) return -1; m_bRelFieldsCreated = TRUE; } return m_poRelation->SetFeature(poFeature, nFeatureId);}/********************************************************************** * TABView::GetLayerDefn() * * Returns a reference to the OGRFeatureDefn that will be used to create * features in this dataset. * * Returns a reference to an object that is maintained by this TABView * object (and thus should not be modified or freed by the caller) or * NULL if the OGRFeatureDefn has not been initialized yet (i.e. no file * opened yet) **********************************************************************/OGRFeatureDefn *TABView::GetLayerDefn(){ if (m_poRelation) return m_poRelation->GetFeatureDefn(); return NULL;}/********************************************************************** * TABView::SetFeatureDefn() * * Set the FeatureDefn for this dataset. * * For now, fields passed through SetFeatureDefn will not be mapped * properly, so this function can be used only with an empty feature defn. **********************************************************************/int TABView::SetFeatureDefn(OGRFeatureDefn *poFeatureDefn, TABFieldType *paeMapInfoNativeFieldTypes /* =NULL */){ if (m_poRelation) return m_poRelation->SetFeatureDefn(poFeatureDefn); return -1;}/********************************************************************** * TABView::GetNativeFieldType() * * Returns the native MapInfo field type for the specified field. * * Returns TABFUnknown if file is not opened, or if specified field index is * invalid. * * Note that field ids are positive and start at 0. **********************************************************************/TABFieldType TABView::GetNativeFieldType(int nFieldId){ if (m_poRelation) return m_poRelation->GetNativeFieldType(nFieldId); return TABFUnknown;}/********************************************************************** * TABView::AddFieldNative() * * Create a new field using a native mapinfo data type... this is an * alternative to defining fields through the OGR interface. * This function should be called after creating a new dataset, but before * writing the first feature. * * This function will build/update the OGRFeatureDefn that will have to be * used when writing features to this dataset. * * A reference to the OGRFeatureDefn can be obtained using GetLayerDefn(). * * Returns 0 on success, -1 on error. **********************************************************************/int TABView::AddFieldNative(const char *pszName, TABFieldType eMapInfoType, int nWidth /*=0*/, int nPrecision /*=0*/, GBool bIndexed /*=FALSE*/, GBool bUnique/*=FALSE*/){ if (m_poRelation) return m_poRelation->AddFieldNative(pszName, eMapInfoType, nWidth, nPrecision, bIndexed, bUnique); return -1;}/********************************************************************** * TABView::SetFieldIndexed() * * Request that a field be indexed. This will create the .IND file if * necessary, etc. * * Note that field ids are positive and start at 0. * * Returns 0 on success, -1 on error. **********************************************************************/int TABView::SetFieldIndexed(int nFieldId){ if (m_poRelation) return m_poRelation->SetFieldIndexed(nFieldId); return -1;}/********************************************************************** * TABView::IsFieldIndexed() * * Returns TRUE if field is indexed, or FALSE otherwise. **********************************************************************/GBool TABView::IsFieldIndexed(int nFieldId){ if (m_poRelation) return m_poRelation->IsFieldIndexed(nFieldId); return FALSE;}/********************************************************************** * TABView::IsFieldUnique() * * Returns TRUE if field is in the Unique table, or FALSE otherwise. **********************************************************************/GBool TABView::IsFieldUnique(int nFieldId){ if (m_poRelation) return m_poRelation->IsFieldUnique(nFieldId); return FALSE;}/********************************************************************** * TABView::GetBounds() * * Fetch projection coordinates bounds of a dataset. * * The bForce flag has no effect on TAB files since the bounds are * always in the header. * * Returns 0 on success, -1 on error. **********************************************************************/int TABView::GetBounds(double &dXMin, double &dYMin, double &dXMax, double &dYMax, GBool bForce /*= TRUE*/){ if (m_nMainTableIndex == -1) { CPLError(CE_Failure, CPLE_AppDefined, "GetBounds() can be called only after dataset has been opened."); return -1; } return m_papoTABFiles[m_nMainTableIndex]->GetBounds(dXMin, dYMin, dXMax, dYMax, bForce);}/********************************************************************** * TABView::GetExtent() * * Fetch extent of the data currently stored in the dataset. * * The bForce flag has no effect on TAB files since that value is * always in the header. * * Returns OGRERR_NONE/OGRRERR_FAILURE. **********************************************************************/OGRErr TABView::GetExtent (OGREnvelope *psExtent, int bForce){ if (m_nMainTableIndex == -1) { CPLError(CE_Failure, CPLE_AppDefined, "GetExtent() can be called only after dataset has been opened."); return -1; } return m_papoTABFiles[m_nMainTableIndex]->GetExtent(psExtent, bForce);}/********************************************************************** * TABView::GetFeatureCountByType() * * Return number of features of each type. * * Note that the sum of the 4 returned values may be different from * the total number of features since features with NONE geometry * are not taken into account here. * * Note: the bForce flag has nmo effect on .TAB files since the info * is always in the header. * * Returns 0 on success, or silently returns -1 (with no error) if this * information is not available. **********************************************************************/int TABView::GetFeatureCountByType(int &numPoints, int &numLines, int &numRegions, int &numTexts, GBool bForce /*= TRUE*/){ if (m_nMainTableIndex == -1) return -1; return m_papoTABFiles[m_nMainTableIndex]->GetFeatureCountByType(numPoints, numLines, numRegions, numTexts, bForce);}/********************************************************************** * TABView::GetSpatialRef() * * Returns a reference to an OGRSpatialReference for this dataset. * If the projection parameters have not been parsed yet, then we will * parse them before returning. * * The returned object is owned and maintained by this TABFile and * should not be modified or freed by the caller. * * Returns NULL if the SpatialRef cannot be accessed. **********************************************************************/OGRSpatialReference *TABView::GetSpatialRef(){ if (m_nMainTableIndex == -1) { CPLError(CE_Failure, CPLE_AssertionFailed, "GetSpatialRef() failed: file has not been opened yet."); return NULL; } return m_papoTABFiles[m_nMainTableIndex]->GetSpatialRef();}/********************************************************************** * TABView::SetSpatialRef() **********************************************************************/int TABView::SetSpatialRef(OGRSpatialReference *poSpatialRef){ if (m_nMainTableIndex == -1) { CPLError(CE_Failure, CPLE_AssertionFailed, "SetSpatialRef() failed: file has not been opened yet."); return -1; } return m_papoTABFiles[m_nMainTableIndex]->SetSpatialRef(poSpatialRef);}/********************************************************************** * TABView::SetBounds() **********************************************************************/int TABView::SetBounds(double dXMin, double dYMin, double dXMax, double dYMax){ if (m_nMainTableIndex == -1) { CPLError(CE_Failure, CPLE_AssertionFailed, "SetBounds() failed: file has not been opened yet."); return -1; } return m_papoTABFiles[m_nMainTableIndex]->SetBounds(dXMin, dYMin, dXMax, dYMax);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -