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

📄 avc_e00parse.c

📁 GIS系统支持库Geospatial Data Abstraction Library代码.GDAL is a translator library for raster geospatial dat
💻 C
📖 第 1 页 / 共 5 页
字号:
    {        return AVCFileUnknown;    }    /*-----------------------------------------------------------------     * Check if pszLine is a valid section header line.     *----------------------------------------------------------------*/    if (psInfo->eSuperSectionType == AVCFileUnknown)    {        /*-------------------------------------------------------------         * We're looking for a top-level section...         *------------------------------------------------------------*/        if (EQUALN(pszLine, "ARC  ", 5))            eNewType = AVCFileARC;        else if (EQUALN(pszLine, "PAL  ", 5))            eNewType = AVCFilePAL;        else if (EQUALN(pszLine, "CNT  ", 5))            eNewType = AVCFileCNT;        else if (EQUALN(pszLine, "LAB  ", 5))            eNewType = AVCFileLAB;        else if (EQUALN(pszLine, "TOL  ", 5))            eNewType = AVCFileTOL;        else if (EQUALN(pszLine, "PRJ  ", 5))            eNewType = AVCFilePRJ;        else if (EQUALN(pszLine, "TXT  ", 5))            eNewType = AVCFileTXT;        else        {            eNewType = AVCFileUnknown;            return AVCFileUnknown;        }        /*-------------------------------------------------------------         * OK, we have a valid new section header. Set the precision and          * get ready to read objects from it.         *------------------------------------------------------------*/        if (atoi(pszLine+4) == 2)            psInfo->nPrecision = AVC_SINGLE_PREC;        else if (atoi(pszLine+4) == 3)            psInfo->nPrecision = AVC_DOUBLE_PREC;        else        {            CPLError(CE_Failure, CPLE_AppDefined,                      "Parse Error: Invalid section header line (\"%s\")!",                      pszLine);            eNewType = AVCFileUnknown;            return AVCFileUnknown;        }    }    else    {        /*-------------------------------------------------------------         * We're looking for a section inside a super-section...         * in this case, the header line contains the subclass name,         * so any non-empty line is acceptable!         * Note: the precision is already set from the previous call to         *       AVCE00ParseSuperSectionHeader()         * Note2: Inside a double precision RPL supersection, the end of         *        each sub-section is marked by 2 lines, just like what         *        happens with double precision PALs... we have to make         *        sure we don't catch that second line as the beginning         *        of a new RPL sub-section.         *------------------------------------------------------------*/        if (strlen(pszLine) > 0 && !isspace(pszLine[0]) &&             !EQUALN(pszLine, "JABBERWOCKY", 11) &&            !EQUALN(pszLine, "EOI", 3) &&            ! ( psInfo->eSuperSectionType == AVCFileRPL &&                EQUALN(pszLine, " 0.00000", 6)  ) )        {            eNewType = psInfo->eSuperSectionType;        }        else        {            eNewType = AVCFileUnknown;            return AVCFileUnknown;        }    }    /*-----------------------------------------------------------------     * nCurObjectId is used to keep track of sequential ids that are      * not explicitly stored in E00.  e.g. polygon Id in a PAL section.     *----------------------------------------------------------------*/    psInfo->nCurObjectId = 0;    /*-----------------------------------------------------------------     * Allocate a temp. structure to use to store the objects we read     * (Using Calloc() will automatically initialize the struct contents     *  to NULL... this is very important for ARCs and PALs)     *----------------------------------------------------------------*/    _AVCE00ParseDestroyCurObject(psInfo);    if (eNewType == AVCFileARC)    {        psInfo->cur.psArc = (AVCArc*)CPLCalloc(1, sizeof(AVCArc));    }    else if (eNewType == AVCFilePAL ||             eNewType == AVCFileRPL )    {        psInfo->cur.psPal = (AVCPal*)CPLCalloc(1, sizeof(AVCPal));    }    else if (eNewType == AVCFileCNT)    {        psInfo->cur.psCnt = (AVCCnt*)CPLCalloc(1, sizeof(AVCCnt));    }    else if (eNewType == AVCFileLAB)    {        psInfo->cur.psLab = (AVCLab*)CPLCalloc(1, sizeof(AVCLab));    }    else if (eNewType == AVCFileTOL)    {        psInfo->cur.psTol = (AVCTol*)CPLCalloc(1, sizeof(AVCTol));    }    else if (eNewType == AVCFilePRJ)    {        psInfo->cur.psTol = (AVCTol*)CPLCalloc(1, sizeof(AVCTol));    }    else if (eNewType == AVCFilePRJ)    {        psInfo->cur.papszPrj = NULL;    }    else if (eNewType == AVCFileTXT ||             eNewType == AVCFileTX6)    {        psInfo->cur.psTxt = (AVCTxt*)CPLCalloc(1, sizeof(AVCTxt));    }    else if (eNewType == AVCFileRXP)    {        psInfo->cur.psRxp = (AVCRxp*)CPLCalloc(1, sizeof(AVCRxp));    }    else if (eNewType == AVCFileTABLE)    {        psInfo->cur.pasFields = NULL;        psInfo->hdr.psTableDef = NULL;        psInfo->bTableHdrComplete = FALSE;    }    else    {        CPLError(CE_Failure, CPLE_NotSupported,                 "AVCE00ParseSectionHeader(): Unsupported file type!");        eNewType = AVCFileUnknown;    }    /*-----------------------------------------------------------------     * Keep track of section header line... this is used for some file     * types, specially the ones enclosed inside supersections.     *----------------------------------------------------------------*/    CPLFree(psInfo->pszSectionHdrLine);    psInfo->pszSectionHdrLine = CPLStrdup(pszLine);    psInfo->eFileType = eNewType;    return psInfo->eFileType;}/********************************************************************** *                          AVCE00ParseSectionEnd() * * Check if pszLine marks the end of the current section.   *  * Passing bResetParseInfo=TRUE will reset the parser struct if an end of * section is found.  Passing FALSE simply tests for the end of section  * without affecting the parse info struct. * * Return TRUE if this is the end of the section (and reset the * ParseInfo structure) , or FALSE otherwise. **********************************************************************/GBool  AVCE00ParseSectionEnd(AVCE00ParseInfo  *psInfo, const char *pszLine,                             GBool bResetParseInfo){    if ( psInfo->bForceEndOfSection ||         ((psInfo->eFileType == AVCFileARC ||           psInfo->eFileType == AVCFilePAL ||           psInfo->eFileType == AVCFileLAB ||           psInfo->eFileType == AVCFileRPL ||           psInfo->eFileType == AVCFileCNT ||           psInfo->eFileType == AVCFileTOL ||           psInfo->eFileType == AVCFileTXT ||           psInfo->eFileType == AVCFileTX6 ||           psInfo->eFileType == AVCFileRXP )  &&           EQUALN(pszLine, "        -1         0", 20)  ) ||         ( psInfo->eFileType == AVCFilePRJ && EQUALN(pszLine, "EOP", 3) ) )    {        /* Reset ParseInfo only if explicitly requested.          */        if (bResetParseInfo)        {            _AVCE00ParseDestroyCurObject(psInfo);            AVCE00ParseReset(psInfo);            psInfo->eFileType = AVCFileUnknown;            CPLFree(psInfo->pszSectionHdrLine);            psInfo->pszSectionHdrLine = NULL;            psInfo->bForceEndOfSection = FALSE;        }        return TRUE;  /* YES, we reached the end */    }    return FALSE;  /* NO, it's not the end of section line */}/********************************************************************** *                          AVCE00ParseNextLine() * * Take the next line of E00 input and parse it. * * Returns NULL if the current object is not complete yet (expecting * more lines of input) or a reference to a complete object if it * is complete. * * The returned object is a reference to an internal data structure. * It should not be modified or freed by the caller. * * If the input is invalid or other problems happen, then a CPLError() * will be generated.  CPLGetLastErrorNo() should be called to check * that the line was parsed succesfully. * * Note for TABLES: * When parsing input from info tables, the first valid object that * will be returned will be the AVCTableDef, and then the data records * will follow.  When all the records have been read, then the * psInfo->bForceEndOfSection flag will be set to TRUE since there is * no explicit "end of table" line in E00. **********************************************************************/void   *AVCE00ParseNextLine(AVCE00ParseInfo  *psInfo, const char *pszLine){    void *psObj = NULL;    CPLAssert(psInfo);    switch(psInfo->eFileType)    {      case AVCFileARC:        psObj = (void*)AVCE00ParseNextArcLine(psInfo, pszLine);        break;      case AVCFilePAL:      case AVCFileRPL:        psObj = (void*)AVCE00ParseNextPalLine(psInfo, pszLine);        break;      case AVCFileCNT:        psObj = (void*)AVCE00ParseNextCntLine(psInfo, pszLine);        break;      case AVCFileLAB:        psObj = (void*)AVCE00ParseNextLabLine(psInfo, pszLine);        break;      case AVCFileTOL:        psObj = (void*)AVCE00ParseNextTolLine(psInfo, pszLine);        break;      case AVCFilePRJ:        psObj = (void*)AVCE00ParseNextPrjLine(psInfo, pszLine);        break;      case AVCFileTXT:        psObj = (void*)AVCE00ParseNextTxtLine(psInfo, pszLine);        break;      case AVCFileTX6:        psObj = (void*)AVCE00ParseNextTx6Line(psInfo, pszLine);        break;      case AVCFileRXP:        psObj = (void*)AVCE00ParseNextRxpLine(psInfo, pszLine);        break;      case AVCFileTABLE:        if ( ! psInfo->bTableHdrComplete )            psObj = (void*)AVCE00ParseNextTableDefLine(psInfo, pszLine);        else            psObj = (void*)AVCE00ParseNextTableRecLine(psInfo, pszLine);        break;      default:        CPLError(CE_Failure, CPLE_NotSupported,                 "AVCE00ParseNextLine(): Unsupported file type!");    }    return psObj;}/********************************************************************** *                          AVCE00ParseNextArcLine() * * Take the next line of E00 input for an ARC object and parse it. * * Returns NULL if the current object is not complete yet (expecting * more lines of input) or a reference to a complete object if it * is complete. * * The returned object is a reference to an internal data structure. * It should not be modified or freed by the caller. * * If the input is invalid or other problems happen, then a CPLError() * will be generated.  CPLGetLastErrorNo() should be called to check * that the line was parsed succesfully. **********************************************************************/AVCArc   *AVCE00ParseNextArcLine(AVCE00ParseInfo *psInfo, const char *pszLine){    AVCArc *psArc;    int     nLen;    CPLAssert(psInfo->eFileType == AVCFileARC);    psArc = psInfo->cur.psArc;    nLen = strlen(pszLine);    if (psInfo->numItems == 0)    {        /*-------------------------------------------------------------         * Begin processing a new object, read header line:         *    ArcId, UserId, FNode, TNode, LPoly, RPoly, numVertices         *------------------------------------------------------------*/        if (nLen < 70)        {            CPLError(CE_Failure, CPLE_AppDefined,                      "Error parsing E00 ARC line: \"%s\"", pszLine);            return NULL;        }        else        {            psArc->nArcId = AVCE00Str2Int(pszLine, 10);            psArc->nUserId = AVCE00Str2Int(pszLine+10, 10);            psArc->nFNode = AVCE00Str2Int(pszLine+20, 10);            psArc->nTNode = AVCE00Str2Int(pszLine+30, 10);            psArc->nLPoly = AVCE00Str2Int(pszLine+40, 10);            psArc->nRPoly = AVCE00Str2Int(pszLine+50, 10);            psArc->numVertices = AVCE00Str2Int(pszLine+60, 10);                        /* Realloc the array of vertices              */            psArc->pasVertices = (AVCVertex*)CPLRealloc(psArc->pasVertices,                                                        psArc->numVertices*                                                        sizeof(AVCVertex));            /* psInfo->iCurItem is the last vertex that was read.             * psInfo->numItems is the number of vertices to read.             */            psInfo->iCurItem = 0;            psInfo->numItems = psArc->numVertices;        }    }    else if (psInfo->iCurItem < psInfo->numItems &&              psInfo->nPrecision == AVC_SINGLE_PREC &&             ( (psInfo->iCurItem==psInfo->numItems-1 && nLen >= 28) ||               nLen >= 56 )  )    {        /*-------------------------------------------------------------         * Single precision ARCs: 2 pairs of X,Y values per line         * Except on the last line with an odd number of vertices)         *------------------------------------------------------------*/        psArc->pasVertices[psInfo->iCurItem].x = atof(pszLine);

⌨️ 快捷键说明

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