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

📄 ogrgeometryfactory.cpp

📁 用于读取TAB、MIF、SHP文件的类
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/****************************************************************************** * $Id: ogrgeometryfactory.cpp,v 1.34 2006/11/13 17:57:50 fwarmerdam Exp $ * * Project:  OpenGIS Simple Features Reference Implementation * Purpose:  Factory for converting geometry to and from well known binary *           format. * Author:   Frank Warmerdam, warmerdam@pobox.com * ****************************************************************************** * Copyright (c) 1999, Frank Warmerdam * * 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: ogrgeometryfactory.cpp,v $ * Revision 1.34  2006/11/13 17:57:50  fwarmerdam * Similar fix for multipoint and multipolygon. * * Revision 1.33  2006/11/13 17:55:49  fwarmerdam * Fixed memory leak in forceToMultiLineString. * * Revision 1.32  2006/09/05 15:54:54  fwarmerdam * Fixed docs on nBytes for createFromWkb(). * * Revision 1.31  2006/08/24 19:32:21  hobu * a little example for OGR_G_CreateFromWkt * * Revision 1.30  2006/07/07 00:05:46  mloskot * Removed GEOS C++ API usage from OGR and autotools. * * Revision 1.29  2006/01/31 02:38:37  fwarmerdam * Fixed corrupt data reporting. * * Revision 1.28  2005/10/21 15:58:34  fwarmerdam * use c++ casting for GEOSGeom * * Revision 1.27  2005/10/20 19:55:29  fwarmerdam * added GEOS C API support * * Revision 1.26  2005/08/05 20:28:55  fwarmerdam * pass nbytes in OGR_G_CreateFromWkb() * * Revision 1.25  2005/04/18 15:42:17  fwarmerdam * fix geos exception catching * * Revision 1.24  2005/02/22 17:17:30  hobu * typo in the haveGEOS() method * * Revision 1.23  2005/02/22 12:48:09  fwarmerdam * added OGRGeometryFactory::haveGEOS() * * Revision 1.22  2004/08/20 21:21:28  warmerda * added support for managing a persistent geos::GeometryFactory * * Revision 1.21  2004/07/10 04:54:01  warmerda * added GEOS methods * * Revision 1.20  2003/06/09 13:48:54  warmerda * added DB2 V7.2 byte order hack * * Revision 1.19  2003/06/04 13:50:54  warmerda * applied patch for IBM DB2 V7.2 WKB bug (with byte order flag) * * Revision 1.18  2003/04/28 15:39:33  warmerda * ryan added forceToMultiPolyline and forceToMultiPoint * * Revision 1.17  2003/03/31 15:55:42  danmo * Added C API function docs * * Revision 1.16  2003/03/06 20:29:27  warmerda * added GML import/export entry points * * Revision 1.15  2003/02/19 02:57:49  warmerda * added wkbLinearRing support * * Revision 1.14  2003/01/14 22:14:04  warmerda * added logic to force Geometry collection to multipolygon * * Revision 1.13  2003/01/08 22:04:11  warmerda * added forceToPolygon and forceToMultiPolygon methods * * Revision 1.12  2002/09/26 18:12:38  warmerda * added C support * * Revision 1.11  2002/09/11 13:47:17  warmerda * preliminary set of fixes for 3D WKB enum * * Revision 1.10  2001/11/01 16:56:08  warmerda * added createGeometry and destroyGeometry methods * * Revision 1.9  2001/07/18 05:03:05  warmerda * added CPL_CVSID * * Revision 1.8  2001/06/01 14:34:02  warmerda * added debugging of corrupt geometry * * Revision 1.7  1999/11/18 19:02:19  warmerda * expanded tabs * * Revision 1.6  1999/05/31 20:41:27  warmerda * Cleaned up functions substantially, by moving shared code to end of case * statements.  createFromWkt() now updates pointer to text to indicate how * much text was consumed.  Added multipoint, and multilinestring support. * * Revision 1.5  1999/05/31 11:05:08  warmerda * added some documentation * * Revision 1.4  1999/05/23 05:34:40  warmerda * added support for clone(), multipolygons and geometry collections * * Revision 1.3  1999/05/20 14:35:44  warmerda * added support for well known text format * * Revision 1.2  1999/03/30 21:21:43  warmerda * added linearring/polygon support * * Revision 1.1  1999/03/29 21:21:10  warmerda * New * */#include "ogr_geometry.h"#include "ogr_api.h"#include "ogr_p.h"#include <assert.h>#include "ogr_geos.h"CPL_CVSID("$Id: ogrgeometryfactory.cpp,v 1.34 2006/11/13 17:57:50 fwarmerdam Exp $");/************************************************************************//*                           createFromWkb()                            *//************************************************************************//** * Create a geometry object of the appropriate type from it's well known * binary representation. * * Note that if nBytes is passed as zero, no checking can be done on whether * the pabyData is sufficient.  This can result in a crash if the input * data is corrupt.  This function returns no indication of the number of * bytes from the data source actually used to represent the returned * geometry object.  Use OGRGeometry::WkbSize() on the returned geometry to * establish the number of bytes it required in WKB format. * * Also note that this is a static method, and that there * is no need to instantiate an OGRGeometryFactory object.   * * The C function OGR_G_CreateFromWkb() is the same as this method. * * @param pabyData pointer to the input BLOB data. * @param poSR pointer to the spatial reference to be assigned to the *             created geometry object.  This may be NULL. * @param ppoReturn the newly created geometry object will be assigned to the *                  indicated pointer on return.  This will be NULL in case *                  of failure. * @param nBytes the number of bytes available in pabyData, or -1 if it isn't *               known. * * @return OGRERR_NONE if all goes well, otherwise any of * OGRERR_NOT_ENOUGH_DATA, OGRERR_UNSUPPORTED_GEOMETRY_TYPE, or * OGRERR_CORRUPT_DATA may be returned. */OGRErr OGRGeometryFactory::createFromWkb(unsigned char *pabyData,                                         OGRSpatialReference * poSR,                                         OGRGeometry **ppoReturn,                                         int nBytes ){    OGRwkbGeometryType eGeometryType;    OGRwkbByteOrder eByteOrder;    OGRErr      eErr;    OGRGeometry *poGeom;    *ppoReturn = NULL;    if( nBytes < 5 && nBytes != -1 )        return OGRERR_NOT_ENOUGH_DATA;/* -------------------------------------------------------------------- *//*      Get the byte order byte.  The extra tests are to work around    *//*      bug sin the WKB of DB2 v7.2 as identified by Safe Software.     *//* -------------------------------------------------------------------- */    eByteOrder = DB2_V72_FIX_BYTE_ORDER((OGRwkbByteOrder) *pabyData);    if( eByteOrder != wkbXDR && eByteOrder != wkbNDR )    {        CPLDebug( "OGR",                   "OGRGeometryFactory::createFromWkb() - got corrupt data.\n"                  "%02X%02X%02X%02X%02X%02X%02X%02X\n",                   pabyData[0],                  pabyData[1],                  pabyData[2],                  pabyData[3],                  pabyData[4],                  pabyData[5],                  pabyData[6],                  pabyData[7],                  pabyData[8] );        return OGRERR_CORRUPT_DATA;    }/* -------------------------------------------------------------------- *//*      Get the geometry feature type.  For now we assume that          *//*      geometry type is between 0 and 255 so we only have to fetch     *//*      one byte.                                                       *//* -------------------------------------------------------------------- */    if( eByteOrder == wkbNDR )        eGeometryType = (OGRwkbGeometryType) pabyData[1];    else        eGeometryType = (OGRwkbGeometryType) pabyData[4];/* -------------------------------------------------------------------- *//*      Instantiate a geometry of the appropriate type, and             *//*      initialize from the input stream.                               *//* -------------------------------------------------------------------- */    poGeom = createGeometry( eGeometryType );        if( poGeom == NULL )        return OGRERR_UNSUPPORTED_GEOMETRY_TYPE;/* -------------------------------------------------------------------- *//*      Import from binary.                                             *//* -------------------------------------------------------------------- */    eErr = poGeom->importFromWkb( pabyData, nBytes );/* -------------------------------------------------------------------- *//*      Assign spatial reference system.                                *//* -------------------------------------------------------------------- */    if( eErr == OGRERR_NONE )    {        poGeom->assignSpatialReference( poSR );        *ppoReturn = poGeom;    }    else    {        delete poGeom;    }    return eErr;}/************************************************************************//*                        OGR_G_CreateFromWkb()                         *//************************************************************************//** * Create a geometry object of the appropriate type from it's well known * binary representation. * * Note that if nBytes is passed as zero, no checking can be done on whether * the pabyData is sufficient.  This can result in a crash if the input * data is corrupt.  This function returns no indication of the number of * bytes from the data source actually used to represent the returned * geometry object.  Use OGR_G_WkbSize() on the returned geometry to * establish the number of bytes it required in WKB format. * * The OGRGeometryFactory::createFromWkb() CPP method  is the same as this * function. * * @param pabyData pointer to the input BLOB data. * @param hSRS handle to the spatial reference to be assigned to the *             created geometry object.  This may be NULL. * @param phGeometry the newly created geometry object will  * be assigned to the indicated handle on return.  This will be NULL in case * of failure. * @param nBytes the number of bytes of data available in pabyData, or -1 * if it is not known, but assumed to be sufficient. * * @return OGRERR_NONE if all goes well, otherwise any of * OGRERR_NOT_ENOUGH_DATA, OGRERR_UNSUPPORTED_GEOMETRY_TYPE, or * OGRERR_CORRUPT_DATA may be returned. */OGRErr CPL_DLL OGR_G_CreateFromWkb( unsigned char *pabyData,                                     OGRSpatialReferenceH hSRS,                                    OGRGeometryH *phGeometry,                                     int nBytes ){    return OGRGeometryFactory::createFromWkb( pabyData,                                               (OGRSpatialReference *) hSRS,                                              (OGRGeometry **) phGeometry,                                              nBytes );}/************************************************************************//*                           createFromWkt()                            *//************************************************************************//** * Create a geometry object of the appropriate type from it's well known * text representation.

⌨️ 快捷键说明

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