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

📄 avc_binwr.c

📁 GIS系统支持库Geospatial Data Abstraction Library代码.GDAL is a translator library for raster geospatial dat
💻 C
📖 第 1 页 / 共 5 页
字号:
     * Write a header only if applicable.     *----------------------------------------------------------------*/    if (bHeader)        nStatus = _AVCBinWriteHeader(psFile->psRawBinFile, &sHeader,                                     psFile->eCoverType);    /*-----------------------------------------------------------------     * Write a header for the index file... it is identical to the main     * file's header.     *----------------------------------------------------------------*/    if (nStatus == 0 && bHeader && psFile->psIndexFile)        nStatus = _AVCBinWriteHeader(psFile->psIndexFile, &sHeader,                                     psFile->eCoverType);    return nStatus;}/********************************************************************** *                          AVCBinWriteClose() * * Close a coverage file opened for wirting, and release all memory  * (object strcut., buffers, etc.) associated with this file. **********************************************************************/void    AVCBinWriteClose(AVCBinFile *psFile){    if (psFile->eFileType == AVCFileTABLE)    {        _AVCBinWriteCloseTable(psFile);        return;    }    /*-----------------------------------------------------------------     * Write the file size (nbr of 2 byte words) in the header at      * byte 24 in the 100 byte header (only if applicable)     * (And write the same value at byte 2-5 in the first header of PC Cover)     *----------------------------------------------------------------*/    if (psFile->psRawBinFile &&        (psFile->eFileType == AVCFileARC ||         psFile->eFileType == AVCFilePAL ||         psFile->eFileType == AVCFileRPL ||         psFile->eFileType == AVCFileLAB ||         psFile->eFileType == AVCFileCNT ||         psFile->eFileType == AVCFileTXT ||         psFile->eFileType == AVCFileTX6 ||         (psFile->eFileType == AVCFileTOL &&           psFile->nPrecision == AVC_DOUBLE_PREC) ) )    {        GInt32 n32Size;        n32Size = psFile->psRawBinFile->nCurPos/2;        if (psFile->eCoverType == AVCCoverPC)        {            /* PC Cover... Pad to multiple of 512 bytes and write 2 headers             * extra bytes at EOF are not included in the size written in             * header.             * The first 256 bytes header is not counted in the file size              * written in both headers             */            n32Size -= 128;  /* minus 256 bytes */            if (psFile->psRawBinFile->nCurPos%512 != 0)                AVCRawBinWriteZeros(psFile->psRawBinFile,                                     512 - psFile->psRawBinFile->nCurPos%512);                            VSIFSeek(psFile->psRawBinFile->fp, 2, SEEK_SET);            AVCRawBinWriteInt32(psFile->psRawBinFile, n32Size);            VSIFSeek(psFile->psRawBinFile->fp, 256+24, SEEK_SET);            AVCRawBinWriteInt32(psFile->psRawBinFile, n32Size);        }        else        {            /* V7 Cover ... only 1 header */            VSIFSeek(psFile->psRawBinFile->fp, 24, SEEK_SET);            AVCRawBinWriteInt32(psFile->psRawBinFile, n32Size);        }    }            AVCRawBinClose(psFile->psRawBinFile);    psFile->psRawBinFile = NULL;    /*-----------------------------------------------------------------     * Same for the index file if it exists.     *----------------------------------------------------------------*/    if (psFile->psIndexFile)    {        GInt32 n32Size;        n32Size = psFile->psIndexFile->nCurPos/2;        if (psFile->eCoverType == AVCCoverPC)        {            /* PC Cover... Pad to multiple of 512 bytes and write 2 headers             * extra bytes at EOF are not included in the size written in             * header             */            n32Size -= 128;  /* minus 256 bytes */            if (psFile->psIndexFile->nCurPos%512 != 0)                AVCRawBinWriteZeros(psFile->psIndexFile,                                     512 - psFile->psIndexFile->nCurPos%512);                            VSIFSeek(psFile->psIndexFile->fp, 2, SEEK_SET);            AVCRawBinWriteInt32(psFile->psIndexFile, n32Size);            VSIFSeek(psFile->psIndexFile->fp, 256+24, SEEK_SET);            AVCRawBinWriteInt32(psFile->psIndexFile, n32Size);        }        else        {            /* V7 Cover ... only 1 header */            VSIFSeek(psFile->psIndexFile->fp, 24, SEEK_SET);            AVCRawBinWriteInt32(psFile->psIndexFile, n32Size);        }        AVCRawBinClose(psFile->psIndexFile);        psFile->psIndexFile = NULL;    }    CPLFree(psFile->pszFilename);    CPLFree(psFile);}/********************************************************************** *                          _AVCBinWriteIndexEntry() * * (This function is for internal library use... the index entries * are automatically handled by the AVCBinWrite*() functions) * * Write an Index Entry at the current position in the file. * * Position is relative to the beginning of the file, including the header. * Both position and size are specified in number of 2 byte words. * * Returns 0 on success or -1 on error. **********************************************************************/int _AVCBinWriteIndexEntry(AVCRawBinFile *psFile,                            int nPosition, int nSize){    AVCRawBinWriteInt32(psFile, nPosition);    AVCRawBinWriteInt32(psFile, nSize);    if (CPLGetLastErrorNo() != 0)        return -1;    return 0;}/********************************************************************** *                          AVCBinWriteObject() * * Write a CNT (Polygon Centroid) structure to the fin object to a  * coverage file. * * Simply redirects the call to the right function based on the value * of psFile->eFileType. * * Returns 0 on success or -1 on error. * * If a problem happens, then CPLError() will be called by the lower-level * functions and CPLGetLastErrorNo() can be used to find out what happened. **********************************************************************/int AVCBinWriteObject(AVCBinFile *psFile, void *psObj){    int nStatus = 0;    switch(psFile->eFileType)    {      case AVCFileARC:        nStatus = AVCBinWriteArc(psFile, (AVCArc *)psObj);        break;      case AVCFilePAL:      case AVCFileRPL:        nStatus = AVCBinWritePal(psFile, (AVCPal *)psObj);        break;      case AVCFileCNT:        nStatus = AVCBinWriteCnt(psFile, (AVCCnt *)psObj);        break;      case AVCFileLAB:        nStatus = AVCBinWriteLab(psFile, (AVCLab *)psObj);        break;      case AVCFileTOL:        nStatus = AVCBinWriteTol(psFile, (AVCTol *)psObj);        break;      case AVCFilePRJ:        nStatus = AVCBinWritePrj(psFile, (char **)psObj);        break;      case AVCFileTXT:      case AVCFileTX6:        nStatus = AVCBinWriteTxt(psFile, (AVCTxt *)psObj);        break;      case AVCFileRXP:        nStatus = AVCBinWriteRxp(psFile, (AVCRxp *)psObj);        break;      case AVCFileTABLE:        nStatus = AVCBinWriteTableRec(psFile, (AVCField *)psObj);        break;      default:        CPLError(CE_Failure, CPLE_IllegalArg,                 "AVCBinWriteObject(): Unsupported file type!");        nStatus = -1;    }    return nStatus;}/*===================================================================== *                              ARC *====================================================================*//********************************************************************** *                          _AVCBinWriteArc() * * (This function is for internal library use... external calls should * go to AVCBinWriteNextArc() instead) * * Write an Arc structure to the file. * * The contents of the psArc structure is assumed to be valid... this * function performs no validation on the consistency of what it is  * given as input. * * Returns 0 on success or -1 on error. **********************************************************************/int _AVCBinWriteArc(AVCRawBinFile *psFile, AVCArc *psArc,                    int nPrecision, AVCRawBinFile *psIndexFile){    int         i, nRecSize, nCurPos;    nCurPos = psFile->nCurPos/2;  /* Value in 2 byte words */    AVCRawBinWriteInt32(psFile, psArc->nArcId);    if (CPLGetLastErrorNo() != 0)        return -1;    /*-----------------------------------------------------------------     * Record size is expressed in 2 byte words, and does not count the     * first 8 bytes of the ARC entry.     *----------------------------------------------------------------*/    nRecSize = (6 * 4 + psArc->numVertices*2 *                 ((nPrecision == AVC_SINGLE_PREC)? 4 : 8)) / 2;    AVCRawBinWriteInt32(psFile, nRecSize);    AVCRawBinWriteInt32(psFile, psArc->nUserId);    AVCRawBinWriteInt32(psFile, psArc->nFNode);    AVCRawBinWriteInt32(psFile, psArc->nTNode);    AVCRawBinWriteInt32(psFile, psArc->nLPoly);    AVCRawBinWriteInt32(psFile, psArc->nRPoly);    AVCRawBinWriteInt32(psFile, psArc->numVertices);    if (nPrecision == AVC_SINGLE_PREC)    {        for(i=0; i<psArc->numVertices; i++)        {            AVCRawBinWriteFloat(psFile, (float)psArc->pasVertices[i].x);            AVCRawBinWriteFloat(psFile, (float)psArc->pasVertices[i].y);        }    }    else    {        for(i=0; i<psArc->numVertices; i++)        {            AVCRawBinWriteDouble(psFile, psArc->pasVertices[i].x);            AVCRawBinWriteDouble(psFile, psArc->pasVertices[i].y);        }    }    /*-----------------------------------------------------------------     * Write index entry (arx.adf)     *----------------------------------------------------------------*/    if (psIndexFile)    {        _AVCBinWriteIndexEntry(psIndexFile, nCurPos, nRecSize);    }    if (CPLGetLastErrorNo() != 0)        return -1;    return 0;}/********************************************************************** *                          AVCBinWriteArc() * * Write the next Arc structure to the file. * * The contents of the psArc structure is assumed to be valid... this * function performs no validation on the consistency of what it is  * given as input. * * Returns 0 on success or -1 on error. * * If a problem happens, then CPLError() will be called by the lower-level * functions and CPLGetLastErrorNo() can be used to find out what happened. **********************************************************************/int AVCBinWriteArc(AVCBinFile *psFile, AVCArc *psArc){    if (psFile->eFileType != AVCFileARC)        return -1;    return _AVCBinWriteArc(psFile->psRawBinFile, psArc,                           psFile->nPrecision, psFile->psIndexFile);}/*===================================================================== *                              PAL *====================================================================*//********************************************************************** *                          _AVCBinWritePal() * * (This function is for internal library use... external calls should * go to AVCBinWritePal() instead) * * Write a PAL (Polygon Arc List) structure to the file. * * The contents of the psPal structure is assumed to be valid... this * function performs no validation on the consistency of what it is  * given as input. * * Returns 0 on success or -1 on error. **********************************************************************/int _AVCBinWritePal(AVCRawBinFile *psFile, AVCPal *psPal,                     int nPrecision, AVCRawBinFile *psIndexFile){    int i, nRecSize, nCurPos;    nCurPos = psFile->nCurPos/2;  /* Value in 2 byte words */    AVCRawBinWriteInt32(psFile, psPal->nPolyId);    if (CPLGetLastErrorNo() != 0)        return -1;    /*-----------------------------------------------------------------     * Record size is expressed in 2 byte words, and does not count the     * first 8 bytes of the PAL entry.     *----------------------------------------------------------------*/    nRecSize = ( 4 + psPal->numArcs*3 * 4 +                 4 * ((nPrecision == AVC_SINGLE_PREC)? 4 : 8)) / 2;    AVCRawBinWriteInt32(psFile, nRecSize);    if (nPrecision == AVC_SINGLE_PREC)    {        AVCRawBinWriteFloat(psFile, (float)psPal->sMin.x);        AVCRawBinWriteFloat(psFile, (float)psPal->sMin.y);        AVCRawBinWriteFloat(psFile, (float)psPal->sMax.x);        AVCRawBinWriteFloat(psFile, (float)psPal->sMax.y);    }    else    {        AVCRawBinWriteDouble(psFile, psPal->sMin.x);        AVCRawBinWriteDouble(psFile, psPal->sMin.y);        AVCRawBinWriteDouble(psFile, psPal->sMax.x);        AVCRawBinWriteDouble(psFile, psPal->sMax.y);    }    AVCRawBinWriteInt32(psFile, psPal->numArcs);

⌨️ 快捷键说明

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