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

📄 tabfile.cpp

📁 linux下一款GIS程序源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    {        /*-------------------------------------------------------------         * Read access: .MAP/.ID are optional... try to open but return         * no error if files do not exist.         *------------------------------------------------------------*/        if (m_poMAPFile->Open(pszTmpFname, pszAccess, TRUE) < 0)        {            // File exists, but Open Failed...             // we have to produce an error message            if (!bTestOpenNoError)                UGKError(ET_Failure, UGKErr_FileIO,                          "Open() failed for %s", pszTmpFname);            else                UGKErrorReset();            UGK_Free(pszTmpFname);            Close();            return -1;        }        /*-------------------------------------------------------------         * Set geometry type if the geometry objects are uniform.         *------------------------------------------------------------*/        int numPoints=0, numRegions=0, numTexts=0, numLines=0;        GetFeatureCountByType( numPoints, numLines, numRegions, numTexts);        numPoints += numTexts;        if( numPoints > 0 && numLines == 0 && numRegions == 0 )            m_poDefn->SetGeomType( wkbPoint );        else if( numPoints == 0 && numLines > 0 && numRegions == 0 )            m_poDefn->SetGeomType( wkbLineString );        else if( numPoints == 0 && numLines == 0 && numRegions > 0 )            m_poDefn->SetGeomType( wkbPolygon );        else            /* we leave it unknown indicating a mixture */;    }    else if (m_poMAPFile->Open(pszTmpFname, pszAccess) != 0)    {        // Open Failed for write...         // an error has already been reported, just return.        UGK_Free(pszTmpFname);        Close();        if (bTestOpenNoError)            UGKErrorReset();        return -1;    }    UGK_Free(pszTmpFname);    pszTmpFname = NULL;    /*-----------------------------------------------------------------     * __TODO__ we could probably call GetSpatialRef() here to force     * parsing the projection information... this would allow us to      * assignSpatialReference() on the geometries that we return.     *----------------------------------------------------------------*/    return 0;}/********************************************************************** *                   TABFile::ParseTABFileFirstPass() * * Do a first pass in the TAB header file to establish the table type, etc. * and store any useful information into class members. * * This private method should be used only during the Open() call. * * Returns 0 on success, -1 on error. **********************************************************************/int TABFile::ParseTABFileFirstPass(UGKBool bTestOpenNoError){    int         iLine, numLines, numFields = 0;    char        **papszTok=NULL;    UGKBool       bInsideTableDef = FALSE, bFoundTableFields=FALSE;    if (m_eAccessMode != TABRead)    {       UGKError(ET_Failure, UGKErr_NotSupported,                 "ParseTABFile() can be used only with Read access.");        return -1;    }    numLines = CountOfList(m_papszTABFile);    for(iLine=0; iLine<numLines; iLine++)    {        /*-------------------------------------------------------------         * Tokenize the next .TAB line, and check first keyword         *------------------------------------------------------------*/        FreeStrList(papszTok);        papszTok = TokenizeStringComplex(m_papszTABFile[iLine], " \t(),;",                                            TRUE, FALSE);        if (CountOfList(papszTok) < 2)            continue;   // All interesting lines have at least 2 tokens        if (EQUAL(papszTok[0], "!version"))        {            m_nVersion = atoi(papszTok[1]);            if (m_nVersion == 100)            {                /* Version 100 files contain only the fields definition,                 * so we set default values for the other params.                 */                bInsideTableDef = TRUE;                m_pszCharset = UGKStrdup("Neutral");                m_eTableType = TABTableNative;            }        }        else if (EQUAL(papszTok[0], "!edit_version"))        {            /* Sometimes, V450 files have version 300 + edit_version 450             * for us version and edit_version are the same              */            m_nVersion = atoi(papszTok[1]);        }        else if (EQUAL(papszTok[0], "!charset"))        {            m_pszCharset = UGKStrdup(papszTok[1]);        }        else if (EQUAL(papszTok[0], "Definition") &&                 EQUAL(papszTok[1], "Table") )        {            bInsideTableDef = TRUE;        }        else if (bInsideTableDef && !bFoundTableFields &&                 (EQUAL(papszTok[0], "Type") || EQUAL(papszTok[0],"FORMAT:")) )        {            if (EQUAL(papszTok[1], "NATIVE") || EQUAL(papszTok[1], "LINKED"))                m_eTableType = TABTableNative;            else if (EQUAL(papszTok[1], "DBF"))                m_eTableType = TABTableDBF;            else            {                // Type=ACCESS, or other unsupported type... cannot open!                if (!bTestOpenNoError)                    UGKError(ET_Failure, UGKErr_NotSupported,                             "Unsupported table type '%s' in file %s.  "                      "This type of .TAB file cannot be read by this library.",                             papszTok[1], m_pszFname);                FreeStrList(papszTok);                return -1;            }        }        else if (bInsideTableDef && !bFoundTableFields &&                 (EQUAL(papszTok[0],"Fields") || EQUAL(papszTok[0],"FIELDS:")))        {            /*---------------------------------------------------------             * We found the list of table fields             * Just remember number of fields... the field types will be             * parsed inside ParseTABFileFields() later...             *--------------------------------------------------------*/            bFoundTableFields = TRUE;            numFields = atoi(papszTok[1]);            if (numFields < 1 || numFields>2048 || iLine+numFields >= numLines)            {                if (!bTestOpenNoError)                    UGKError(ET_Failure, UGKErr_FileIO,                         "Invalid number of fields (%s) at line %d in file %s",                             papszTok[1], iLine+1, m_pszFname);                FreeStrList(papszTok);                return -1;            }            bInsideTableDef = FALSE;        }/* end of fields section*/        else        {            // Simply Ignore unrecognized lines        }    }    FreeStrList(papszTok);    if (m_pszCharset == NULL)        m_pszCharset = UGKStrdup("Neutral");    if (numFields == 0)    {        if (!bTestOpenNoError)            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::ParseTABFileFields() * * Extract the field definition from the TAB header file, validate * with what we have in the previously opened .DAT or .DBF file, and  * finally build the m_poDefn UGKFeatureDefn for this dataset. * * This private method should be used only during the Open() call and after * ParseTABFileFirstPass() has been called. * * Returns 0 on success, -1 on error. **********************************************************************/int TABFile::ParseTABFileFields(){    int         iLine, numLines=0, numTok, nStatus;    char        **papszTok=NULL;    UGKFieldDefn *poFieldDefn;    if (m_eAccessMode != TABRead)    {        UGKError(ET_Failure, UGKErr_NotSupported,                 "ParseTABFile() can be used only with Read access.");        return -1;    }    char *pszFeatureClassName = TABGetBasename(m_pszFname);    m_poDefn = new UGKFeatureDefn(pszFeatureClassName);    UGK_Free(pszFeatureClassName);    // Ref count defaults to 0... set it to 1    m_poDefn->Reference();    /*-------------------------------------------------------------     * Scan for fields.     *------------------------------------------------------------*/    numLines = CountOfList(m_papszTABFile);    for(iLine=0; iLine<numLines; iLine++)    {        /*-------------------------------------------------------------         * Tokenize the next .TAB line, and check first keyword         *------------------------------------------------------------*/        const char *pszStr = m_papszTABFile[iLine];        while(*pszStr != '\0' && isspace(*pszStr))            pszStr++;        if (EQUALN(pszStr, "Fields", 6))        {            /*---------------------------------------------------------             * We found the list of table fields             *--------------------------------------------------------*/            int iField, numFields;            numFields = atoi(pszStr+7);            if (numFields < 1 || numFields > 2048 ||                 iLine+numFields >= numLines)            {                UGKError(ET_Failure, UGKErr_FileIO,                         "Invalid number of fields (%s) at line %d in file %s",                         pszStr+7, iLine+1, m_pszFname);                FreeStrList(papszTok);                return -1;            }            // Alloc the array to keep track of indexed fields            m_panIndexNo = (int *)UGK_Calloc(numFields, sizeof(int));            iLine++;            poFieldDefn = NULL;            for(iField=0; iField<numFields; iField++, iLine++)            {                /*-----------------------------------------------------                 * For each field definition found in the .TAB:                 * Pass the info to the DAT file object.  It will validate                 * the info with what is found in the .DAT header, and will                 * also use this info later to interpret field values.                 *                 * We also create the UGKFieldDefn at the same time to                  * initialize the UGKFeatureDefn                 *----------------------------------------------------*/                FreeStrList(papszTok);                papszTok = TokenizeStringComplex(m_papszTABFile[iLine],                                                     " \t(),;",                                                    TRUE, FALSE);                numTok = CountOfList(papszTok);                nStatus = -1;                assert(m_poDefn);                if (numTok >= 3 && EQUAL(papszTok[1], "char"))                {                    /*-------------------------------------------------                     * CHAR type                     *------------------------------------------------*///$zgq                    nStatus = m_poDATFile->ValidateFieldInfoFromTAB(iField,                                                                papszTok[0],                                                               TABFChar,                                                            atoi(papszTok[2]),                                                               0);                    poFieldDefn = new UGKFieldDefn(papszTok[0], OFTString);                    poFieldDefn->SetWidth(atoi(papszTok[2]));                }                else if (numTok >= 2 && EQUAL(papszTok[1], "integer"))                {                    /*-------------------------------------------------                     * INTEGER type                     *------------------------------------------------*/                    nStatus = m_poDATFile->ValidateFieldInfoFromTAB(iField,                                                                papszTok[0],                                                               TABFInteger,                                                               0,                                                               0);                    poFieldDefn = new UGKFieldDefn(papszTok[0], OFTInteger);                }                else if (numTok >= 2 && EQUAL(papszTok[1], "smallint"))                {                    /*-------------------------------------------------                     * SMALLINT type                     *------------------------------------------------*/                    nStatus = m_poDATFile->ValidateFieldInfoFromTAB(iField,                                                                papszTok[0],                                                               TABFSmallInt,                                                               0,                                                               0);                    poFieldDefn = new UGKFieldDefn(papszTok[0], OFTInteger);                }                else if (numTok >= 4 && EQUAL(papszTok[1], "decimal"))                {                    /*-------------------------------------------------                     * DECIMAL type                     *------------------------------------------------*/                    nStatus = m_poDATFile->ValidateFieldInfoFromTAB(iField,                                                                papszTok[0],                                                               TABFDecimal,                                                           atoi(papszTok[2]),                                                           atoi(papszTok[3]));                    poFieldDefn = new UGKFieldDefn(papszTok[0], OFTReal);                    poFieldDefn->SetWidth(atoi(papszTok[2]));                    poFieldDefn->SetPrecision(atoi(papszTok[3]));                }                else if (numTok >= 2 && EQUAL(papszTok[1], "float"))                {                    /*-------------------------------------------------                     * FLOAT type                     *------------------------------------------------*/                    nStatus = m_poDATFile->ValidateFieldInfoFromTAB(iField,                                                                papszTok[0],                                                               TABFFloat,                                                               0, 0);                    poFieldDefn = new UGKFieldDefn(papszTok[0], OFTReal);                }                else if (numTok >= 2 && EQUAL(papszTok[1], "date"))                {                    /*-------------------------------------------------                     * DATE type (returned as a string: "DD/MM/YYYY")                     *------------------------------------------------*/                    nStatus = m_poDATFile->ValidateFieldInfoFromTAB(iField,                                                                papszTok[0],                                                               TABFDate,                                                               0,                                                               0);

⌨️ 快捷键说明

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