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

📄 mitab_tabfile.cpp

📁 在linux环境下
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/********************************************************************** * $Id: mitab_tabfile.cpp,v 1.56 2004/09/17 19:26:23 fwarmerdam Exp $ * * Name:     mitab_tabfile.cpp * Project:  MapInfo TAB Read/Write library * Language: C++ * Purpose:  Implementation of the TABFile class, the main class of the lib. *           To be used by external programs to handle reading/writing of *           features from/to TAB datasets. * Author:   Daniel Morissette, dmorissette@dmsolutions.ca * ********************************************************************** * Copyright (c) 1999-2003, 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: mitab_tabfile.cpp,v $ * Revision 1.56  2004/09/17 19:26:23  fwarmerdam * Several fixes in error/failure cases in TABFile::Open() care of * Stephen Cheesman of GeoSoft. * * Revision 1.55  2004/06/30 20:29:04  dmorissette * Fixed refs to old address danmo@videotron.ca * * Revision 1.54  2004/05/20 13:49:46  fwarmerdam * Removed special bailout for m_poMAPFile == NULL in TABFile::Close(). * It is important to cleanup other used memory. * * Revision 1.53  2003/01/18 20:22:39  daniel * Fixed leak of TABMAPObjHdr when writing NONE geometries in SetFeature() * * Revision 1.52  2002/09/23 13:15:35  warmerda * fixed memory leak in SetMIFCoordSys * * Revision 1.51  2002/09/23 13:06:21  warmerda * ensure pre-created m_poDefn is referenced properly * * Revision 1.50  2002/08/27 17:19:22  warmerda * auto-add FID column if there aren't any columns * * Revision 1.49  2002/03/26 01:48:40  daniel * Added Multipoint object type (V650) * * Revision 1.48  2001/11/19 15:08:50  daniel * Handle the case of TAB_GEOM_NONE with the new TABMAPObjHdr classes. * * Revision 1.47  2001/11/17 21:54:06  daniel * Made several changes in order to support writing objects in 16 bits  * coordinate format. New TABMAPObjHdr-derived classes are used to hold  * object info in mem until block is full. * * Revision 1.46  2001/09/19 21:39:31  warmerda * improved capabilities logic * * Revision 1.45  2001/09/14 19:14:43  warmerda * added attribute query support * * Revision 1.44  2001/09/14 03:23:55  warmerda * Substantial upgrade to support spatial queries using spatial indexes * * Revision 1.43  2001/03/15 03:57:51  daniel * Added implementation for new OGRLayer::GetExtent(), returning data MBR. * * Revision 1.42  2001/03/09 04:14:19  daniel * Fixed problem creating new files with mixed case extensions (e.g. ".Tab") * * Revision 1.41  2001/01/23 21:23:42  daniel * Added projection bounds lookup table, called from TABFile::SetProjInfo() * * Revision 1.40  2001/01/22 16:03:58  warmerda * expanded tabs * * Revision 1.39  2000/12/15 05:32:31  daniel * Handle table type LINKED the same way as table type NATIVE. * Make sure max char field width is 254 in AddFieldNative(). * * Revision 1.38  2000/10/18 03:53:16  daniel * GetBounds() now calculates bounds based on +/- 1e9 integer coordinates limit * * Revision 1.37  2000/09/20 18:32:02  daniel * Accept "FORMAT: DBF" in version 100 .tab headers * * Revision 1.36  2000/09/07 23:32:13  daniel * Added RecordDeletedFlag to TABFeature with get/set methods * * Revision 1.35  2000/07/04 01:50:02  warmerda * removed unprotected debugging printf. * * Revision 1.34  2000/06/28 00:31:05  warmerda * Try to set geometry type on OGRFeatureDefn by feature count * * Revision 1.33  2000/03/19 23:22:43  daniel * Fixed test on return value of SetSpatialRef() in SetMIFCoordSys() * * Revision 1.32  2000/02/28 17:11:14  daniel * Support indexed fields and new V450 object types * * Revision 1.31  2000/02/18 20:45:56  daniel * Validate field names on write * * Revision 1.30  2000/01/26 18:18:01  warmerda * fixed capabilities test * * Revision 1.29  2000/01/18 23:13:05  daniel * Added missing m_poDefn->Reference() * * Revision 1.28  2000/01/18 22:14:36  daniel * Fixed compile warnings * * Revision 1.27  2000/01/16 19:08:49  daniel * Added support for reading 'Table Type DBF' tables * * ... * * Revision 1.1  1999/07/12 04:18:25  daniel * Initial checkin * **********************************************************************/#include "mitab.h"#include "mitab_utils.h"#include <ctype.h>      /* isspace() *//*===================================================================== *                      class TABFile *====================================================================*//********************************************************************** *                   TABFile::TABFile() * * Constructor. **********************************************************************/TABFile::TABFile(){    m_eAccessMode = TABRead;    m_pszFname = NULL;    m_papszTABFile = NULL;    m_nVersion = 300;    m_pszCharset = NULL;    m_eTableType = TABTableNative;    m_poMAPFile = NULL;    m_poDATFile = NULL;    m_poINDFile = NULL;    m_poDefn = NULL;    m_poSpatialRef = NULL;    m_poCurFeature = NULL;    m_nCurFeatureId = 0;    m_nLastFeatureId = 0;    m_panIndexNo = NULL;    bUseSpatialTraversal = FALSE;}/********************************************************************** *                   TABFile::~TABFile() * * Destructor. **********************************************************************/TABFile::~TABFile(){    Close();}/************************************************************************//*                          GetFeatureCount()                           *//************************************************************************/int TABFile::GetFeatureCount (int bForce){        if( m_poFilterGeom != NULL || m_poAttrQuery != NULL )        return OGRLayer::GetFeatureCount( bForce );    else        return m_nLastFeatureId;}/************************************************************************//*                            ResetReading()                            *//************************************************************************/void TABFile::ResetReading(){    m_nCurFeatureId = 0;    if( m_poMAPFile != NULL )        m_poMAPFile->ResetReading();/* -------------------------------------------------------------------- *//*      Decide whether to operate in spatial traversal mode or not,     *//*      and ensure the current spatial filter is applied to the map     *//*      file object.                                                    *//* -------------------------------------------------------------------- */    if( m_poMAPFile )    {        bUseSpatialTraversal = FALSE;            m_poMAPFile->ResetCoordFilter();        if( m_poFilterGeom != NULL )        {            OGREnvelope  sEnvelope;            TABVertex sMin, sMax;            TABMAPHeaderBlock *poHeader;                poHeader = m_poMAPFile->GetHeaderBlock();            m_poFilterGeom->getEnvelope( &sEnvelope );            m_poMAPFile->GetCoordFilter( sMin, sMax );            if( sEnvelope.MinX > sMin.x                 || sEnvelope.MinY > sMin.y                || sEnvelope.MaxX < sMax.x                || sEnvelope.MaxY < sMax.y )            {                bUseSpatialTraversal = TRUE;                sMin.x = sEnvelope.MinX;                sMin.y = sEnvelope.MinY;                sMax.x = sEnvelope.MaxX;                sMax.y = sEnvelope.MaxY;                m_poMAPFile->SetCoordFilter( sMin, sMax );            }        }    }}/********************************************************************** *                   TABFile::Open() * * Open a .TAB dataset and the associated files, and initialize the  * structures to be ready to read features from (or write to) it. * * Supported access modes are "r" (read-only) and "w" (create new dataset). * * Set bTestOpenNoError=TRUE to silently return -1 with no error message * if the file cannot be opened.  This is intended to be used in the * context of a TestOpen() function.  The default value is FALSE which * means that an error is reported if the file cannot be opened. * * Note that dataset extents will have to be set using SetBounds() before * any feature can be written to a newly created dataset. * * In read mode, a valid dataset must have at least a .TAB and a .DAT file. * The .MAP and .ID files are optional and if they do not exist then * all features will be returned with NONE geometry. * * Returns 0 on success, -1 on error. **********************************************************************/int TABFile::Open(const char *pszFname, const char *pszAccess,                  GBool bTestOpenNoError /*=FALSE*/ ){    char *pszTmpFname = NULL;    int nFnameLen = 0;    CPLErrorReset();       if (m_poMAPFile)    {        CPLError(CE_Failure, CPLE_AssertionFailed,                 "Open() failed: object already contains an open file");        return -1;    }    /*-----------------------------------------------------------------     * Validate access mode     *----------------------------------------------------------------*/    if (EQUALN(pszAccess, "r", 1))    {        m_eAccessMode = TABRead;        pszAccess = "rb";    }    else if (EQUALN(pszAccess, "w", 1))    {        m_eAccessMode = TABWrite;        pszAccess = "wb";    }    else    {        if (!bTestOpenNoError)            CPLError(CE_Failure, CPLE_FileIO,                 "Open() failed: access mode \"%s\" not supported", pszAccess);        else            CPLErrorReset();        return -1;    }    /*-----------------------------------------------------------------     * Make sure filename has a .TAB extension...      *----------------------------------------------------------------*/    m_pszFname = CPLStrdup(pszFname);    nFnameLen = strlen(m_pszFname);    if (nFnameLen > 4 && (strcmp(m_pszFname+nFnameLen-4, ".TAB")==0 ||                     strcmp(m_pszFname+nFnameLen-4, ".MAP")==0 ||                     strcmp(m_pszFname+nFnameLen-4, ".DAT")==0 ) )        strcpy(m_pszFname+nFnameLen-4, ".TAB");    else if (nFnameLen > 4 && (EQUAL(m_pszFname+nFnameLen-4, ".tab") ||                               EQUAL(m_pszFname+nFnameLen-4, ".map") ||                               EQUAL(m_pszFname+nFnameLen-4, ".dat") ) )        strcpy(m_pszFname+nFnameLen-4, ".tab");    else    {        if (!bTestOpenNoError)            CPLError(CE_Failure, CPLE_FileIO,                     "Open() failed for %s: invalid filename extension",                     m_pszFname);        else            CPLErrorReset();        CPLFree(m_pszFname);        return -1;    }    pszTmpFname = CPLStrdup(m_pszFname);#ifndef _WIN32    /*-----------------------------------------------------------------     * On Unix, make sure extension uses the right cases     * We do it even for write access because if a file with the same     * extension already exists we want to overwrite it.     *----------------------------------------------------------------*/    TABAdjustFilenameExtension(m_pszFname);#endif    /*-----------------------------------------------------------------     * Handle .TAB file... depends on access mode.     *----------------------------------------------------------------*/    if (m_eAccessMode == TABRead)    {        /*-------------------------------------------------------------

⌨️ 快捷键说明

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