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

📄 tabfile.cpp

📁 linux下一款GIS程序源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
                    poFieldDefn = new UGKFieldDefn(papszTok[0], OFTString);                    poFieldDefn->SetWidth(10);                }                else if (numTok >= 2 && EQUAL(papszTok[1], "logical"))                {                    /*-------------------------------------------------                     * LOGICAL type (value "T" or "F")                     *------------------------------------------------*/                    nStatus = m_poDATFile->ValidateFieldInfoFromTAB(iField,                                                                papszTok[0],                                                               TABFLogical,                                                               0,                                                               0);                    poFieldDefn = new UGKFieldDefn(papszTok[0], OFTString);                    poFieldDefn->SetWidth(1);                }                else                     nStatus = -1; // Unrecognized field type or line corrupt                if (nStatus != 0)                {                    UGKError(ET_Failure, UGKErr_FileIO,                     "Failed to parse field definition at line %d in file %s",                              iLine+1, m_pszFname);                    FreeStrList(papszTok);                    return -1;                }                /*-----------------------------------------------------                 * Keep track of index number if present                 *----------------------------------------------------*/                if (numTok >= 4 && EQUAL(papszTok[numTok-2], "index"))                {                    m_panIndexNo[iField] = atoi(papszTok[numTok-1]);                }                else                {                    m_panIndexNo[iField] = 0;                }                /*-----------------------------------------------------                 * Add the FieldDefn to the FeatureDefn and continue with                 * the next one.                 *----------------------------------------------------*/                m_poDefn->AddFieldDefn(poFieldDefn);                // AddFieldDenf() takes a copy, so we delete the original                if (poFieldDefn) delete poFieldDefn;                poFieldDefn = NULL;            }            /*---------------------------------------------------------             * OK, we're done... end the loop now.             *--------------------------------------------------------*/            break;        }/* end of fields section*/        else        {            // Simply Ignore unrecognized lines        }    }    FreeStrList(papszTok);    if (m_poDefn->GetFieldCount() == 0)    {        UGKError(ET_Failure, UGKErr_NotSupported,                 "%s contains no table field definition.  "                 "This type of .TAB file cannot be read by this library.",                 m_pszFname);        return -1;    }    return 0;}/********************************************************************** *                   TABFile::WriteTABFile() * * Generate the .TAB file using mainly the attribute fields definition. * * This private method should be used only during the Close() call with * write access mode. * * Returns 0 on success, -1 on error. **********************************************************************/int TABFile::WriteTABFile(){    FILE *fp;    if (m_eAccessMode != TABWrite)    {        UGKError(ET_Failure, UGKErr_NotSupported,                 "WriteTABFile() can be used only with Write access.");        return -1;    }    if ( (fp = fopen(m_pszFname, "wt")) != NULL)    {        fprintf(fp, "!table\n");        fprintf(fp, "!version %d\n", m_nVersion);        fprintf(fp, "!charset %s\n", m_pszCharset);        fprintf(fp, "\n");        if (m_poDefn && m_poDefn->GetFieldCount() > 0)        {            int iField;            UGKFieldDefn *poFieldDefn;            const char *pszFieldType;            fprintf(fp, "Definition Table\n");            fprintf(fp, "  Type NATIVE Charset \"%s\"\n", m_pszCharset);            fprintf(fp, "  Fields %d\n", m_poDefn->GetFieldCount());            for(iField=0; iField<m_poDefn->GetFieldCount(); iField++)            {                poFieldDefn = m_poDefn->GetFieldDefn(iField);                switch(GetNativeFieldType(iField))                {                  case TABFChar:                    pszFieldType = UGKSPrintf("Char (%d)",                                               poFieldDefn->GetWidth());                    break;                  case TABFDecimal:                    pszFieldType = UGKSPrintf("Decimal (%d,%d)",                                              poFieldDefn->GetWidth(),                                              poFieldDefn->GetPrecision());                    break;                  case TABFInteger:                    pszFieldType = "Integer";                    break;                  case TABFSmallInt:                    pszFieldType = "SmallInt";                    break;                  case TABFFloat:                    pszFieldType = "Float";                    break;                  case TABFLogical:                    pszFieldType = "Logical";                    break;                  case TABFDate:                    pszFieldType = "Date";                    break;                  default:                    // Unsupported field type!!!  This should never happen.                    UGKError(ET_Failure, UGKErr_AssertionFailed,                             "WriteTABFile(): Unsupported field type");                    fclose(fp);                    return -1;                }                if (GetFieldIndexNumber(iField) == 0)                {                    fprintf(fp, "    %s %s ;\n", poFieldDefn->GetNameRef(),                             pszFieldType );                }                else                {                    fprintf(fp, "    %s %s Index %d ;\n",                             poFieldDefn->GetNameRef(), pszFieldType,                            GetFieldIndexNumber(iField) );                }                            }        }        else        {            fprintf(fp, "Definition Table\n");            fprintf(fp, "  Type NATIVE Charset \"%s\"\n", m_pszCharset);            fprintf(fp, "  Fields 1\n");            fprintf(fp, "    FID Integer ;\n" );        }        fclose(fp);    }    else    {        UGKError(ET_Failure, UGKErr_FileIO,                 "Failed to create file `%s'", m_pszFname);        return -1;    }    return 0;}/********************************************************************** *                   TABFile::Close() * * Close current file, and release all memory used. * * Returns 0 on success, -1 on error. **********************************************************************/int TABFile::Close(){    // Commit the latest changes to the file...        // In Write access, it's time to write the .TAB file.    if (m_eAccessMode == TABWrite && m_poMAPFile)    {        // First update file version number...        int nMapObjVersion = m_poMAPFile->GetMinTABFileVersion();        m_nVersion =(m_nVersion>nMapObjVersion) ? m_nVersion : nMapObjVersion;         WriteTABFile();    }    if (m_poMAPFile)    {        m_poMAPFile->Close();        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();        assert( nRefCount >= 0 );        if( nRefCount == 0 )           delete m_poDefn;        m_poDefn = NULL;    }                FreeStrList(m_papszTABFile);    m_papszTABFile = NULL;    UGK_Free(m_pszFname);    m_pszFname = NULL;    UGK_Free(m_pszCharset);    m_pszCharset = NULL;    UGK_Free(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)    {        UGKError(ET_Failure, UGKErr_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 UGKNullFID;    }    /*-----------------------------------------------------------------     * 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 )        {            UGKError(ET_Failure, UGKErr_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)    {        UGKError(ET_Failure, UGKErr_NotSupported,            "GetNextFeatureId_Spatial() can be used only with Read access.");        return -1;    }    if( m_poMAPFile == NULL )    {

⌨️ 快捷键说明

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