📄 ogrlayer.cpp
字号:
/****************************************************************************** * $Id: ogrlayer.cpp,v 1.18 2003/05/28 19:18:04 warmerda Exp $ * * Project: OpenGIS Simple Features Reference Implementation * Purpose: The generic portions of the OGRSFLayer class. * Author: Frank Warmerdam, warmerdam@pobox.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: ogrlayer.cpp,v $ * Revision 1.18 2003/05/28 19:18:04 warmerda * fixup argument names for docs * * Revision 1.17 2003/05/21 04:54:29 warmerda * avoid warnings about unused formal parameters and possibly uninit variables * * Revision 1.16 2003/04/22 19:36:04 warmerda * Added SyncToDisk * * Revision 1.15 2003/03/19 20:35:05 warmerda * added reference counting support * * Revision 1.14 2003/03/04 17:45:16 warmerda * Ensure m_poAttrIndex is initialized. * * Revision 1.13 2003/03/04 05:48:05 warmerda * added index initialize support * * Revision 1.12 2002/09/26 18:16:19 warmerda * added C entry points * * Revision 1.11 2002/03/27 21:25:25 warmerda * added working default implementation of GetFeature() * * Revision 1.10 2001/11/15 21:19:21 warmerda * added transaction semantics * * Revision 1.9 2001/10/02 14:16:21 warmerda * fix handling of case where a query is being cleared * * Revision 1.8 2001/07/19 18:26:42 warmerda * expand tabs * * Revision 1.7 2001/07/18 04:55:16 warmerda * added CPL_CSVID * * Revision 1.6 2001/06/19 15:53:49 warmerda * Added attribute query support * * Revision 1.5 2001/03/15 04:01:43 danmo * Added OGRLayer::GetExtent() * * Revision 1.4 1999/11/04 21:10:30 warmerda * Added CreateField() method. * * Revision 1.3 1999/07/27 00:51:39 warmerda * added GetInfo(), fixed args for other methods * * Revision 1.2 1999/07/26 13:59:06 warmerda * added feature writing api * * Revision 1.1 1999/07/08 20:05:13 warmerda * New * */#include "ogrsf_frmts.h"#include "ogr_api.h"#include "ogr_p.h"#include "ogr_attrind.h"CPL_CVSID("$Id: ogrlayer.cpp,v 1.18 2003/05/28 19:18:04 warmerda Exp $");/************************************************************************//* OGRLayer() *//************************************************************************/OGRLayer::OGRLayer(){ m_poStyleTable = NULL; m_poAttrQuery = NULL; m_poAttrIndex = NULL; m_nRefCount = 0;}/************************************************************************//* ~OGRLayer() *//************************************************************************/OGRLayer::~OGRLayer(){ if( m_poAttrIndex != NULL ) { delete m_poAttrIndex; m_poAttrIndex = NULL; } if( m_poAttrQuery != NULL ) { delete m_poAttrQuery; m_poAttrQuery = NULL; }}/************************************************************************//* Reference() *//************************************************************************/int OGRLayer::Reference(){ return ++m_nRefCount;}/************************************************************************//* OGR_L_Reference() *//************************************************************************/int OGR_L_Reference( OGRLayerH hLayer ){ return ((OGRLayer *) hLayer)->Reference();}/************************************************************************//* Dereference() *//************************************************************************/int OGRLayer::Dereference(){ return --m_nRefCount;}/************************************************************************//* OGR_L_Dereference() *//************************************************************************/int OGR_L_Dereference( OGRLayerH hLayer ){ return ((OGRLayer *) hLayer)->Dereference();}/************************************************************************//* GetRefCount() *//************************************************************************/int OGRLayer::GetRefCount() const{ return m_nRefCount;}/************************************************************************//* OGR_L_GetRefCount() *//************************************************************************/int OGR_L_GetRefCount( OGRLayerH hLayer ){ return ((OGRLayer *) hLayer)->GetRefCount();}/************************************************************************//* GetFeatureCount() *//************************************************************************/int OGRLayer::GetFeatureCount( int bForce ){ OGRFeature *poFeature; int nFeatureCount = 0; if( !bForce ) return -1; ResetReading(); while( (poFeature = GetNextFeature()) != NULL ) { nFeatureCount++; delete poFeature; } ResetReading(); return nFeatureCount;}/************************************************************************//* OGR_L_GetFeatureCount() *//************************************************************************/int OGR_L_GetFeatureCount( OGRLayerH hLayer, int bForce ){ return ((OGRLayer *) hLayer)->GetFeatureCount(bForce);}/************************************************************************//* GetExtent() *//************************************************************************/OGRErr OGRLayer::GetExtent(OGREnvelope *psExtent, int bForce ){ OGRFeature *poFeature; OGREnvelope oEnv; GBool bExtentSet = FALSE; if( !bForce ) return OGRERR_FAILURE; ResetReading(); while( (poFeature = GetNextFeature()) != NULL ) { OGRGeometry *poGeom = poFeature->GetGeometryRef(); if (poGeom && !bExtentSet) { poGeom->getEnvelope(psExtent); bExtentSet = TRUE; } else if (poGeom) { poGeom->getEnvelope(&oEnv); if (oEnv.MinX < psExtent->MinX) psExtent->MinX = oEnv.MinX; if (oEnv.MinY < psExtent->MinY) psExtent->MinY = oEnv.MinY; if (oEnv.MaxX > psExtent->MaxX) psExtent->MaxX = oEnv.MaxX; if (oEnv.MaxY > psExtent->MaxY) psExtent->MaxY = oEnv.MaxY; } delete poFeature; } ResetReading(); return (bExtentSet ? OGRERR_NONE : OGRERR_FAILURE);}/************************************************************************//* OGR_L_GetExtent() *//************************************************************************/OGRErr OGR_L_GetExtent( OGRLayerH hLayer, OGREnvelope *psExtent, int bForce ){ return ((OGRLayer *) hLayer)->GetExtent( psExtent, bForce );}/************************************************************************//* SetAttributeFilter() *//************************************************************************/OGRErr OGRLayer::SetAttributeFilter( const char *pszQuery ){/* -------------------------------------------------------------------- *//* Are we just clearing any existing query? *//* -------------------------------------------------------------------- */ if( pszQuery == NULL || strlen(pszQuery) == 0 ) { if( m_poAttrQuery ) { delete m_poAttrQuery; m_poAttrQuery = NULL; ResetReading(); } return OGRERR_NONE; }/* -------------------------------------------------------------------- *//* Or are we installing a new query? *//* -------------------------------------------------------------------- */ OGRErr eErr; if( !m_poAttrQuery ) m_poAttrQuery = new OGRFeatureQuery(); eErr = m_poAttrQuery->Compile( GetLayerDefn(), pszQuery ); if( eErr != OGRERR_NONE ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -