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

📄 avc_misc.c

📁 用于读取TAB、MIF、SHP文件的类
💻 C
📖 第 1 页 / 共 2 页
字号:
/********************************************************************** * $Id: avc_misc.c,v 1.9 2005/06/03 03:49:59 daniel Exp $ * * Name:     avc_misc.c * Project:  Arc/Info vector coverage (AVC)  BIN<->E00 conversion library * Language: ANSI C * Purpose:  Misc. functions used by several parts of the library * 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_misc.c,v $ * Revision 1.9  2005/06/03 03:49:59  daniel * Update email address, website url, and copyright dates * * Revision 1.8  2004/08/31 21:00:20  warmerda * Applied Carl Anderson's patch to reduce the amount of stating while * trying to discover filename "case" on Unix in AVCAdjustCaseSensitiveFilename. * http://bugzilla.remotesensing.org/show_bug.cgi?id=314 * * Revision 1.7  2001/11/25 21:38:01  daniel * Remap '\\' to '/' in AVCAdjustCaseSensitiveFilename() on Unix. * * Revision 1.6  2001/11/25 21:15:23  daniel * Added hack (AVC_MAP_TYPE40_TO_DOUBLE) to map type 40 fields bigger than 8 * digits to double precision as we generate E00 output (bug599) * * Revision 1.5  2000/09/26 20:21:04  daniel * Added AVCCoverPC write * * Revision 1.4  2000/09/22 19:45:21  daniel * Switch to MIT-style license * * Revision 1.3  2000/01/10 02:53:21  daniel * Added AVCAdjustCaseSensitiveFilename() and AVCFileExists() * * Revision 1.2  1999/08/23 18:24:27  daniel * Fixed support for attribute fields of type 40 * * Revision 1.1  1999/05/11 02:34:46  daniel * Initial revision * **********************************************************************/#include "avc.h"/********************************************************************** *                          AVCE00ComputeRecSize() * * Computes the number of chars required to generate a E00 attribute * table record. * * Returns -1 on error, i.e. if it encounters an unsupported field type. **********************************************************************/int _AVCE00ComputeRecSize(int numFields, AVCFieldInfo *pasDef,                          GBool bMapType40ToDouble){    int i, nType, nBufSize=0;    /*-------------------------------------------------------------      * Add up the nbr of chars used by each field     *------------------------------------------------------------*/    for(i=0; i < numFields; i++)    {        nType = pasDef[i].nType1*10;        if (nType ==  AVC_FT_DATE || nType == AVC_FT_CHAR ||            nType == AVC_FT_FIXINT )        {            nBufSize += pasDef[i].nSize;        }        else if (nType == AVC_FT_BININT && pasDef[i].nSize == 4)            nBufSize += 11;        else if (nType == AVC_FT_BININT && pasDef[i].nSize == 2)            nBufSize += 6;        else if (bMapType40ToDouble &&                  nType == AVC_FT_FIXNUM && pasDef[i].nSize > 8)        {            /* See explanation in AVCE00GenTableHdr() about this hack to remap             * type 40 fields to double precision floats.             */            nBufSize += 24;  /* Remap to double float */        }        else if ((nType == AVC_FT_BINFLOAT && pasDef[i].nSize == 4) ||                  nType == AVC_FT_FIXNUM )            nBufSize += 14;        else if (nType == AVC_FT_BINFLOAT && pasDef[i].nSize == 8)            nBufSize += 24;        else        {            /*-----------------------------------------------------             * Hummm... unsupported field type...             *----------------------------------------------------*/            CPLError(CE_Failure, CPLE_NotSupported,                     "_AVCE00ComputeRecSize(): Unsupported field type: "                     "(type=%d, size=%d)",                     nType, pasDef[i].nSize);            return -1;        }    }    return nBufSize;}/********************************************************************** *                          _AVCDestroyTableFields() * * Release all memory associated with an array of AVCField structures. **********************************************************************/void _AVCDestroyTableFields(AVCTableDef *psTableDef, AVCField *pasFields){    int     i, nFieldType;    if (pasFields)    {        for(i=0; i<psTableDef->numFields; i++)        {            nFieldType = psTableDef->pasFieldDef[i].nType1*10;            if (nFieldType == AVC_FT_DATE   ||                nFieldType == AVC_FT_CHAR   ||                nFieldType == AVC_FT_FIXINT ||                nFieldType == AVC_FT_FIXNUM)            {                CPLFree(pasFields[i].pszStr);            }        }        CPLFree(pasFields);    }}/********************************************************************** *                          _AVCDestroyTableDef() * * Release all memory associated with a AVCTableDef structure. * **********************************************************************/void _AVCDestroyTableDef(AVCTableDef *psTableDef){    if (psTableDef)    {        CPLFree(psTableDef->pasFieldDef);        CPLFree(psTableDef);    }}/********************************************************************** *                          _AVCDupTableDef() * * Create a new copy of a AVCTableDef structure. **********************************************************************/AVCTableDef *_AVCDupTableDef(AVCTableDef *psSrcDef){    AVCTableDef *psNewDef;    if (psSrcDef == NULL)        return NULL;    psNewDef = (AVCTableDef*)CPLMalloc(1*sizeof(AVCTableDef));    memcpy(psNewDef, psSrcDef, sizeof(AVCTableDef));    psNewDef->pasFieldDef = (AVCFieldInfo*)CPLMalloc(psSrcDef->numFields*                                                     sizeof(AVCFieldInfo));    memcpy(psNewDef->pasFieldDef, psSrcDef->pasFieldDef,            psSrcDef->numFields*sizeof(AVCFieldInfo));   return psNewDef;}/********************************************************************** *                          AVCFileExists() * * Returns TRUE if a file with the specified name exists in the * specified directory. * * For now I simply try to fopen() the file ... would it be more * efficient to use stat() ??? **********************************************************************/GBool AVCFileExists(const char *pszPath, const char *pszName){    char        *pszBuf;    GBool       bFileExists = FALSE;    FILE        *fp;    pszBuf = (char*)CPLMalloc((strlen(pszPath)+strlen(pszName)+1)*                              sizeof(char));    sprintf(pszBuf, "%s%s", pszPath, pszName);    AVCAdjustCaseSensitiveFilename(pszBuf);    if ((fp = VSIFOpen(pszBuf, "rb")) != NULL)    {        bFileExists = TRUE;        VSIFClose(fp);    }    CPLFree(pszBuf);    return bFileExists;}/********************************************************************** *                     AVCAdjustCaseSensitiveFilename() * * Scan a filename and its path, adjust uppercase/lowercases if * necessary, and return a reference to that filename. * * This function works on the original buffer and returns a reference to it. * It does nothing on Windows systems where filenames are not case sensitive. * * NFW: It seems like this could be made somewhat more efficient by * getting a directory listing and doing a case insensitive search in  * that list rather than all this stating that can be very expensive * in some circumstances.  However, at least with Carl's fix this is * somewhat faster. * see: http://buzilla.remotesensing.org/show_bug.cgi?id=314 **********************************************************************/char *AVCAdjustCaseSensitiveFilename(char *pszFname){#ifdef _WIN32    /*-----------------------------------------------------------------     * Nothing to do on Windows     *----------------------------------------------------------------*/    return pszFname;#else    /*-----------------------------------------------------------------

⌨️ 快捷键说明

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