📄 avc_e00gen.c
字号:
psInfo->iCurItem++; } else { /* No more lines to generate for this TX6. */ return NULL; } return psInfo->pszBuf;}/*===================================================================== RXP stuff =====================================================================*//********************************************************************** * AVCE00GenRxp() * * Generate the next line of an E00 RXP entry (RXPs are related to regions). * * This function should be called once with bCont=FALSE to get the * first E00 line for the current RXP, and then call with bCont=TRUE * to get all the other lines for this RXP. * * The function returns NULL when there are no more lines to generate * for this RXP entry. **********************************************************************/const char *AVCE00GenRxp(AVCE00GenInfo *psInfo, AVCRxp *psRxp, GBool bCont){ if (bCont == TRUE) { /*--------------------------------------------------------- * RXP entries are only 1 line, we support the bCont flag * only for compatibility with the other AVCE00Gen*() functions. *--------------------------------------------------------*/ return NULL; } sprintf(psInfo->pszBuf, "%10d%10d", psRxp->n1, psRxp->n2); return psInfo->pszBuf;}/*===================================================================== TABLE stuff =====================================================================*//********************************************************************** * AVCE00GenTableHdr() * * Generate the next line of an E00 Table header. * * This function should be called once with bCont=FALSE to get the * first E00 line for the current table header, and then call with * bCont=TRUE to get all the other lines. * * The function returns NULL when there are no more lines to generate. **********************************************************************/const char *AVCE00GenTableHdr(AVCE00GenInfo *psInfo, AVCTableDef *psDef, GBool bCont){ if (bCont == FALSE) { int nRecSize; /* Initialize the psInfo structure with info about the * current Table Header */ psInfo->iCurItem = 0; psInfo->numItems = psDef->numFields; nRecSize = psDef->nRecSize;#ifdef AVC_MAP_TYPE40_TO_DOUBLE { /* Adjust Table record size if we're remapping type 40 fields */ int i; for(i=0; i<psDef->numFields; i++) { if (psDef->pasFieldDef[i].nType1*10 == AVC_FT_FIXNUM && psDef->pasFieldDef[i].nSize > 8) { nRecSize -= psDef->pasFieldDef[i].nSize; nRecSize += 8; } } nRecSize = ((nRecSize+1)/2)*2; }#endif /* And return the header's header line(!). */ sprintf(psInfo->pszBuf, "%-32.32s%s%4d%4d%4d%10d", psDef->szTableName, psDef->szExternal, psDef->numFields, psDef->numFields, nRecSize, psDef->numRecords); } else if (psInfo->iCurItem < psInfo->numItems) { int nSize, nType, nOffset; nSize = psDef->pasFieldDef[psInfo->iCurItem].nSize; nType = psDef->pasFieldDef[psInfo->iCurItem].nType1 * 10; nOffset = psDef->pasFieldDef[psInfo->iCurItem].nOffset;#ifdef AVC_MAP_TYPE40_TO_DOUBLE /* Type 40 fields with more than 12 digits written to E00 by Arc/Info * will lose some digits of precision (and we starts losing them at 8 * with the way AVC lib writes type 40). This (optional) hack will * remap type 40 fields with more than 8 digits to double precision * floats which can carry up to 18 digits of precision. (bug 599) */ if (nType == AVC_FT_FIXNUM && nSize > 8) { /* Remap to double-precision float */ nType = AVC_FT_BINFLOAT; nSize = 8; } /* Adjust field offset if this field is preceded by any type40 fields * that were remapped. */ { int i; for(i=0; i < psInfo->iCurItem; i++) { if (psDef->pasFieldDef[i].nType1*10 == AVC_FT_FIXNUM && psDef->pasFieldDef[i].nSize > 8) { nOffset -= psDef->pasFieldDef[i].nSize; nOffset += 8; } } }#endif /* Return next Field definition line */ sprintf(psInfo->pszBuf, "%-16.16s%3d%2d%4d%1d%2d%4d%2d%3d%2d%4d%4d%2d%-16.16s%4d-", psDef->pasFieldDef[psInfo->iCurItem].szName, nSize, psDef->pasFieldDef[psInfo->iCurItem].v2, nOffset, psDef->pasFieldDef[psInfo->iCurItem].v4, psDef->pasFieldDef[psInfo->iCurItem].v5, psDef->pasFieldDef[psInfo->iCurItem].nFmtWidth, psDef->pasFieldDef[psInfo->iCurItem].nFmtPrec, nType, psDef->pasFieldDef[psInfo->iCurItem].v10, psDef->pasFieldDef[psInfo->iCurItem].v11, psDef->pasFieldDef[psInfo->iCurItem].v12, psDef->pasFieldDef[psInfo->iCurItem].v13, psDef->pasFieldDef[psInfo->iCurItem].szAltName, psDef->pasFieldDef[psInfo->iCurItem].nIndex ); psInfo->iCurItem++; } else { /* No more lines to generate. */ return NULL; } return psInfo->pszBuf;}/********************************************************************** * AVCE00GenTableRec() * * Generate the next line of an E00 Table Data Record. * * This function should be called once with bCont=FALSE to get the * first E00 line for the current table record, and then call with * bCont=TRUE to get all the other lines. * * The function returns NULL when there are no more lines to generate. **********************************************************************/const char *AVCE00GenTableRec(AVCE00GenInfo *psInfo, int numFields, AVCFieldInfo *pasDef, AVCField *pasFields, GBool bCont){ int i, nSize, nType, nLen; char *pszBuf2; if (bCont == FALSE) { /*------------------------------------------------------------- * Initialize the psInfo structure to be ready to process this * new Table Record *------------------------------------------------------------*/ psInfo->iCurItem = 0;#ifdef AVC_MAP_TYPE40_TO_DOUBLE psInfo->numItems = _AVCE00ComputeRecSize(numFields, pasDef, TRUE);#else psInfo->numItems = _AVCE00ComputeRecSize(numFields, pasDef, FALSE);#endif /*------------------------------------------------------------- * First, we need to make sure that the output buffer is big * enough to hold the whole record, plus 81 chars to hold * the line that we'll return to the caller. *------------------------------------------------------------*/ nSize = psInfo->numItems + 1 + 81; if (psInfo->nBufSize < nSize) { psInfo->pszBuf = (char*)CPLRealloc(psInfo->pszBuf, nSize*sizeof(char)); psInfo->nBufSize = nSize; } /*------------------------------------------------------------- * Generate the whole record now, and we'll return it to the * caller by chunks of 80 chars. * The first 80 chars of the buffer will be used to return * one line at a time, and the rest of the buffer is used to * hold the whole record. *------------------------------------------------------------*/ pszBuf2 = psInfo->pszBuf+81; for(i=0; i<numFields; i++) { nType = pasDef[i].nType1*10; nSize = pasDef[i].nSize; if (nType == AVC_FT_DATE || nType == AVC_FT_CHAR || nType == AVC_FT_FIXINT ) { strncpy(pszBuf2, pasFields[i].pszStr, nSize); pszBuf2 += nSize; }#ifdef AVC_MAP_TYPE40_TO_DOUBLE /* See explanation in AVCE00GenTableHdr() about this hack to remap * type 40 fields to double precision floats. */ else if (nType == AVC_FT_FIXNUM && nSize > 8) { pszBuf2[0] = '\0'; /* NOTE: The E00 representation for a binary float is * defined by its binary size, not by the coverage's * precision. */ nLen = AVCPrintRealValue(pszBuf2, AVC_DOUBLE_PREC, AVCFileTABLE, atof(pasFields[i].pszStr)); pszBuf2 += nLen; }#endif else if (nType == AVC_FT_FIXNUM) { /* TYPE 40 attributes are stored with 1 byte per digit * in binary format, and as single precision floats in * E00 tables, even in double precision coverages. */ pszBuf2[0] = '\0'; nLen = AVCPrintRealValue(pszBuf2, AVC_SINGLE_PREC, AVCFileTABLE, atof(pasFields[i].pszStr)); pszBuf2 += nLen; } else if (nType == AVC_FT_BININT && nSize == 4) { sprintf(pszBuf2, "%11d", pasFields[i].nInt32); pszBuf2 += 11; } else if (nType == AVC_FT_BININT && nSize == 2) { sprintf(pszBuf2, "%6d", pasFields[i].nInt16); pszBuf2 += 6; } else if (nType == AVC_FT_BINFLOAT && nSize == 4) { pszBuf2[0] = '\0'; /* NOTE: The E00 representation for a binary float is * defined by its binary size, not by the coverage's * precision. */ nLen = AVCPrintRealValue(pszBuf2, AVC_SINGLE_PREC, AVCFileTABLE, pasFields[i].fFloat); pszBuf2 += nLen; } else if (nType == AVC_FT_BINFLOAT && nSize == 8) { pszBuf2[0] = '\0'; /* NOTE: The E00 representation for a binary float is * defined by its binary size, not by the coverage's * precision. */ nLen = AVCPrintRealValue(pszBuf2, AVC_DOUBLE_PREC, AVCFileTABLE, pasFields[i].dDouble); pszBuf2 += nLen; } else { /*----------------------------------------------------- * Hummm... unsupported field type... *----------------------------------------------------*/ CPLError(CE_Failure, CPLE_NotSupported, "Unsupported field type: (type=%d, size=%d)", nType, nSize); return NULL; } } *pszBuf2 = '\0'; } if (psInfo->iCurItem < psInfo->numItems) { /*------------------------------------------------------------- * Return the next 80 chars chunk. * The first 80 chars of the buffer is used to return * one line at a time, and the rest of the buffer (chars 81+) * is used to hold the whole record. *------------------------------------------------------------*/ nLen = psInfo->numItems - psInfo->iCurItem; if (nLen > 80) nLen = 80; strncpy(psInfo->pszBuf, psInfo->pszBuf+(81+psInfo->iCurItem), nLen); psInfo->pszBuf[nLen] = '\0'; psInfo->iCurItem += nLen; /*------------------------------------------------------------- * Arc/Info removes spaces at the end of the lines... let's * remove them as well since it can reduce the E00 file size. *------------------------------------------------------------*/ nLen--; while(nLen >= 0 && psInfo->pszBuf[nLen] == ' ') { psInfo->pszBuf[nLen] = '\0'; nLen--; } } else { /* No more lines to generate. */ return NULL; } return psInfo->pszBuf;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -