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

📄 avc_e00write.c

📁 用于读取TAB、MIF、SHP文件的类
💻 C
📖 第 1 页 / 共 3 页
字号:
}/********************************************************************** *                          _AVCE00WriteCloseCoverFile() * * Close current coverage file and reset the contents of psInfo. * * File should have been previously opened by _AVCE00WriteCreateCoverFile(). * **********************************************************************/void  _AVCE00WriteCloseCoverFile(AVCE00WritePtr psInfo){    /*-----------------------------------------------------------------     * PRJ sections behave differently... since there is only one "object"     * per section, they accumulate lines while we read them, and we      * write everything at once when we reach the end-of-section (EOP) line.     *----------------------------------------------------------------*/    if (psInfo->eCurFileType == AVCFilePRJ)    {        AVCBinWriteObject(psInfo->hFile, psInfo->hParseInfo->cur.papszPrj);    }    AVCBinWriteClose(psInfo->hFile);    psInfo->hFile = NULL;    psInfo->eCurFileType = AVCFileUnknown;}/********************************************************************** *                          AVCE00WriteNextLine() * * Take the next line of E00 input for this coverage, parse it and  * write the result to the coverage. * * Important Note: The E00 source lines are assumed to be valid... the * library performs no validation on the consistency of what it is  * given as input (i.e. topology, polygons consistency, etc.). * So the coverage that will be created will be only as good as the  * E00 input that is used to generate it. * * Returns 0 on success or -1 on error. **********************************************************************/int     AVCE00WriteNextLine(AVCE00WritePtr psInfo, const char *pszLine){    /*-----------------------------------------------------------------     * TODO: Update this call to use _AVCE00ReadNextLineE00(), if     * possible.     *----------------------------------------------------------------*/    int nStatus = 0;    CPLErrorReset();    /*-----------------------------------------------------------------     * If we're at the top level inside a supersection... check if this     * supersection ends here.     *----------------------------------------------------------------*/    if (AVCE00ParseSuperSectionEnd(psInfo->hParseInfo, pszLine) == TRUE)    {        /* Nothing to do... it's all been done by the call to          * AVCE00ParseSuperSectionEnd()         */    }    else if (psInfo->eCurFileType == AVCFileUnknown)    {        /*-------------------------------------------------------------         * We're at the top level or inside a supersection... waiting          * to encounter a valid section or supersection header          * (i.e. "ARC  2", etc...)         *------------------------------------------------------------*/        /*-------------------------------------------------------------         * First check for a supersection header (TX6, RXP, IFO, ...)         *------------------------------------------------------------*/        if ( AVCE00ParseSuperSectionHeader(psInfo->hParseInfo,                                           pszLine) == AVCFileUnknown )        {            /*---------------------------------------------------------             * This was not a supersection header... check if it's a simple             * section header             *--------------------------------------------------------*/            psInfo->eCurFileType=AVCE00ParseSectionHeader(psInfo->hParseInfo,                                                          pszLine);        }        /*-------------------------------------------------------------         * If the coverage was created using AVC_DEFAULT_PREC and we are         * processing the first section header, then use this section's         * precision for the new coverage.         * (Note: this code segment will be executed only once per          *        coverage and only if AVC_DEFAULT_PREC was selected)         *------------------------------------------------------------*/        if (psInfo->nPrecision == AVC_DEFAULT_PREC &&            psInfo->eCurFileType != AVCFileUnknown)        {            psInfo->nPrecision = psInfo->hParseInfo->nPrecision;        }        if (psInfo->eCurFileType == AVCFileTABLE)        {            /*---------------------------------------------------------             * We can't create the file for a TABLE until the             * whole header has been read... send the first header             * line to the parser and wait until the whole header has              * been read.             *--------------------------------------------------------*/            AVCE00ParseNextLine(psInfo->hParseInfo, pszLine);         }        else if (psInfo->eCurFileType != AVCFileUnknown)        {            /*---------------------------------------------------------             * OK, we've found a valid section header... create the              * corresponding file in the coverage.             * Note: supersection headers don't trigger the creation             *       of any output file... they just alter the psInfo state.             *--------------------------------------------------------*/            nStatus = _AVCE00WriteCreateCoverFile(psInfo,                                                   psInfo->eCurFileType,                                       psInfo->hParseInfo->pszSectionHdrLine,                                                  NULL);        }    }    else if (psInfo->eCurFileType == AVCFileTABLE &&             ! psInfo->hParseInfo->bTableHdrComplete )    {        /*-------------------------------------------------------------         * We're reading a TABLE header... continue reading lines         * from the header, and create the output file only once         * the header will have been completely read.         *         * Note: When parsing a TABLE, the first object returned will          * be the AVCTableDef, then data records will follow.         *------------------------------------------------------------*/        AVCTableDef *psTableDef;        psTableDef = (AVCTableDef*)AVCE00ParseNextLine(psInfo->hParseInfo,                                                        pszLine);         if (psTableDef)        {            nStatus = _AVCE00WriteCreateCoverFile(psInfo,                                                   psInfo->eCurFileType,                                       psInfo->hParseInfo->pszSectionHdrLine,                                                  psTableDef);        }    }    else    {        /*-------------------------------------------------------------         * We're are in the middle of a section... first check if we         * have reached the end.         *         * note: The first call to AVCE00ParseSectionEnd() with FALSE will          *       not reset the parser until we close the file... and then         *       we call the function again to reset the parser.         *------------------------------------------------------------*/        if (AVCE00ParseSectionEnd(psInfo->hParseInfo, pszLine, FALSE))        {            _AVCE00WriteCloseCoverFile(psInfo);            AVCE00ParseSectionEnd(psInfo->hParseInfo, pszLine, TRUE);        }        else        /*-------------------------------------------------------------         * ... not at the end yet, so continue reading objects.         *------------------------------------------------------------*/        {            void *psObj;            psObj = AVCE00ParseNextLine(psInfo->hParseInfo, pszLine);            if (psObj)                AVCBinWriteObject(psInfo->hFile, psObj);        }    }    if (psInfo->hParseInfo->bForceEndOfSection)    {        /*-------------------------------------------------------------         * The last call encountered an implicit end of section, so         * we close the section now without waiting for an end-of-section         * line (there won't be any!)... and get ready to proceed with         * the next section.         * This is used for TABLEs.         *------------------------------------------------------------*/        _AVCE00WriteCloseCoverFile(psInfo);        AVCE00ParseSectionEnd(psInfo->hParseInfo, pszLine, TRUE);        /* psInfo->hParseInfo->bForceEndOfSection = FALSE; */    }    if (CPLGetLastErrorNo() != 0)        nStatus = -1;    return nStatus;}/********************************************************************** *                          AVCE00DeleteCoverage() * * Delete a coverage directory, its contents, and the associated info * tables. * * Note: * When deleting tables, only the ../info/arc????.nit and arc????.dat * need to be deleted; the arc.dir does not need to be updated.  This * is exactly what Arc/Info's KILL command does. * * Returns 0 on success or -1 on error. **********************************************************************/int     AVCE00DeleteCoverage(const char *pszCoverToDelete){    int i, j, nStatus = 0;    char *pszInfoPath, *pszCoverPath, *pszCoverName;    const char *pszFname;    char **papszTables=NULL, **papszFiles=NULL;    AVCE00ReadPtr   psInfo;    VSIStatBuf      sStatBuf;    AVCCoverType    eCoverType;    CPLErrorReset();    /*-----------------------------------------------------------------     * Since we don't want to duplicate all the logic to figure coverage     * and info dir name, etc... we'll simply open the coverage and     * grab the info we need from the coverage handle.     * By the same way, this will verify that the coverage exists and is     * valid.     *----------------------------------------------------------------*/    psInfo = AVCE00ReadOpen(pszCoverToDelete);    if (psInfo == NULL)    {        CPLError(CE_Failure, CPLE_FileIO,                 "Cannot delete coverage %s: it does not appear to be valid\n",                 pszCoverToDelete);        return -1;    }    pszCoverPath = CPLStrdup(psInfo->pszCoverPath);    pszInfoPath = CPLStrdup(psInfo->pszInfoPath);    pszCoverName = CPLStrdup(psInfo->pszCoverName);    eCoverType = psInfo->eCoverType;    AVCE00ReadClose(psInfo);    /*-----------------------------------------------------------------     * Delete files in cover directory.     *----------------------------------------------------------------*/    papszFiles = CPLReadDir(pszCoverPath);    for(i=0; nStatus==0 && papszFiles && papszFiles[i]; i++)    {        if (!EQUAL(".", papszFiles[i]) &&            !EQUAL("..", papszFiles[i]))        {            pszFname = CPLSPrintf("%s%s", pszCoverPath, papszFiles[i]);            if (unlink(pszFname) != 0)            {                CPLError(CE_Failure, CPLE_FileIO,                          "Failed deleting %s%s: %s",                          pszCoverPath, papszFiles[i], strerror);                nStatus = -1;                break;            }        }    }    CSLDestroy(papszFiles);    papszFiles = NULL;    /*-----------------------------------------------------------------     * Get the list of info files (ARC????) to delete and delete them     * (No 'info' directory for PC coverages)     *----------------------------------------------------------------*/    if (nStatus == 0 && eCoverType != AVCCoverPC && eCoverType != AVCCoverPC2)    {        papszTables = AVCBinReadListTables(pszInfoPath, pszCoverName,                                            &papszFiles, eCoverType,                                           NULL /*DBCSInfo*/);        for(i=0; nStatus==0 && papszFiles && papszFiles[i]; i++)        {            /* Convert table filename to lowercases */            for(j=0; papszFiles[i] && papszFiles[i][j]!='\0'; j++)                papszFiles[i][j] = tolower(papszFiles[i][j]);            /* Delete the .DAT file */            pszFname = CPLSPrintf("%s%s.dat", pszInfoPath, papszFiles[i]);            if ( VSIStat(pszFname, &sStatBuf) != -1 &&                 unlink(pszFname) != 0)            {                CPLError(CE_Failure, CPLE_FileIO,                          "Failed deleting %s%s: %s",                          pszInfoPath, papszFiles[i], strerror);                nStatus = -1;                break;            }            /* Delete the .DAT file */            pszFname = CPLSPrintf("%s%s.nit", pszInfoPath, papszFiles[i]);            if ( VSIStat(pszFname, &sStatBuf) != -1 &&                 unlink(pszFname) != 0)            {                CPLError(CE_Failure, CPLE_FileIO,                          "Failed deleting %s%s: %s",                          pszInfoPath, papszFiles[i], strerror);                nStatus = -1;                break;            }        }        CSLDestroy(papszTables);        CSLDestroy(papszFiles);    }    /*-----------------------------------------------------------------     * Delete the coverage directory itself     * In some cases, the directory could be locked by another application      * on the same system or somewhere on the network.       * Define AVC_IGNORE_RMDIR_ERROR at compile time if you want this      * error to be ignored.     *----------------------------------------------------------------*/    if (VSIRmdir(pszCoverPath) != 0)    {#ifndef AVC_IGNORE_RMDIR_ERROR        CPLError(CE_Failure, CPLE_FileIO,                  "Failed deleting directory %s: %s", pszCoverPath, strerror);        nStatus = -1;#endif    }    CPLFree(pszCoverPath);    CPLFree(pszInfoPath);    CPLFree(pszCoverName);    return nStatus;}

⌨️ 快捷键说明

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