📄 ogrfeature.cpp
字号:
/****************************************************************************** * $Id: ogrfeature.cpp,v 1.46 2006/12/13 18:34:25 dron Exp $ * * Project: OpenGIS Simple Features Reference Implementation * Purpose: The OGRFeature class implementation. * Author: Frank Warmerdam, warmerda@home.com * ****************************************************************************** * Copyright (c) 1999, Les Technologies SoftMap Inc. * * 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: ogrfeature.cpp,v $ * Revision 1.46 2006/12/13 18:34:25 dron * Added SetStyleStringDirectly(), GetStyleTable() and SetStyleTableDirectly() * methods. * * Revision 1.45 2006/11/28 00:00:35 tamas * RFC 6: Geometry and Feature Style as OGR Special Fields * * Revision 1.44 2006/09/20 13:01:51 osemykin * Make the functions GetFieldAsStringList(...) and IsFieldSet(...) const * * Revision 1.43 2006/08/28 15:25:49 fwarmerdam * No need for null tests before delete! * * Revision 1.42 2006/08/28 15:24:40 fwarmerdam * Ensure SetGeometryDirectly() doesn't assume an existing geometry on feature. * * Revision 1.41 2006/08/28 15:17:57 mloskot * Added comment about NULL values passed to SetGeometry* functions. Added assert to GetNextFeature() of shape driver. * * Revision 1.40 2006/08/28 14:00:02 mloskot * Added stronger test of Shapefile reading failures, e.g. truncated files. * The problem was discovered by Tim Sutton and reported here https://svn.qgis.org/trac/ticket/200 * * Revision 1.39 2006/06/30 09:20:19 mloskot * Fixed null dates issue reported by Aaron Koning. Fixed zero-fill of year value in OGRFeature::GetFieldAsString. Added assertions and NULL pointer tests. * * Revision 1.38 2006/06/27 14:10:04 fwarmerdam * Always set style string even if just clearing in SetFrom(). * * Revision 1.37 2006/06/27 14:05:53 fwarmerdam * Support NULL setting a null style string. * * Revision 1.36 2006/04/02 18:25:59 fwarmerdam * added OFTDateTime, and OFTTime support * * Revision 1.35 2006/02/28 05:04:18 fwarmerdam * Reduced default GetFieldAsString() format to %.15g to avoid introducing * partially fake digits. * * Revision 1.34 2006/02/15 20:30:51 fwarmerdam * added date support * * Revision 1.33 2005/09/21 00:50:26 fwarmerdam * release OGRFeatureDefn on feature destruction * * Revision 1.32 2005/08/30 23:52:35 fwarmerdam * implement preliminary OFTBinary support * * Revision 1.31 2005/02/22 12:38:19 fwarmerdam * rename Equal/Intersect to Equals/Intersects * * Revision 1.30 2004/10/12 19:26:33 fwarmerdam * fixed up documentation on passing NULL to DumpReadable() * * Revision 1.29 2003/05/28 19:16:42 warmerda * fixed up argument names and stuff for docs * * Revision 1.28 2003/04/08 20:57:28 warmerda * added RemapFields on OGRFeature * * Revision 1.27 2003/04/03 23:39:11 danmo * Small updates to C API docs (Normand S.) * * Revision 1.26 2003/03/31 15:55:42 danmo * Added C API function docs * * Revision 1.25 2003/01/08 22:03:44 warmerda * added StealGeometry() method on OGRFeature * * Revision 1.24 2002/11/12 19:42:41 warmerda * copy style string in SetFrom() * * Revision 1.23 2002/09/26 18:12:38 warmerda * added C support * * Revision 1.22 2002/04/25 16:06:26 warmerda * don't copy style string if not set during clone * * Revision 1.21 2002/04/24 20:00:30 warmerda * fix clone to copy fid as well */#include "ogr_feature.h"#include "ogr_api.h"#include "ogr_p.h"CPL_CVSID("$Id: ogrfeature.cpp,v 1.46 2006/12/13 18:34:25 dron Exp $");/************************************************************************//* OGRFeature() *//************************************************************************//** * Constructor * * Note that the OGRFeature will increment the reference count of it's * defining OGRFeatureDefn. Destruction of the OGRFeatureDefn before * destruction of all OGRFeatures that depend on it is likely to result in * a crash. * * This method is the same as the C function OGR_F_Create(). * * @param poDefnIn feature class (layer) definition to which the feature will * adhere. */OGRFeature::OGRFeature( OGRFeatureDefn * poDefnIn ){ m_pszStyleString = NULL; m_poStyleTable = NULL; m_pszTmpFieldValue = NULL; poDefnIn->Reference(); poDefn = poDefnIn; nFID = OGRNullFID; poGeometry = NULL; // we should likely be initializing from the defaults, but this will // usually be a waste. pauFields = (OGRField *) CPLCalloc( poDefn->GetFieldCount(), sizeof(OGRField) ); for( int i = 0; i < poDefn->GetFieldCount(); i++ ) { pauFields[i].Set.nMarker1 = OGRUnsetMarker; pauFields[i].Set.nMarker2 = OGRUnsetMarker; }}/************************************************************************//* OGR_F_Create() *//************************************************************************//** * Feature factory. * * Note that the OGRFeature will increment the reference count of it's * defining OGRFeatureDefn. Destruction of the OGRFeatureDefn before * destruction of all OGRFeatures that depend on it is likely to result in * a crash. * * This function is the same as the C++ method OGRFeature::OGRFeature(). * * @param hDefn handle to the feature class (layer) definition to * which the feature will adhere. * * @return an handle to the new feature object with null fields and * no geometry. */OGRFeatureH OGR_F_Create( OGRFeatureDefnH hDefn ){ return (OGRFeatureH) new OGRFeature( (OGRFeatureDefn *) hDefn );}/************************************************************************//* ~OGRFeature() *//************************************************************************/OGRFeature::~OGRFeature(){ if( poGeometry != NULL ) delete poGeometry; for( int i = 0; i < poDefn->GetFieldCount(); i++ ) { OGRFieldDefn *poFDefn = poDefn->GetFieldDefn(i); if( !IsFieldSet(i) ) continue; switch( poFDefn->GetType() ) { case OFTString: if( pauFields[i].String != NULL ) VSIFree( pauFields[i].String ); break; case OFTBinary: if( pauFields[i].Binary.paData != NULL ) VSIFree( pauFields[i].Binary.paData ); break; case OFTStringList: CSLDestroy( pauFields[i].StringList.paList ); break; case OFTIntegerList: case OFTRealList: CPLFree( pauFields[i].IntegerList.paList ); break; default: // should add support for wide strings. break; } } poDefn->Release(); CPLFree( pauFields ); CPLFree(m_pszStyleString); CPLFree(m_pszTmpFieldValue);}/************************************************************************//* OGR_F_Destroy() *//************************************************************************//** * Destroy feature * * The feature is deleted, but within the context of the GDAL/OGR heap. * This is necessary when higher level applications use GDAL/OGR from a * DLL and they want to delete a feature created within the DLL. If the * delete is done in the calling application the memory will be freed onto * the application heap which is inappropriate. * * This function is the same as the C++ method OGRFeature::DestroyFeature(). * * @param hFeat handle to the feature to destroy. */void OGR_F_Destroy( OGRFeatureH hFeat ){ delete (OGRFeature *) hFeat;}/************************************************************************//* CreateFeature() *//************************************************************************//** * Feature factory. * * This is essentially a feature factory, useful for * applications creating features but wanting to ensure they * are created out of the OGR/GDAL heap. * * @param poDefn Feature definition defining schema. * * @return new feature object with null fields and no geometry. May be * deleted with delete. */OGRFeature *OGRFeature::CreateFeature( OGRFeatureDefn *poDefn ){ return new OGRFeature( poDefn );}/************************************************************************//* DestroyFeature() *//************************************************************************//** * Destroy feature * * The feature is deleted, but within the context of the GDAL/OGR heap. * This is necessary when higher level applications use GDAL/OGR from a * DLL and they want to delete a feature created within the DLL. If the * delete is done in the calling application the memory will be freed onto * the application heap which is inappropriate. * * This method is the same as the C function OGR_F_Destroy(). * * @param poFeature the feature to delete. */void OGRFeature::DestroyFeature( OGRFeature *poFeature ){ delete poFeature;}/************************************************************************//* GetDefnRef() *//************************************************************************//** * \fn OGRFeatureDefn *OGRFeature::GetDefnRef(); * * Fetch feature definition. * * This method is the same as the C function OGR_F_GetDefnRef(). * * @return a reference to the feature definition object. *//************************************************************************//* OGR_F_GetDefnRef() *//************************************************************************//** * Fetch feature definition. * * This function is the same as the C++ method OGRFeature::GetDefnRef(). * * @param hFeat handle to the feature to get the feature definition from. * * @return an handle to the feature definition object on which feature * depends. */OGRFeatureDefnH OGR_F_GetDefnRef( OGRFeatureH hFeat ){ return ((OGRFeature *) hFeat)->GetDefnRef();}/************************************************************************//* SetGeometryDirectly() *//************************************************************************//** * Set feature geometry. * * This method updates the features geometry, and operate exactly as * SetGeometry(), except that this method assumes ownership of the * passed geometry. * * This method is the same as the C function OGR_F_SetGeometryDirectly(). * * @param poGeomIn new geometry to apply to feature. Passing NULL value here * is correct and it will result in deallocation of currently assigned geometry * without assigning new one. * * @return OGRERR_NONE if successful, or OGR_UNSUPPORTED_GEOMETRY_TYPE if * the geometry type is illegal for the OGRFeatureDefn (checking not yet * implemented). */ OGRErr OGRFeature::SetGeometryDirectly( OGRGeometry * poGeomIn ){ delete poGeometry; poGeometry = poGeomIn; // I should be verifying that the geometry matches the defn's type. return OGRERR_NONE;}/************************************************************************//* OGR_F_SetGeometryDirectly() *//************************************************************************//** * Set feature geometry. * * This function updates the features geometry, and operate exactly as * SetGeometry(), except that this function assumes ownership of the * passed geometry. * * This function is the same as the C++ method * OGRFeature::SetGeometryDirectly. * * @param hFeat handle to the feature on which to apply the geometry. * @param hGeom handle to the new geometry to apply to feature. * * @return OGRERR_NONE if successful, or OGR_UNSUPPORTED_GEOMETRY_TYPE if * the geometry type is illegal for the OGRFeatureDefn (checking not yet * implemented). */ OGRErr OGR_F_SetGeometryDirectly( OGRFeatureH hFeat, OGRGeometryH hGeom ){ return ((OGRFeature *) hFeat)->SetGeometryDirectly((OGRGeometry *) hGeom);}/************************************************************************//* SetGeometry() *//************************************************************************//** * Set feature geometry.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -