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

📄 avc_e00read.c

📁 用于读取TAB、MIF、SHP文件的类
💻 C
📖 第 1 页 / 共 5 页
字号:
                pszName = "ARC";                break;            case AVCFilePAL:                pszName = "PAL";                break;            case AVCFileCNT:                pszName = "CNT";                break;            case AVCFileLAB:                pszName = "LAB";                break;            case AVCFileRPL:                pszName = "RPL";                break;            case AVCFileTXT:                pszName = "TXT";                break;            case AVCFileTX6:                pszName = "TX6";                break;            case AVCFilePRJ:                pszName = "PRJ";                break;            case AVCFileTABLE:                pszName = psInfo->hdr.psTableDef->szTableName;                break;            default:                break;            }            if (pszName && (psRead->numSections == 0 ||                    psRead->pasSections[iSect].eType != psInfo->eFileType ||                    !EQUAL(pszName, psRead->pasSections[iSect].pszName)))            {                iSect = _AVCIncreaseSectionsArray(&(psRead->pasSections),                                       &(psRead->numSections), 1);                psRead->pasSections[iSect].eType = psInfo->eFileType;                /* psRead->pasSections[iSect].pszName = CPLStrdup(psRead->pszCoverName); */                psRead->pasSections[iSect].pszName = CPLStrdup(pszName);                psRead->pasSections[iSect].pszFilename = CPLStrdup(psRead->pszCoverPath);                psRead->pasSections[iSect].nLineNum = psInfo->nStartLineNum;                psRead->pasSections[iSect].nFeatureCount = 0;            }            if (pszName && psRead->numSections)            {                /* increase feature count for current layer */                ++psRead->pasSections[iSect].nFeatureCount;            }        }    }}/********************************************************************** *                         _AVCE00ReadNextTableLine() * * Return the next line of the E00 representation of a info table. * * This function is used by AVCE00ReadNextLine() to generate table * output... it should never be called directly. **********************************************************************/static const char *_AVCE00ReadNextTableLine(AVCE00ReadPtr psInfo){    const char *pszLine = NULL;    AVCE00Section *psSect;    psSect = &(psInfo->pasSections[psInfo->iCurSection]);    CPLAssert(psSect->eType == AVCFileTABLE);    if (psInfo->iCurStep == AVC_GEN_NOTSTARTED)    {        /*---------------------------------------------------------         * Open table and start returning header         *--------------------------------------------------------*/        if (psInfo->eCoverType == AVCCoverPC ||            psInfo->eCoverType == AVCCoverPC2)        {            /*---------------------------------------------------------             * PC Arc/Info: We pass the DBF table's full filename + the             * Arc/Info table name (for E00 header)             *--------------------------------------------------------*/            char *pszFname;            pszFname = CPLStrdup(CPLSPrintf("%s%s", psInfo->pszInfoPath,                                                    psSect->pszFilename ));            psInfo->hFile = AVCBinReadOpen(pszFname, psSect->pszName,                                            psInfo->eCoverType, psSect->eType,                                           psInfo->psDBCSInfo);            CPLFree(pszFname);        }        else        {            /*---------------------------------------------------------             * AVCCoverV7 and AVCCoverWeird:              * We pass the INFO dir's path, and the Arc/Info table name             * will be searched in the arc.dir             *--------------------------------------------------------*/            psInfo->hFile = AVCBinReadOpen(psInfo->pszInfoPath,                                            psSect->pszName,                                            psInfo->eCoverType, psSect->eType,                                           psInfo->psDBCSInfo);        }        /* For some reason the file could not be opened... abort now.         * An error message should have already been produced by          * AVCBinReadOpen()         */        if (psInfo->hFile == NULL)            return NULL;        psInfo->iCurStep = AVC_GEN_TABLEHEADER;        pszLine = AVCE00GenTableHdr(psInfo->hGenInfo,                                    psInfo->hFile->hdr.psTableDef,                                    FALSE);    }            if (pszLine == NULL &&        psInfo->iCurStep == AVC_GEN_TABLEHEADER)    {        /*---------------------------------------------------------         * Continue table header         *--------------------------------------------------------*/        pszLine = AVCE00GenTableHdr(psInfo->hGenInfo,                                    psInfo->hFile->hdr.psTableDef,                                    TRUE);        if (pszLine == NULL)        {            /* Finished with table header... time to proceed with the             * table data.             * Reset the AVCE00GenInfo struct. so that it returns NULL,             * which will force reading of the first record from the              * file on the next call to AVCE00ReadNextLine()             */            AVCE00GenReset(psInfo->hGenInfo);            psInfo->iCurStep = AVC_GEN_TABLEDATA;        }    }    if (pszLine == NULL &&        psInfo->iCurStep == AVC_GEN_TABLEDATA)    {        /*---------------------------------------------------------         * Continue with records of data         *--------------------------------------------------------*/        pszLine = AVCE00GenTableRec(psInfo->hGenInfo,                                     psInfo->hFile->hdr.psTableDef->numFields,                                    psInfo->hFile->hdr.psTableDef->pasFieldDef,                                    psInfo->hFile->cur.pasFields,                                    TRUE);        if (pszLine == NULL)        {            /* Current record is finished generating... we need to read              * a new one from the file.             */            if (AVCBinReadNextObject(psInfo->hFile) != NULL)            {                pszLine = AVCE00GenTableRec(psInfo->hGenInfo,                                     psInfo->hFile->hdr.psTableDef->numFields,                                    psInfo->hFile->hdr.psTableDef->pasFieldDef,                                    psInfo->hFile->cur.pasFields,                                    FALSE);            }                    }    }    if (pszLine == NULL)    {        /*---------------------------------------------------------         * No more lines to output for this table ... Close it.         *--------------------------------------------------------*/        AVCBinReadClose(psInfo->hFile);        psInfo->hFile = NULL;        /*---------------------------------------------------------         * And now proceed to the next section...         * OK, I don't really like recursivity either... but it was         * the simplest way to do this, and anyways we should never         * have more than one level of recursivity.         *--------------------------------------------------------*/        if (psInfo->bReadAllSections)            psInfo->iCurSection++;        else            psInfo->iCurSection = psInfo->numSections;        psInfo->iCurStep = AVC_GEN_NOTSTARTED;        pszLine = AVCE00ReadNextLine(psInfo);    }    /*-----------------------------------------------------------------     * Check for errors... if any error happened, tehn return NULL     *----------------------------------------------------------------*/    if (CPLGetLastErrorNo() != 0)    {        pszLine = NULL;    }    return pszLine;}/********************************************************************** *                          AVCE00ReadNextLine() * * Returns the next line of the E00 representation of the coverage * or NULL when there are no more lines to generate, or if an error happened. * The returned line is a null-terminated string, and it does not * include a newline character. * * Call CPLGetLastErrorNo() after calling AVCE00ReadNextLine() to  * make sure that the line was generated succesfully. * * Note that AVCE00ReadNextLine() returns a reference to an * internal buffer whose contents will * be valid only until the next call to this function.  The caller should * not attempt to free() the returned pointer. **********************************************************************/const char *AVCE00ReadNextLine(AVCE00ReadPtr psInfo){    const char *pszLine = NULL;    AVCE00Section *psSect;    CPLErrorReset();    /*-----------------------------------------------------------------     * Check if we have finished generating E00 output     *----------------------------------------------------------------*/    if (psInfo->iCurSection >= psInfo->numSections)        return NULL;    psSect = &(psInfo->pasSections[psInfo->iCurSection]);    /*-----------------------------------------------------------------     * For simplicity, the generation of table output is in a separate     * function.     *----------------------------------------------------------------*/    if (psSect->eType == AVCFileTABLE)    {        return _AVCE00ReadNextTableLine(psInfo);    }    if (psSect->eType == AVCFileUnknown)    {    /*-----------------------------------------------------------------     * Section not attached to any file, used to hold header lines     * or section separators, etc... just return the line directly and     * move pointer to the next section.     *----------------------------------------------------------------*/        pszLine = psSect->pszName;        if (psInfo->bReadAllSections)            psInfo->iCurSection++;        else            psInfo->iCurSection = psInfo->numSections;        psInfo->iCurStep = AVC_GEN_NOTSTARTED;    }    /*=================================================================     *              ARC, PAL, CNT, LAB, TOL and TXT     *================================================================*/    else if (psInfo->iCurStep == AVC_GEN_NOTSTARTED &&             (psSect->eType == AVCFileARC ||              psSect->eType == AVCFilePAL ||              psSect->eType == AVCFileRPL ||              psSect->eType == AVCFileCNT ||              psSect->eType == AVCFileLAB ||              psSect->eType == AVCFileTOL ||              psSect->eType == AVCFileTXT ||              psSect->eType == AVCFileTX6 ||              psSect->eType == AVCFileRXP   ) )    {    /*-----------------------------------------------------------------     * Start processing of an ARC, PAL, CNT, LAB or TOL section:     *   Open the file, get ready to read the first object from the      *   file, and return the header line.     *  If the file fails to open then we will return NULL.     *----------------------------------------------------------------*/        psInfo->hFile = AVCBinReadOpen(psInfo->pszCoverPath,                                        psSect->pszFilename,                                        psInfo->eCoverType, psSect->eType,                                       psInfo->psDBCSInfo);        /*-------------------------------------------------------------         * For some reason the file could not be opened... abort now.         * An error message should have already been produced by          * AVCBinReadOpen()         *------------------------------------------------------------*/        if (psInfo->hFile == NULL)            return NULL;        pszLine = AVCE00GenStartSection(psInfo->hGenInfo,                                         psSect->eType, psSect->pszName);        /*-------------------------------------------------------------         * Reset the AVCE00GenInfo struct. so that it returns NULL,         * which will force reading of the first object from the          * file on the next call to AVCE00ReadNextLine()         *------------------------------------------------------------*/        AVCE00GenReset(psInfo->hGenInfo);        psInfo->iCurStep = AVC_GEN_DATA;    }    else if (psInfo->iCurStep == AVC_GEN_DATA &&             (psSect->eType == AVCFileARC ||              psSect->eType == AVCFilePAL ||              psSect->eType == AVCFileRPL ||              psSect->eType == AVCFileCNT ||              psSect->eType == AVCFileLAB ||              psSect->eType == AVCFileTOL ||              psSect->eType == AVCFileTXT ||              psSect->eType == AVCFileTX6 ||              psSect->eType == AVCFileRXP    ) )    {    /*---------------

⌨️ 快捷键说明

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