⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tabseamless.cpp

📁 linux下一款GIS程序源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    else    {        TABFeature *poIndexFeature = m_poIndexTable->GetFeatureRef(nTableId);            if (poIndexFeature)        {            if (OpenBaseTable(poIndexFeature, bTestOpenNoError) != 0)            {                // Open Failed... an error has already been reported.                if (bTestOpenNoError)                    UGKErrorReset();                return -1;            }        }    }    return 0;}/********************************************************************** *                   TABSeamless::OpenNextBaseTable() * * Open the next base table in the dataset, using GetNextFeature() so that * the spatial filter is respected. * * m_bEOF will be set if there are no more base tables to read. * * Returns 0 on success, -1 on error. **********************************************************************/int TABSeamless::OpenNextBaseTable(UGKBool bTestOpenNoError /*=FALSE*/){    assert(m_poIndexTable);    TABFeature *poIndexFeature = (TABFeature*)m_poIndexTable->GetNextFeature();        if (poIndexFeature)    {        if (OpenBaseTable(poIndexFeature, bTestOpenNoError) != 0)        {            // Open Failed... an error has already been reported.            if (bTestOpenNoError)                UGKErrorReset();            delete poIndexFeature;            return -1;        }        delete poIndexFeature;        m_bEOF = FALSE;    }    else    {        // Reached EOF        m_bEOF = TRUE;    }    return 0;}/********************************************************************** *                   TABSeamless::EncodeFeatureId() * * Combine the table id + feature id into a single feature id that should * be unique amongst all base tables in this seamless dataset. * * We reserve some bits in the feature id for the table id based on the * number of features in the index table.  This reduces the available range * of feature ids for each base table... for instance, if the index contains * 65000 entries, then each base table will be limited to 65535 features. * * If the number of features in a base table exceeds the number of bits * available (e.g. 65535 inthe above example) then the feature ids will * wrap for this table and thus it will be impossible to access some of * the features unless the caller uses only calls to GetNextFeature() and * avoids calls to GetFeatureRef(). **********************************************************************/int TABSeamless::EncodeFeatureId(int nTableId, int nBaseFeatureId){    if (nTableId == -1 || nBaseFeatureId == -1)        return -1;    /*-----------------------------------------------------------------     * __TODO__ For now we hardcode the bitmasks to be 12 bits for tableid     *          and 20 bits for base feature id, but we should really     *          base the numbers of bits on the number of features in     *          the index table.     *----------------------------------------------------------------*/    return (nTableId*0x00100000 + nBaseFeatureId);}int TABSeamless::ExtractBaseTableId(int nEncodedFeatureId){    if (nEncodedFeatureId == -1)        return -1;    return (nEncodedFeatureId/0x00100000);}int TABSeamless::ExtractBaseFeatureId(int nEncodedFeatureId){    if (nEncodedFeatureId == -1)        return -1;    return (nEncodedFeatureId & 0x000fffff);}/********************************************************************** *                   TABSeamless::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 TABSeamless::GetNextFeatureId(int nPrevId){    if (m_poIndexTable == NULL)        return -1; // File is not opened yet    if (nPrevId == -1 || m_nCurBaseTableId != ExtractBaseTableId(nPrevId))    {        if (OpenBaseTable(ExtractBaseTableId(nPrevId)) != 0)            return -1;    }    int nId = ExtractBaseFeatureId(nPrevId);    do    {        nId = m_poCurBaseTable->GetNextFeatureId(nId);        if (nId != -1)            return EncodeFeatureId(m_nCurBaseTableId, nId);  // Found one!        else            OpenNextBaseTable();  // Skip to next tile and loop again    } while (nId == -1 && !m_bEOF && m_poCurBaseTable);    return -1;}/********************************************************************** *                   TABSeamless::GetFeatureRef() * * Fill and return a TABFeature object for the specified feature id. * * The returned pointer is a reference to an object owned and maintained * by this TABSeamless 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 *TABSeamless::GetFeatureRef(int nFeatureId){    if (m_poIndexTable == NULL)        return NULL; // File is not opened yet    if (nFeatureId == m_nCurFeatureId && m_poCurFeature)        return m_poCurFeature;    if (m_nCurBaseTableId != ExtractBaseTableId(nFeatureId))    {        if (OpenBaseTable(ExtractBaseTableId(nFeatureId)) != 0)            return NULL;    }    if (m_poCurBaseTable)    {        if (m_poCurFeature)            delete m_poCurFeature;        m_poCurFeature = (TABFeature*)m_poCurBaseTable->GetFeature(ExtractBaseFeatureId(nFeatureId));        m_nCurFeatureId = nFeatureId;        m_poCurFeature->SetFID(nFeatureId);        return m_poCurFeature;    }    return NULL;}/********************************************************************** *                   TABSeamless::GetLayerDefn() * * Returns a reference to the UGKFeatureDefn that will be used to create * features in this dataset. * * Returns a reference to an object that is maintained by this TABSeamless * object (and thus should not be modified or freed by the caller) or * NULL if the UGKFeatureDefn has not been initialized yet (i.e. no file * opened yet) **********************************************************************/UGKFeatureDefn *TABSeamless::GetLayerDefn(){    return m_poFeatureDefnRef;}/********************************************************************** *                   TABSeamless::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 TABSeamless::GetNativeFieldType(int nFieldId){    if (m_poCurBaseTable)        return m_poCurBaseTable->GetNativeFieldType(nFieldId);    return TABFUnknown;}/********************************************************************** *                   TABSeamless::IsFieldIndexed() * * Returns TRUE if field is indexed, or FALSE otherwise. **********************************************************************/UGKBool TABSeamless::IsFieldIndexed(int nFieldId){    if (m_poCurBaseTable)        return m_poCurBaseTable->IsFieldIndexed(nFieldId);    return FALSE;}/********************************************************************** *                   TABSeamless::IsFieldUnique() * * Returns TRUE if field is in the Unique table, or FALSE otherwise. **********************************************************************/UGKBool TABSeamless::IsFieldUnique(int nFieldId){    if (m_poCurBaseTable)        return m_poCurBaseTable->IsFieldUnique(nFieldId);    return FALSE;}/********************************************************************** *                   TABSeamless::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 TABSeamless::GetBounds(double &dXMin, double &dYMin,                        double &dXMax, double &dYMax,                       UGKBool bForce /*= TRUE*/){    if (m_poIndexTable == NULL)    {        UGKError(ET_Failure, UGKErr_AppDefined,             "GetBounds() can be called only after dataset has been opened.");        return -1;    }    return m_poIndexTable->GetBounds(dXMin, dYMin, dXMax, dYMax, bForce);}/********************************************************************** *                   TABSeamless::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 UGKERR_NONE/UGKRERR_FAILURE. **********************************************************************/UGKErr TABSeamless::GetExtent (UGKEnvelope *psExtent, int bForce){    if (m_poIndexTable == NULL)    {        UGKError(ET_Failure, UGKErr_AppDefined,             "GetExtent() can be called only after dataset has been opened.");        return UGKERR_FAILURE;    }    return m_poIndexTable->GetExtent(psExtent, bForce);}/********************************************************************** *                   TABSeamless::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. * * Returns 0 on success, or silently returns -1 (with no error) if this * information is not available. **********************************************************************/int TABSeamless::GetFeatureCountByType(int &numPoints, int &numLines,                                   int &numRegions, int &numTexts,                                   UGKBool bForce /*= TRUE*/){    /*-----------------------------------------------------------------     * __TODO__  This should be implemented to return -1 if force=false,     * or scan all the base tables if force=true     *----------------------------------------------------------------*/    return -1;}int TABSeamless::GetFeatureCount(int bForce){    /*-----------------------------------------------------------------     * __TODO__  This should be implemented to return -1 if force=false,     * or scan all the base tables if force=true     *----------------------------------------------------------------*/    return UGKLayer::GetFeatureCount(bForce);}/************************************************************************//*                           TestCapability()                           *//************************************************************************/int TABSeamless::TestCapability( const char * pszCap ){    if( EQUAL(pszCap,OLCRandomRead) )        return TRUE;    else if( EQUAL(pszCap,OLCSequentialWrite)              || EQUAL(pszCap,OLCRandomWrite) )        return FALSE;    else if( EQUAL(pszCap,OLCFastFeatureCount) )        return FALSE;    else if( EQUAL(pszCap,OLCFastSpatialFilter) )        return FALSE;    else if( EQUAL(pszCap,OLCFastGetExtent) )        return TRUE;    else         return FALSE;}/********************************************************************** *                   TABSeamless::Dump() * * Dump block contents... available only in DEBUG mode. **********************************************************************/void TABSeamless::Dump(FILE *fpOut /*=NULL*/){    if (fpOut == NULL)        fpOut = stdout;    fprintf(fpOut, "----- TABSeamless::Dump() -----\n");    if (m_poIndexTable == NULL)    {        fprintf(fpOut, "File is not opened.\n");    }    else    {        fprintf(fpOut, "File is opened: %s\n", m_pszFname);    }    fflush(fpOut);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -