📄 ogrfeature.cpp
字号:
/****************************************************************************** * $Id: ogrfeature.cpp,v 1.29 2003/05/28 19:16:42 warmerda 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.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 * * Revision 1.20 2001/11/09 15:02:40 warmerda * dump render style * * Revision 1.19 2001/11/01 16:54:16 warmerda * added DestroyFeature * * Revision 1.18 2001/07/18 05:03:05 warmerda * added CPL_CVSID * * Revision 1.17 2001/06/01 14:32:27 warmerda * added CreateFeature factory method * * Revision 1.16 2001/02/06 14:14:09 warmerda * fixed up documentation * * Revision 1.15 2000/08/25 20:17:34 danmo * Init m_poStyleTable=NULL in constructor * * Revision 1.14 2000/08/18 21:26:53 svillene * Add representation * * Revision 1.13 2000/06/09 21:15:39 warmerda * fixed field copying * * Revision 1.12 1999/11/26 03:05:38 warmerda * added unset field support */#include "ogr_feature.h"#include "ogr_api.h"#include "ogr_p.h"CPL_CVSID("$Id: ogrfeature.cpp,v 1.29 2003/05/28 19:16:42 warmerda 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; 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 CPP 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 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; } } CPLFree( pauFields ); CPLFree(m_pszStyleString); if (poDefn->Dereference() == 0) delete poDefn;}/************************************************************************//* 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 CPP 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 CPP 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. * * @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 ){ if( poGeometry != NULL ) 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 CPP 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. * * This method updates the features geometry, and operate exactly as * SetGeometryDirectly(), except that this method does not assume ownership * of the passed geometry, but instead makes a copy of it. * * This method is the same as the C function OGR_F_SetGeometry(). * * @param poGeomIn 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 OGRFeature::SetGeometry( OGRGeometry * poGeomIn ){ if( poGeometry != NULL ) delete poGeometry; if( poGeomIn != NULL ) poGeometry = poGeomIn->clone(); else poGeometry = NULL; // I should be verifying that the geometry matches the defn's type. return OGRERR_NONE;}/************************************************************************//* OGR_F_SetGeometry() *//************************************************************************//** * Set feature geometry. * * This function updates the features geometry, and operate exactly as * SetGeometryDirectly(), except that this function does not assume ownership * of the passed geometry, but instead makes a copy of it.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -