📄 avc_bin.c
字号:
psFile->hdr.psTableDef->pasFieldDef, psFile->cur.pasFields) == 0) { return psFile->cur.pasFields; } return NULL;}/*===================================================================== * ARC *====================================================================*//********************************************************************** * _AVCBinReadNextArc() * * (This function is for internal library use... external calls should * go to AVCBinReadNextArc() instead) * * Read the next Arc structure from the file. * * The contents of the psArc structure is assumed to be valid, and the * psArc->pasVertices buffer may be reallocated or free()'d if it is not * NULL. * * Returns 0 on success or -1 on error. **********************************************************************/int _AVCBinReadNextArc(AVCRawBinFile *psFile, AVCArc *psArc, int nPrecision){ int i, numVertices; int nRecordSize, nStartPos, nBytesRead; psArc->nArcId = AVCRawBinReadInt32(psFile); if (AVCRawBinEOF(psFile)) return -1; nRecordSize = AVCRawBinReadInt32(psFile) * 2; nStartPos = psFile->nCurPos+psFile->nOffset; psArc->nUserId = AVCRawBinReadInt32(psFile); psArc->nFNode = AVCRawBinReadInt32(psFile); psArc->nTNode = AVCRawBinReadInt32(psFile); psArc->nLPoly = AVCRawBinReadInt32(psFile); psArc->nRPoly = AVCRawBinReadInt32(psFile); numVertices = AVCRawBinReadInt32(psFile); /* Realloc the vertices array only if it needs to grow... * do not realloc to a smaller size. * Note that for simplicity reasons, we always store the vertices as * double values in memory, even for single precision coverages. */ if (psArc->pasVertices == NULL || numVertices > psArc->numVertices) psArc->pasVertices = (AVCVertex*)CPLRealloc(psArc->pasVertices, numVertices*sizeof(AVCVertex)); psArc->numVertices = numVertices; if (nPrecision == AVC_SINGLE_PREC) { for(i=0; i<numVertices; i++) { psArc->pasVertices[i].x = AVCRawBinReadFloat(psFile); psArc->pasVertices[i].y = AVCRawBinReadFloat(psFile); } } else { for(i=0; i<numVertices; i++) { psArc->pasVertices[i].x = AVCRawBinReadDouble(psFile); psArc->pasVertices[i].y = AVCRawBinReadDouble(psFile); } } /*----------------------------------------------------------------- * Record size may be larger than number of vertices. Skip up to * start of next object. *----------------------------------------------------------------*/ nBytesRead = (psFile->nCurPos + psFile->nOffset) - nStartPos; if ( nBytesRead < nRecordSize) AVCRawBinFSeek(psFile, nRecordSize - nBytesRead, SEEK_CUR); return 0;}/********************************************************************** * AVCBinReadNextArc() * * Read the next Arc structure from the file. * * Returns a pointer to a static AVCArc structure whose contents will be * valid only until the next call or NULL if an error happened or if EOF * was reached. **********************************************************************/AVCArc *AVCBinReadNextArc(AVCBinFile *psFile){ if (psFile->eFileType != AVCFileARC || AVCRawBinEOF(psFile->psRawBinFile) || _AVCBinReadNextArc(psFile->psRawBinFile, psFile->cur.psArc, psFile->nPrecision) !=0) { return NULL; } return psFile->cur.psArc;}/*===================================================================== * PAL *====================================================================*//********************************************************************** * _AVCBinReadNextPal() * * (This function is for internal library use... external calls should * go to AVCBinReadNextPal() instead) * * Read the next PAL (Polygon Arc List) structure from the file. * * The contents of the psPal structure is assumed to be valid, and the * psPal->paVertices buffer may be reallocated or free()'d if it is not * NULL. * * Returns 0 on success or -1 on error. **********************************************************************/int _AVCBinReadNextPal(AVCRawBinFile *psFile, AVCPal *psPal, int nPrecision){ int i, numArcs; int nRecordSize, nStartPos, nBytesRead; psPal->nPolyId = AVCRawBinReadInt32(psFile); nRecordSize = AVCRawBinReadInt32(psFile) * 2; nStartPos = psFile->nCurPos+psFile->nOffset; if (AVCRawBinEOF(psFile)) return -1; if (nPrecision == AVC_SINGLE_PREC) { psPal->sMin.x = AVCRawBinReadFloat(psFile); psPal->sMin.y = AVCRawBinReadFloat(psFile); psPal->sMax.x = AVCRawBinReadFloat(psFile); psPal->sMax.y = AVCRawBinReadFloat(psFile); } else { psPal->sMin.x = AVCRawBinReadDouble(psFile); psPal->sMin.y = AVCRawBinReadDouble(psFile); psPal->sMax.x = AVCRawBinReadDouble(psFile); psPal->sMax.y = AVCRawBinReadDouble(psFile); } numArcs = AVCRawBinReadInt32(psFile); /* Realloc the arc list array only if it needs to grow... * do not realloc to a smaller size. */ if (psPal->pasArcs == NULL || numArcs > psPal->numArcs) psPal->pasArcs = (AVCPalArc*)CPLRealloc(psPal->pasArcs, numArcs*sizeof(AVCPalArc)); psPal->numArcs = numArcs; for(i=0; i<numArcs; i++) { psPal->pasArcs[i].nArcId = AVCRawBinReadInt32(psFile); psPal->pasArcs[i].nFNode = AVCRawBinReadInt32(psFile); psPal->pasArcs[i].nAdjPoly = AVCRawBinReadInt32(psFile); } /*----------------------------------------------------------------- * Record size may be larger than number of vertices. Skip up to * start of next object. *----------------------------------------------------------------*/ nBytesRead = (psFile->nCurPos + psFile->nOffset) - nStartPos; if ( nBytesRead < nRecordSize) AVCRawBinFSeek(psFile, nRecordSize - nBytesRead, SEEK_CUR); return 0;}/********************************************************************** * AVCBinReadNextPal() * * Read the next PAL structure from the file. * * Returns a pointer to a static AVCPal structure whose contents will be * valid only until the next call or NULL if an error happened or if EOF * was reached. **********************************************************************/AVCPal *AVCBinReadNextPal(AVCBinFile *psFile){ if ((psFile->eFileType!=AVCFilePAL && psFile->eFileType!=AVCFileRPL) || AVCRawBinEOF(psFile->psRawBinFile) || _AVCBinReadNextPal(psFile->psRawBinFile, psFile->cur.psPal, psFile->nPrecision) !=0) { return NULL; } return psFile->cur.psPal;}/*===================================================================== * CNT *====================================================================*//********************************************************************** * _AVCBinReadNextCnt() * * (This function is for internal library use... external calls should * go to AVCBinReadNextCnt() instead) * * Read the next CNT (Polygon Centroid) structure from the file. * * Returns 0 on success or -1 on error. **********************************************************************/int _AVCBinReadNextCnt(AVCRawBinFile *psFile, AVCCnt *psCnt, int nPrecision){ int i, numLabels; int nRecordSize, nStartPos, nBytesRead; psCnt->nPolyId = AVCRawBinReadInt32(psFile); nRecordSize = AVCRawBinReadInt32(psFile) * 2; nStartPos = psFile->nCurPos+psFile->nOffset; if (AVCRawBinEOF(psFile)) return -1; if (nPrecision == AVC_SINGLE_PREC) { psCnt->sCoord.x = AVCRawBinReadFloat(psFile); psCnt->sCoord.y = AVCRawBinReadFloat(psFile); } else { psCnt->sCoord.x = AVCRawBinReadDouble(psFile); psCnt->sCoord.y = AVCRawBinReadDouble(psFile); } numLabels = AVCRawBinReadInt32(psFile); /* Realloc the LabelIds array only if it needs to grow... * do not realloc to a smaller size. */ if (psCnt->panLabelIds == NULL || numLabels > psCnt->numLabels) psCnt->panLabelIds = (GInt32 *)CPLRealloc(psCnt->panLabelIds, numLabels*sizeof(GInt32)); psCnt->numLabels = numLabels; for(i=0; i<numLabels; i++) { psCnt->panLabelIds[i] = AVCRawBinReadInt32(psFile); } /*----------------------------------------------------------------- * Record size may be larger than number of vertices. Skip up to * start of next object. *----------------------------------------------------------------*/ nBytesRead = (psFile->nCurPos + psFile->nOffset) - nStartPos; if ( nBytesRead < nRecordSize) AVCRawBinFSeek(psFile, nRecordSize - nBytesRead, SEEK_CUR); return 0;}/********************************************************************** * AVCBinReadNextCnt() * * Read the next CNT structure from the file. * * Returns a pointer to a static AVCCnt structure whose contents will be * valid only until the next call or NULL if an error happened or if EOF * was reached. **********************************************************************/AVCCnt *AVCBinReadNextCnt(AVCBinFile *psFile){ if (psFile->eFileType != AVCFileCNT || AVCRawBinEOF(psFile->psRawBinFile) || _AVCBinReadNextCnt(psFile->psRawBinFile, psFile->cur.psCnt, psFile->nPrecision) !=0) { return NULL; } return psFile->cur.psCnt;}/*===================================================================== * LAB *====================================================================*//********************************************************************** * _AVCBinReadNextLab() * * (This function is for internal library use... external calls should * go to AVCBinReadNextLab() instead) * * Read the next LAB (Centroid Label) structure from the file. * * Returns 0 on success or -1 on error. **********************************************************************/int _AVCBinReadNextLab(AVCRawBinFile *psFile, AVCLab *psLab, int nPrecision){ psLab->nValue = AVCRawBinReadInt32(psFile); psLab->nPolyId = AVCRawBinReadInt32(psFile); if (AVCRawBinEOF(psFile)) return -1; if (nPrecision == AVC_SINGLE_PREC) { psLab->sCoord1.x = AVCRawBinReadFloat(psFile); psLab->sCoord1.y = AVCRawBinReadFloat(psFile); psLab->sCoord2.x = AVCRawBinReadFloat(psFile); psLab->sCoord2.y = AVCRawBinReadFloat(psFile); psLab->sCoord3.x = AVCRawBinReadFloat(psFile); psLab->sCoord3.y = AVCRawBinReadFloat(psFile); } else { psLab->sCoord1.x = AVCRawBinReadDouble(psFile); psLab->sCoord1.y = AVCRawBinReadDouble(psFile); psLab->sCoord2.x = AVCRawBinReadDouble(psFile); psLab->sCoord2.y = AVCRawBinReadDouble(psFile); psLab->sCoord3.x = AVCRawBinReadDouble(psFile); psLab->sCoord3.y = AVCRawBinReadDouble(psFile); } return 0;}/********************************************************************** * AVCBinReadNextLab() * * Read the next LAB structure from the file. * * Returns a pointer to a static AVCLab structure whose contents will be * valid only until the next call or NULL if an error happened or if EOF * was reached. **********************************************************************/AVCLab *AVCBinReadNextLab(AVCBinFile *psFile){ if (psFile->eFileType != AVCFileLAB || AVCRawBinEOF(psFile->psRawBinFile) || _AVCBinReadNextLab(psFile->psRawBinFile, psFile->cur.psLab, psFile->nPrecision) !=0) { return NULL; } return psFile->cur.psLab;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -