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

📄 avc_bin.c

📁 用于读取TAB、MIF、SHP文件的类
💻 C
📖 第 1 页 / 共 5 页
字号:
/********************************************************************** * $Id: avc_bin.c,v 1.28 2006/06/14 16:31:28 daniel Exp $ * * Name:     avc_bin.c * Project:  Arc/Info vector coverage (AVC)  BIN->E00 conversion library * Language: ANSI C * Purpose:  Binary files access functions. * Author:   Daniel Morissette, dmorissette@dmsolutions.ca * ********************************************************************** * Copyright (c) 1999-2005, Daniel Morissette * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: *  * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. *  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER  * DEALINGS IN THE SOFTWARE. ********************************************************************** * * $Log: avc_bin.c,v $ * Revision 1.28  2006/06/14 16:31:28  daniel * Added support for AVCCoverPC2 type (bug 1491) * * Revision 1.27  2005/06/03 03:49:58  daniel * Update email address, website url, and copyright dates * * Revision 1.26  2004/02/28 06:35:49  warmerda * Fixed AVCBinReadObject() index support to use 'x' or 'X' for index * depending on the case of the original name. * Fixed so that PC Arc/Info coverages with the extra 256 byte header work * properly when using indexes to read them. *   http://bugzilla.remotesensing.org/show_bug.cgi?id=493 * * Revision 1.25  2004/02/11 05:49:44  daniel * Added support for deleted flag in arc.dir (bug 2332) * * Revision 1.24  2002/08/27 15:26:06  daniel * Removed C++ style comments for IRIX compiler (GDAL bug 192) * * Revision 1.23  2002/04/16 20:04:24  daniel * Use record size while reading ARC, PAL, CNT to skip junk bytes. (bug940) * * Revision 1.22  2002/03/18 19:03:37  daniel * Fixed AVCBinReadObject() for PAL objects (bug 848) * * Revision 1.21  2002/02/14 22:54:13  warmerda * added polygon and table support for random reading * * Revision 1.20  2002/02/13 20:35:24  warmerda * added AVCBinReadObject * * Revision 1.19  2001/11/25 22:01:23  daniel * Fixed order of args to AVCRawBinFSeek() in _AVCBinReadNextTableRec() * * Revision 1.18  2000/10/16 16:16:20  daniel * Accept TXT files in AVCCoverWeird that use both PC or V7 TXT structure * * Revision 1.17  2000/09/26 20:21:04  daniel * Added AVCCoverPC write * * Revision 1.16  2000/09/22 19:45:20  daniel * Switch to MIT-style license * * Revision 1.15  2000/09/20 15:09:34  daniel * Check for DAT/NIT fnames sometimes truncated to 8 chars in weird coverages * * Revision 1.14  2000/06/05 21:38:53  daniel * Handle precision field > 1000 in cover file header as meaning double prec. * * Revision 1.13  2000/05/29 15:31:30  daniel * Added Japanese DBCS support * * Revision 1.12  2000/02/14 17:22:36  daniel * Check file signature (9993 or 9994) when reading header. * * Revision 1.11  2000/02/02 04:24:52  daniel * Support double precision "weird" coverages * * Revision 1.10  2000/01/10 02:54:10  daniel * Added read support for "weird" coverages * * Revision 1.9  2000/01/07 07:11:51  daniel * Added support for reading PC Coverage TXT files * * Revision 1.8  1999/12/24 07:38:10  daniel * Added missing DBFClose() * * Revision 1.7  1999/12/24 07:18:34  daniel * Added PC Arc/Info coverages support * * Revision 1.6  1999/08/23 18:17:16  daniel * Modified AVCBinReadListTables() to return INFO fnames for DeleteCoverage() * * Revision 1.5  1999/05/11 01:49:08  daniel * Simple changes required by addition of coverage write support * * Revision 1.4  1999/03/03 18:42:53  daniel * Fixed problem with INFO table headers (arc.dir) that sometimes contain an * invalid number of records. * * Revision 1.3  1999/02/25 17:01:53  daniel * Added support for 16 bit integers in INFO tables (type=50, size=2) * * Revision 1.2  1999/02/25 03:41:28  daniel * Added TXT, TX6/TX7, RXP and RPL support * * Revision 1.1  1999/01/29 16:28:52  daniel * Initial revision * **********************************************************************/#include "avc.h"#include <ctype.h>      /* for isspace() *//*===================================================================== * Prototypes for some static functions *====================================================================*/static AVCBinFile *_AVCBinReadOpenTable(const char *pszInfoPath,                                        const char *pszTableName,                                        AVCCoverType eCoverType,                                        AVCDBCSInfo *psDBCSInfo);static AVCBinFile *_AVCBinReadOpenDBFTable(const char *pszInfoPath,                                           const char *pszTableName);static AVCBinFile *_AVCBinReadOpenPrj(const char *pszPath,const char *pszName);static int _AVCBinReadNextTableRec(AVCRawBinFile *psFile, int nFields,                                   AVCFieldInfo *pasDef, AVCField *pasFields,                                   int nRecordSize);static int _AVCBinReadNextDBFTableRec(DBFHandle hDBFFile, int *piRecordIndex,                                       int nFields, AVCFieldInfo *pasDef,                                      AVCField *pasFields);/*===================================================================== * Stuff related to reading the binary coverage files *====================================================================*//********************************************************************** *                          AVCBinReadOpen() * * Open a coverage file for reading, read the file header if applicable, * and initialize a temp. storage structure to be ready to read objects * from the file. * * pszPath is the coverage (or info directory) path, terminated by *         a '/' or a '\\' * pszName is the name of the file to open relative to this directory. * * Note: For most file types except tables, passing pszPath="" and  * including the coverage path as part of pszName instead would work. * * Returns a valid AVCBinFile handle, or NULL if the file could * not be opened. * * AVCBinClose() will eventually have to be called to release the  * resources used by the AVCBinFile structure. **********************************************************************/AVCBinFile *AVCBinReadOpen(const char *pszPath, const char *pszName,                            AVCCoverType eCoverType, AVCFileType eFileType,                           AVCDBCSInfo *psDBCSInfo){    AVCBinFile   *psFile;    /*-----------------------------------------------------------------     * The case of INFO tables is a bit more complicated...     * pass the control to a separate function.     *----------------------------------------------------------------*/    if (eFileType == AVCFileTABLE)    {        if (eCoverType == AVCCoverPC || eCoverType == AVCCoverPC2)            return _AVCBinReadOpenDBFTable(pszPath, pszName);        else            return _AVCBinReadOpenTable(pszPath, pszName,                                         eCoverType, psDBCSInfo);    }    /*-----------------------------------------------------------------     * PRJ files are text files... we won't use the AVCRawBin*()     * functions for them...     *----------------------------------------------------------------*/    if (eFileType == AVCFilePRJ)    {        return _AVCBinReadOpenPrj(pszPath, pszName);    }    /*-----------------------------------------------------------------     * All other file types share a very similar opening method.     *----------------------------------------------------------------*/    psFile = (AVCBinFile*)CPLCalloc(1, sizeof(AVCBinFile));    psFile->eFileType = eFileType;    psFile->eCoverType = eCoverType;    psFile->pszFilename = (char*)CPLMalloc((strlen(pszPath)+strlen(pszName)+1)*                                           sizeof(char));    sprintf(psFile->pszFilename, "%s%s", pszPath, pszName);    AVCAdjustCaseSensitiveFilename(psFile->pszFilename);    psFile->psRawBinFile = AVCRawBinOpen(psFile->pszFilename, "r",                                         AVC_COVER_BYTE_ORDER(eCoverType),                                         psDBCSInfo);    if (psFile->psRawBinFile == NULL)    {        /* Failed to open file... just return NULL since an error message         * has already been issued by AVCRawBinOpen()         */        CPLFree(psFile->pszFilename);        CPLFree(psFile);        return NULL;    }    /*-----------------------------------------------------------------     * Read the header, and set the precision field if applicable     *----------------------------------------------------------------*/    if (AVCBinReadRewind(psFile) != 0)    {        CPLFree(psFile->pszFilename);        CPLFree(psFile);        return NULL;    }    /*-----------------------------------------------------------------     * Allocate a temp. structure to use to read objects from the file     * (Using Calloc() will automatically initialize the struct contents     *  to NULL... this is very important for ARCs and PALs)     *----------------------------------------------------------------*/    if (psFile->eFileType == AVCFileARC)    {        psFile->cur.psArc = (AVCArc*)CPLCalloc(1, sizeof(AVCArc));    }    else if (psFile->eFileType == AVCFilePAL ||             psFile->eFileType == AVCFileRPL )    {        psFile->cur.psPal = (AVCPal*)CPLCalloc(1, sizeof(AVCPal));    }    else if (psFile->eFileType == AVCFileCNT)    {        psFile->cur.psCnt = (AVCCnt*)CPLCalloc(1, sizeof(AVCCnt));    }    else if (psFile->eFileType == AVCFileLAB)    {        psFile->cur.psLab = (AVCLab*)CPLCalloc(1, sizeof(AVCLab));    }    else if (psFile->eFileType == AVCFileTOL)    {        psFile->cur.psTol = (AVCTol*)CPLCalloc(1, sizeof(AVCTol));    }    else if (psFile->eFileType == AVCFileTXT ||             psFile->eFileType == AVCFileTX6)    {        psFile->cur.psTxt = (AVCTxt*)CPLCalloc(1, sizeof(AVCTxt));    }    else if (psFile->eFileType == AVCFileRXP)    {        psFile->cur.psRxp = (AVCRxp*)CPLCalloc(1, sizeof(AVCRxp));    }    else    {        CPLError(CE_Failure, CPLE_IllegalArg,                 "%s: Unsupported file type or corrupted file.",                 psFile->pszFilename);        CPLFree(psFile->pszFilename);        CPLFree(psFile);        psFile = NULL;    }    return psFile;}/********************************************************************** *                          AVCBinReadClose() * * Close a coverage file, and release all memory (object strcut., buffers, * etc.) associated with this file. **********************************************************************/void    AVCBinReadClose(AVCBinFile *psFile){    AVCRawBinClose(psFile->psRawBinFile);    psFile->psRawBinFile = NULL;    CPLFree(psFile->pszFilename);    psFile->pszFilename = NULL;    if (psFile->hDBFFile)        DBFClose(psFile->hDBFFile);    if( psFile->psIndexFile != NULL )        AVCRawBinClose( psFile->psIndexFile );    if (psFile->eFileType == AVCFileARC)    {        if (psFile->cur.psArc)            CPLFree(psFile->cur.psArc->pasVertices);        CPLFree(psFile->cur.psArc);    }    else if (psFile->eFileType == AVCFilePAL ||             psFile->eFileType == AVCFileRPL )    {        if (psFile->cur.psPal)            CPLFree(psFile->cur.psPal->pasArcs);        CPLFree(psFile->cur.psPal);    }    else if (psFile->eFileType == AVCFileCNT)    {        if (psFile->cur.psCnt)            CPLFree(psFile->cur.psCnt->panLabelIds);        CPLFree(psFile->cur.psCnt);    }    else if (psFile->eFileType == AVCFileLAB)    {        CPLFree(psFile->cur.psLab);    }    else if (psFile->eFileType == AVCFileTOL)    {        CPLFree(psFile->cur.psTol);    }    else if (psFile->eFileType == AVCFilePRJ)    {        CSLDestroy(psFile->cur.papszPrj);    }    else if (psFile->eFileType == AVCFileTXT ||              psFile->eFileType == AVCFileTX6)    {        if (psFile->cur.psTxt)        {            CPLFree(psFile->cur.psTxt->pasVertices);            CPLFree(psFile->cur.psTxt->pszText);        }        CPLFree(psFile->cur.psTxt);    }    else if (psFile->eFileType == AVCFileRXP)    {        CPLFree(psFile->cur.psRxp);    }    else if (psFile->eFileType == AVCFileTABLE)    {        _AVCDestroyTableFields(psFile->hdr.psTableDef, psFile->cur.pasFields);        _AVCDestroyTableDef(psFile->hdr.psTableDef);    }    else    {        CPLError(CE_Failure, CPLE_IllegalArg,                 "Unsupported file type or invalid file handle!");    }    CPLFree(psFile);}/********************************************************************** *                          _AVCBinReadHeader() * * (This function is for internal library use... external calls should

⌨️ 快捷键说明

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