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

📄 avc_e00parse.c

📁 用于读取TAB、MIF、SHP文件的类
💻 C
📖 第 1 页 / 共 5 页
字号:
    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);        psArc->pasVertices[psInfo->iCurItem++].y = atof(pszLine+14);        if (psInfo->iCurItem < psInfo->numItems && nLen >= 56)        {            psArc->pasVertices[psInfo->iCurItem].x = atof(pszLine+28);            psArc->pasVertices[psInfo->iCurItem++].y = atof(pszLine+42);        }    }    else if (psInfo->iCurItem < psInfo->numItems &&              psInfo->nPrecision == AVC_DOUBLE_PREC &&             nLen >= 42)    {        /*-------------------------------------------------------------         * Double precision ARCs: 1 pair of X,Y values per line         *------------------------------------------------------------*/        psArc->pasVertices[psInfo->iCurItem].x = atof(pszLine);        psArc->pasVertices[psInfo->iCurItem++].y = atof(pszLine+21);    }    else    {        CPLError(CE_Failure, CPLE_AppDefined,                  "Error parsing E00 ARC line: \"%s\"", pszLine);        psInfo->numItems = psInfo->iCurItem = 0;        return NULL;    }    /*-----------------------------------------------------------------     * If we're done parsing this ARC, then reset the ParseInfo,     * and return a reference to the ARC 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 psArc;    }    return NULL;}/********************************************************************** *                          AVCE00ParseNextPalLine() * * Take the next line of E00 input for an PAL 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. **********************************************************************/AVCPal   *AVCE00ParseNextPalLine(AVCE00ParseInfo *psInfo, const char *pszLine){    AVCPal *psPal;    int     nLen;    CPLAssert(psInfo->eFileType == AVCFilePAL ||              psInfo->eFileType == AVCFileRPL );    psPal = psInfo->cur.psPal;    nLen = strlen(pszLine);    if (psInfo->numItems == 0)    {        /*-------------------------------------------------------------         * Begin processing a new object, read header line:         *    numArcs, MinX, MinY, MaxX, MaxY         * For Double precision, MaxX, MaxY are on a separate line.         *------------------------------------------------------------*/        if (nLen < 52)        {            CPLError(CE_Failure, CPLE_AppDefined,                      "Error parsing E00 PAL line: \"%s\"", pszLine);            return NULL;        }        else        {            /* Polygon Id is not stored in the E00 file.  Polygons are             * stored in increasing order, starting at 1... so we just              * increment the previous value.             */            psPal->nPolyId = ++psInfo->nCurObjectId;            psPal->numArcs = AVCE00Str2Int(pszLine, 10);            /* If a PAL record has 0 arcs, it really has a single "0 0 0"             * triplet as its data.             */            if ( psPal->numArcs == 0 )            {               psPal->numArcs = 1;            }            /* Realloc the array of Arcs             */            psPal->pasArcs = (AVCPalArc*)CPLRealloc(psPal->pasArcs,                                                    psPal->numArcs*                                                    sizeof(AVCPalArc));            /* psInfo->iCurItem is the index of the last arc that was read.             * psInfo->numItems is the number of arcs to read.             */            psInfo->iCurItem = 0;            psInfo->numItems = psPal->numArcs;            if (psInfo->nPrecision == AVC_SINGLE_PREC)            {                psPal->sMin.x = atof(pszLine + 10);                psPal->sMin.y = atof(pszLine + 24);                psPal->sMax.x = atof(pszLine + 38);                psPal->sMax.y = atof(pszLine + 52);            }            else            {                psPal->sMin.x = atof(pszLine + 10);                psPal->sMin.y = atof(pszLine + 31);                /* Set psInfo->iCurItem = -1 since we still have 2 values                 * from the header to read on the next line.                 */                psInfo->iCurItem = -1;            }        }    }    else if (psInfo->iCurItem == -1 && nLen >= 42)    {        psPal->sMax.x = atof(pszLine);        psPal->sMax.y = atof(pszLine + 21);        psInfo->iCurItem++;    }    else if (psInfo->iCurItem < psPal->numArcs &&              (nLen >= 60 ||              (psInfo->iCurItem == psPal->numArcs-1 && nLen >= 30)) )    {        /*-------------------------------------------------------------         * 2 PAL entries (ArcId, FNode, AdjPoly) per line,          * (Except on the last line with an odd number of vertices)         *------------------------------------------------------------*/        psPal->pasArcs[psInfo->iCurItem].nArcId = AVCE00Str2Int(pszLine, 10);        psPal->pasArcs[psInfo->iCurItem].nFNode = AVCE00Str2Int(pszLine+10,10);        psPal->pasArcs[psInfo->iCurItem++].nAdjPoly = AVCE00Str2Int(pszLine+20,                                                                    10);        if (psInfo->iCurItem < psInfo->numItems)        {            psPal->pasArcs[psInfo->iCurItem].nArcId = AVCE00Str2Int(pszLine+30,                                                                    10);            psPal->pasArcs[psInfo->iCurItem].nFNode = AVCE00Str2Int(pszLine+40,                                                                    10);            psPal->pasArcs[psInfo->iCurItem++].nAdjPoly =                                                 AVCE00Str2Int(pszLine+50, 10);        }     }    else    {        CPLError(CE_Failure, CPLE_AppDefined,                  "Error parsing E00 PAL line: \"%s\"", pszLine);        psInfo->numItems = psInfo->iCurItem = 0;        return NULL;    }    /*-----------------------------------------------------------------     * If we're done parsing this PAL, then reset the ParseInfo,     * and return a reference to the PAL 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 psPal;    }    return NULL;}/********************************************************************** *                          AVCE00ParseNextCntLine() * * Take the next line of E00 input for an CNT 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. **********************************************************************/AVCCnt   *AVCE00ParseNextCntLine(AVCE00ParseInfo *psInfo, const char *pszLine){    AVCCnt *psCnt;    int     nLen;    CPLAssert(psInfo->eFileType == AVCFileCNT);    psCnt = psInfo->cur.psCnt;    nLen = strlen(pszLine);    if (psInfo->numItems == 0)    {        /*-------------------------------------------------------------         * Begin processing a new object, read header line:         *    numLabels, X, Y         *------------------------------------------------------------*/        if (nLen < 38)        {            CPLError(CE_Failure, CPLE_AppDefined,                      "Error parsing E00 CNT line: \"%s\"", pszLine);            return NULL;        }        else        {            /* Polygon Id is not stored in the E00 file.  Centroids are             * stored in increasing order of Polygon Id, starting at 1...             * so we just increment the previous value.             */            psCnt->nPolyId = ++psInfo->nCurObjectId;            psCnt->numLabels = AVCE00Str2Int(pszLine, 10);            /* Realloc the array of Labels Ids             * Avoid allocating a 0-length segment since centroids can have             * 0 labels attached to them.             */            if (psCnt->numLabels > 0)                psCnt->panLabelIds = (GInt32 *)CPLRealloc(psCnt->panLabelIds,                                                          psCnt->numLabels*                                                          sizeof(GInt32));            if (psInfo->nPrecision == AVC_SINGLE_PREC)            {                psCnt->sCoord.x = atof(pszLine + 10);                psCnt->sCoord.y = atof(pszLine + 24);            }            else            {                psCnt->sCoord.x = atof(pszLine + 10);                psCnt->sCoord.y = atof(pszLine + 31);            }            /* psInfo->iCurItem is the index of the last label that was read.             * psInfo->numItems is the number of label ids to read.             */            psInfo->iCurItem = 0;            psInfo->numItems = psCnt->numLabels;        }    }    else if (psInfo->iCurItem < psInfo->numItems )    {        /*-------------------------------------------------------------         * Each line can contain up to 8 label ids (10 chars each)         *------------------------------------------------------------*/        int i=0;        while(psInfo->iCurItem < psInfo->numItems && nLen >= (i+1)*10)        {            psCnt->panLabelIds[psInfo->iCurItem++] =                                   AVCE00Str2Int(pszLine + i*10, 10);            i++;        }    }    else    {        CPLError(CE_Failure, CPLE_AppDefined,                  "Error parsing E00 CNT line: \"%s\"", pszLine);        psInfo->numItems = psInfo->iCurItem = 0;        return NULL;    }    /*-----------------------------------------------------------------     * If we're done parsing this CNT, then reset the ParseInfo,     * and return a reference to the CNT 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 psCnt;    }    return NULL;}/**********************************************************************

⌨️ 快捷键说明

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