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

📄 avc_e00parse.c

📁 用于读取TAB、MIF、SHP文件的类
💻 C
📖 第 1 页 / 共 5 页
字号:
 *                          AVCE00ParseNextLabLine() * * Take the next line of E00 input for an LAB 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. **********************************************************************/AVCLab   *AVCE00ParseNextLabLine(AVCE00ParseInfo *psInfo, const char *pszLine){    AVCLab *psLab;    int     nLen;    CPLAssert(psInfo->eFileType == AVCFileLAB);    psLab = psInfo->cur.psLab;    nLen = strlen(pszLine);    if (psInfo->numItems == 0)    {        /*-------------------------------------------------------------         * Begin processing a new object, read header line:         *    LabelValue, PolyId, X1, Y1         *------------------------------------------------------------*/        if (nLen < 48)        {            CPLError(CE_Failure, CPLE_AppDefined,                     "Error parsing E00 LAB line: \"%s\"", pszLine);            return NULL;        }        else        {            psLab->nValue = AVCE00Str2Int(pszLine, 10);            psLab->nPolyId = AVCE00Str2Int(pszLine+10, 10);            if (psInfo->nPrecision == AVC_SINGLE_PREC)            {                psLab->sCoord1.x = atof(pszLine + 20);                psLab->sCoord1.y = atof(pszLine + 34);            }            else            {                psLab->sCoord1.x = atof(pszLine + 20);                psLab->sCoord1.y = atof(pszLine + 41);            }            /* psInfo->iCurItem is the index of the last X,Y pair we read.             * psInfo->numItems is the number of X,Y pairs to read.             */            psInfo->iCurItem = 1;            psInfo->numItems = 3;        }    }    else if (psInfo->iCurItem == 1 && psInfo->nPrecision == AVC_SINGLE_PREC &&             nLen >= 56 )    {        psLab->sCoord2.x = atof(pszLine);        psLab->sCoord2.y = atof(pszLine + 14);        psLab->sCoord3.x = atof(pszLine + 28);        psLab->sCoord3.y = atof(pszLine + 42);        psInfo->iCurItem += 2;    }    else if (psInfo->iCurItem == 1 && psInfo->nPrecision == AVC_DOUBLE_PREC &&             nLen >= 42 )    {        psLab->sCoord2.x = atof(pszLine);        psLab->sCoord2.y = atof(pszLine + 21);        psInfo->iCurItem++;    }    else if (psInfo->iCurItem == 2 && psInfo->nPrecision == AVC_DOUBLE_PREC &&             nLen >= 42 )    {        psLab->sCoord3.x = atof(pszLine);        psLab->sCoord3.y = atof(pszLine + 21);        psInfo->iCurItem++;    }    else    {        CPLError(CE_Failure, CPLE_AppDefined,                  "Error parsing E00 LAB line: \"%s\"", pszLine);        psInfo->numItems = psInfo->iCurItem = 0;        return NULL;    }    /*-----------------------------------------------------------------     * If we're done parsing this LAB, then reset the ParseInfo,     * and return a reference to the LAB structure     * Otherwise return NULL, which means that we are expecting more     * more lines of input.     *----------------------------------------------------------------*/    if (psInfo->iCurItem >= psInfo->numItems)    {        psInfo->numItems = psInfo->iCurItem = 0;        return psLab;    }    return NULL;}/********************************************************************** *                          AVCE00ParseNextTolLine() * * Take the next line of E00 input for an TOL 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. **********************************************************************/AVCTol   *AVCE00ParseNextTolLine(AVCE00ParseInfo *psInfo, const char *pszLine){    AVCTol *psTol;    int     nLen;    CPLAssert(psInfo->eFileType == AVCFileTOL);    psTol = psInfo->cur.psTol;    nLen = strlen(pszLine);    if (nLen >= 34)    {        /*-------------------------------------------------------------         * TOL Entries are only one line each:         *   TolIndex, TolFlag, TolValue         *------------------------------------------------------------*/        psTol->nIndex = AVCE00Str2Int(pszLine, 10);        psTol->nFlag  = AVCE00Str2Int(pszLine + 10, 10);        psTol->dValue = atof(pszLine + 20);    }    else    {        CPLError(CE_Failure, CPLE_AppDefined,                  "Error parsing E00 TOL line: \"%s\"", pszLine);        psInfo->numItems = psInfo->iCurItem = 0;        return NULL;    }    /*-----------------------------------------------------------------     * If we're done parsing this TOL, then reset the ParseInfo,     * and return a reference to the TOL structure     * Otherwise return NULL, which means that we are expecting more     * more lines of input.     *----------------------------------------------------------------*/    if (psInfo->iCurItem >= psInfo->numItems)    {        psInfo->numItems = psInfo->iCurItem = 0;        return psTol;    }    return NULL;}/********************************************************************** *                          AVCE00ParseNextPrjLine() * * Take the next line of E00 input for a PRJ 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. * * Since a PRJ section contains only ONE projection, the function will * always return NULL, until it reaches the end-of-section (EOP) line. * This is behavior is a bit different from the other section types that * will usually return a valid object immediately before the last line * of the section (the end-of-section line). * * 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. **********************************************************************/char  **AVCE00ParseNextPrjLine(AVCE00ParseInfo *psInfo, const char *pszLine){    CPLAssert(psInfo->eFileType == AVCFilePRJ);    /*-------------------------------------------------------------     * Since a PRJ section contains only ONE projection, this function will     * always return NULL until it reaches the end-of-section (EOP) line.     * This is behavior is a bit different from the other section types that     * will usually return a valid object immediately before the last line     * of the section (the end-of-section line).     *------------------------------------------------------------*/    if (EQUALN(pszLine, "EOP", 3))    {        /*-------------------------------------------------------------         * We reached end of section... return the PRJ.         *------------------------------------------------------------*/        psInfo->bForceEndOfSection = TRUE;        return psInfo->cur.papszPrj;    }    if ( pszLine[0] != '~' )    {        /*-------------------------------------------------------------         * This is a new line... add it to the papszPrj stringlist.         *------------------------------------------------------------*/        psInfo->cur.papszPrj = CSLAddString(psInfo->cur.papszPrj, pszLine);    }    else if ( strlen(pszLine) > 1 )    {        /*-------------------------------------------------------------         * '~' is a line continuation char.  Append what follows the '~'         * to the end of the previous line.         *------------------------------------------------------------*/        int  iLastLine, nNewLen;        iLastLine = CSLCount(psInfo->cur.papszPrj) - 1;        nNewLen = strlen(psInfo->cur.papszPrj[iLastLine])+strlen(pszLine)-1+1;        if (iLastLine >= 0)        {            psInfo->cur.papszPrj[iLastLine] =                   (char*)CPLRealloc(psInfo->cur.papszPrj[iLastLine],                                    nNewLen * sizeof(char));            strcat(psInfo->cur.papszPrj[iLastLine], pszLine+1);        }    }        return NULL;}/********************************************************************** *                          AVCE00ParseNextTxtLine() * * Take the next line of E00 input for an TXT 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. **********************************************************************/AVCTxt   *AVCE00ParseNextTxtLine(AVCE00ParseInfo *psInfo, const char *pszLine){    AVCTxt *psTxt;    int     i, nLen, numFixedLines;    CPLAssert(psInfo->eFileType == AVCFileTXT);    psTxt = psInfo->cur.psTxt;    nLen = strlen(pszLine);    /* numFixedLines is the number of lines to expect before the line(s)     * with the text string      */    if (psInfo->nPrecision == AVC_SINGLE_PREC)        numFixedLines = 4;    else        numFixedLines = 6;    if (psInfo->numItems == 0)    {        /*-------------------------------------------------------------         * Begin processing a new object, read header line:         *------------------------------------------------------------*/        if (nLen < 50)        {            CPLError(CE_Failure, CPLE_AppDefined,                      "Error parsing E00 TXT line: \"%s\"", pszLine);            return NULL;        }        else        {            int numVertices;            /*---------------------------------------------------------             * With TXT, there are several unused fields that have to be             * set to default values... usually 0.             *--------------------------------------------------------*/            psTxt->nUserId = 0;            psTxt->n28 = 0;            for(i=0; i<20; i++)                psTxt->anJust1[i] = psTxt->anJust2[i] = 0;            psTxt->dV2 = psTxt->dV3 = 0.0;            /*---------------------------------------------------------             * System Id is not stored in the E00 file.  Annotations are             * stored in increasing order of System Id, starting at 1...             * so we just increment the previous value.             *--------------------------------------------------------*/            psTxt->nTxtId = ++psInfo->nCurObjectId;            psTxt->nLevel          = AVCE00Str2Int(pszLine, 10);            /* Add 1 to numVerticesLine because the first vertex is              * always duplicated in the TXT binary structure...             */            psTxt->numVerticesLine = AVCE00Str2Int(pszLine+10, 10) + 1;            psTxt->numVerticesArrow= AVCE00Str2Int(pszLine+20, 10);            psTxt->nSymbol         = AVCE00Str2Int(pszLine+30, 10);            psTxt->numChars        = AVCE00Str2Int(pszLine+40, 10);            /*---------------------------------------------------------             * Realloc the string buffer and array of vertices             *--------------------------------------------------------*/            psTxt->pszText = (char *)CPLRealloc(psTxt->pszText,                                                (psTxt->numChars+1)*                                                    sizeof(char));            numVertices = ABS(psTxt->numVerticesLine) +                                  ABS(psTxt->numVerticesArrow);            if (numVertices > 0)                psTxt->pasVertices = (AVCVertex*)CPLRealloc(psTxt->pasVertices,                                              numVertices*sizeof(AVCVertex));            /*---------------------------------------------------------             * Fill the whole string buffer with spaces we'll just             * paste lines in it using strncpy()             *--------------------------------------------------------*/            memset(psTxt->pszText, ' ', psTxt->numChars);            psTxt->pszText[psTxt->numChars] = '\0';            /*---------------------------------------------------------             * psInfo->iCurItem is the index of the last line that was read.             * psInfo->numItems is the number of lines to read.

⌨️ 快捷键说明

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