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

📄 mitab_mapfile.cpp

📁 在linux环境下
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/********************************************************************** * $Id: mitab_mapfile.cpp,v 1.31 2004/09/22 13:07:58 fwarmerdam Exp $ * * Name:     mitab_mapfile.cpp * Project:  MapInfo TAB Read/Write library * Language: C++ * Purpose:  Implementation of the TABMAPFile class used to handle *           reading/writing of the .MAP files at the MapInfo object level * Author:   Daniel Morissette, dmorissette@dmsolutions.ca * ********************************************************************** * Copyright (c) 1999-2002, 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_mapfile.cpp,v $ * Revision 1.31  2004/09/22 13:07:58  fwarmerdam * fixed return value in LoadNextMatchingObjectBlock() per rso bug 615 * * Revision 1.30  2004/06/30 20:29:04  dmorissette * Fixed refs to old address danmo@videotron.ca * * Revision 1.29  2003/08/12 23:17:21  dmorissette * Added reading of v500+ coordsys affine params (Anthony D. - Encom) * * Revision 1.28  2002/08/27 17:18:43  warmerda * improved CPL error testing * * Revision 1.27  2002/07/30 13:54:12  julien * TABMAPFile::GetFeatureId() now return -1 when there's no geometry. (bug 169) * * Revision 1.26  2002/04/25 16:05:24  julien * Disabled the overflow warning in SetCoordFilter() by adding bIgnoreOverflow * variable in Coordsys2Int of the TABMAPFile class and TABMAPHeaderBlock class * * Revision 1.25  2002/03/26 19:27:43  daniel * Got rid of tabs in source * * Revision 1.24  2002/03/26 01:48:40  daniel * Added Multipoint object type (V650) * * Revision 1.23  2002/02/20 13:53:40  daniel * Prevent an infinite loop of calls to LoadNextMatchingObjectBlock() in * GetNextFeatureId() if no objects found in spatial index. * * Revision 1.22  2001/11/19 15:04:41  daniel * Prevent writing of coordinates outside of the +/-1e9 integer bounds. * * Revision 1.21  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.20  2001/09/18 20:33:52  warmerda * fixed case of spatial search on file with just one object block * * Revision 1.19  2001/09/14 03:23:55  warmerda * Substantial upgrade to support spatial queries using spatial indexes * * Revision 1.18  2001/03/15 03:57:51  daniel * Added implementation for new OGRLayer::GetExtent(), returning data MBR. * * Revision 1.17  2000/11/23 21:11:07  daniel * OOpps... VC++ didn't like the way TABPenDef, etc. were initialized * * Revision 1.16  2000/11/23 20:47:46  daniel * Use MI defaults for Pen, Brush, Font, Symbol instead of all zeros * * Revision 1.15  2000/11/22 04:03:10  daniel * Added warning when objects written outside of the +/-1e9 int. coord. range * * Revision 1.14  2000/11/15 04:13:49  daniel * Fixed writing of TABMAPToolBlock to allocate a new block when full * * Revision 1.13  2000/05/19 06:44:55  daniel * Modified generation of spatial index to split index nodes and produce a * more balanced tree. * * Revision 1.12  2000/03/13 05:58:01  daniel * Create 1024 bytes V500 .MAP header + limit m_nMaxCoordBufSize for V450 obj. * * Revision 1.11  2000/02/28 17:00:00  daniel * Added V450 object types * * Revision 1.10  2000/01/15 22:30:44  daniel * Switch to MIT/X-Consortium OpenSource license * * Revision 1.9  1999/12/19 17:37:52  daniel * Fixed memory leaks * * Revision 1.8  1999/11/14 04:43:31  daniel * Support dataset with no .MAP/.ID files * * Revision 1.7  1999/10/19 22:57:17  daniel * Create m_poCurObjBlock only when needed to avoid empty blocks in files * and problems with MBR in header block of files with only "NONE" geometries * * Revision 1.6  1999/10/06 13:17:46  daniel * Update m_nMaxCoordBufSize in header block * * Revision 1.5  1999/10/01 03:52:22  daniel * Avoid producing an unused block in the file when closing it. * * Revision 1.4  1999/09/26 14:59:36  daniel * Implemented write support * * Revision 1.3  1999/09/20 18:42:42  daniel * Use binary access to open file. * * Revision 1.2  1999/09/16 02:39:16  daniel * Completed read support for most feature types * * Revision 1.1  1999/07/12 04:18:24  daniel * Initial checkin * **********************************************************************/#include "mitab.h"/*===================================================================== *                      class TABMAPFile *====================================================================*//********************************************************************** *                   TABMAPFile::TABMAPFile() * * Constructor. **********************************************************************/TABMAPFile::TABMAPFile(){    m_nMinTABVersion = 300;    m_fp = NULL;    m_pszFname = NULL;    m_poHeader = NULL;    m_poSpIndex = NULL;    m_poSpIndexLeaf = NULL;    m_poCurObjBlock = NULL;    m_nCurObjPtr = -1;    m_nCurObjType = -1;    m_nCurObjId = -1;    m_poCurCoordBlock = NULL;    m_poToolDefTable = NULL;}/********************************************************************** *                   TABMAPFile::~TABMAPFile() * * Destructor. **********************************************************************/TABMAPFile::~TABMAPFile(){    Close();}/********************************************************************** *                   TABMAPFile::Open() * * Open a .MAP file, and initialize the structures to be ready to read * objects from it. * * Since .MAP and .ID files are optional, you can set bNoErrorMsg=TRUE to * disable the error message and receive an return value of 1 if file  * cannot be opened.   * In this case, only the methods MoveToObjId() and GetCurObjType() can  * be used.  They will behave as if the .ID file contained only null * references, so all object will look like they have NONE geometries. * * Returns 0 on success, -1 on error. **********************************************************************/int TABMAPFile::Open(const char *pszFname, const char *pszAccess,                     GBool bNoErrorMsg /* = FALSE */){    FILE        *fp=NULL;    TABRawBinBlock *poBlock=NULL;    if (m_fp)    {        CPLError(CE_Failure, CPLE_FileIO,                 "Open() failed: object already contains an open file");        return -1;    }    m_nMinTABVersion = 300;    m_fp = NULL;    m_poHeader = NULL;    m_poIdIndex = NULL;    m_poSpIndex = NULL;    m_poToolDefTable = NULL;    /*-----------------------------------------------------------------     * Validate access mode and make sure we use binary access.     *----------------------------------------------------------------*/    if (EQUALN(pszAccess, "r", 1))    {        m_eAccessMode = TABRead;        pszAccess = "rb";    }    else if (EQUALN(pszAccess, "w", 1))    {        m_eAccessMode = TABWrite;        pszAccess = "wb+";    }    else    {        CPLError(CE_Failure, CPLE_FileIO,                 "Open() failed: access mode \"%s\" not supported", pszAccess);        return -1;    }    /*-----------------------------------------------------------------     * Open file     *----------------------------------------------------------------*/    fp = VSIFOpen(pszFname, pszAccess);    m_oBlockManager.Reset();    if (fp != NULL && m_eAccessMode == TABRead)    {        /*-----------------------------------------------------------------         * Read access: try to read header block         * First try with a 512 bytes block to check the .map version.         * If it's version 500 or more then read again a 1024 bytes block         *----------------------------------------------------------------*/        poBlock = TABCreateMAPBlockFromFile(fp, 0, 512);        if (poBlock && poBlock->GetBlockClass() == TABMAP_HEADER_BLOCK &&            ((TABMAPHeaderBlock*)poBlock)->m_nMAPVersionNumber >= 500)        {            // Version 500 or higher.  Read 1024 bytes block instead of 512            delete poBlock;            poBlock = TABCreateMAPBlockFromFile(fp, 0, 1024);        }        if (poBlock==NULL || poBlock->GetBlockClass() != TABMAP_HEADER_BLOCK)        {            if (poBlock)                delete poBlock;            poBlock = NULL;            VSIFClose(fp);            CPLError(CE_Failure, CPLE_FileIO,                "Open() failed: %s does not appear to be a valid .MAP file",                     pszFname);            return -1;        }    }    else if (fp != NULL && m_eAccessMode == TABWrite)    {        /*-----------------------------------------------------------------         * Write access: create a new header block         * .MAP files of Version 500 and up appear to have a 1024 bytes         * header.  The last 512 bytes are usually all zeros.         *----------------------------------------------------------------*/        poBlock = new TABMAPHeaderBlock(m_eAccessMode);        poBlock->InitNewBlock(fp, 1024, m_oBlockManager.AllocNewBlock() );        // Alloc a second 512 bytes of space since oBlockManager deals         // with 512 bytes blocks.        m_oBlockManager.AllocNewBlock();     }    else if (bNoErrorMsg)    {        /*-----------------------------------------------------------------         * .MAP does not exist... produce no error message, but set         * the class members so that MoveToObjId() and GetCurObjType()         * can be used to return only NONE geometries.         *----------------------------------------------------------------*/        m_fp = NULL;        m_nCurObjType = TAB_GEOM_NONE;        /* Create a false header block that will return default         * values for projection and coordsys conversion stuff...         */        m_poHeader = new TABMAPHeaderBlock(m_eAccessMode);        m_poHeader->InitNewBlock(NULL, 512, 0 );        return 1;    }    else    {        CPLError(CE_Failure, CPLE_FileIO,                 "Open() failed for %s", pszFname);        return -1;    }    /*-----------------------------------------------------------------     * File appears to be valid... set the various class members     *----------------------------------------------------------------*/    m_fp = fp;    m_poHeader = (TABMAPHeaderBlock*)poBlock;    m_pszFname = CPLStrdup(pszFname);    /*-----------------------------------------------------------------     * Create a TABMAPObjectBlock, in READ mode only.     *     * In WRITE mode, the object block will be created only when needed.     * We do not create the object block in the open() call because     * files that contained only "NONE" geometries ended up with empty     * object and spatial index blocks.     *----------------------------------------------------------------*/    if (m_eAccessMode == TABRead)    {        m_poCurObjBlock = new TABMAPObjectBlock(m_eAccessMode);        m_poCurObjBlock->InitNewBlock(m_fp, 512);    }    else    {        m_poCurObjBlock = NULL;    }    /*-----------------------------------------------------------------     * Open associated .ID (object id index) file     *----------------------------------------------------------------*/    m_poIdIndex = new TABIDFile;    if (m_poIdIndex->Open(pszFname, pszAccess) != 0)    {        // Failed... an error has already been reported        Close();        return -1;    }    /*-----------------------------------------------------------------     * Default Coord filter is the MBR of the whole file     * This is currently unused but could eventually be used to handle     * spatial filters more efficiently.     *----------------------------------------------------------------*/    if (m_eAccessMode == TABRead)    {        ResetCoordFilter();    }    /*-----------------------------------------------------------------     * We could scan a file through its quad tree index... but we don't!     *     * In read mode, we just ignore the spatial index.     *     * In write mode the index is created and maintained as new object     * blocks are added inside CommitObjBlock().     *----------------------------------------------------------------*/    m_poSpIndex = NULL;    /*-----------------------------------------------------------------     * Initialization of the Drawing Tools table will be done automatically     * as Read/Write calls are done later.     *----------------------------------------------------------------*/    m_poToolDefTable = NULL;

⌨️ 快捷键说明

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