📄 ogrfmelayercached.cpp
字号:
/****************************************************************************** * $Id: ogrfmelayercached.cpp,v 1.4 2005/02/22 12:57:19 fwarmerdam Exp $ * * Project: FMEObjects Translator * Purpose: Implementation of the OGRFMELayerCached class. This is the * class implementing behaviour for layers that are built into a * temporary spatial cache (as opposed to live read database). * Author: Frank Warmerdam, warmerdam@pobox.com * ****************************************************************************** * Copyright (c) 1999, 2001 Safe Software Inc. * All Rights Reserved * * This software may not be copied or reproduced, in all or in part, * without the prior written consent of Safe Software Inc. * * The entire risk as to the results and performance of the software, * supporting text and other information contained in this file * (collectively called the "Software") is with the user. Although * Safe Software Incorporated has used considerable efforts in preparing * the Software, Safe Software Incorporated does not warrant the * accuracy or completeness of the Software. In no event will Safe Software * Incorporated be liable for damages, including loss of profits or * consequential damages, arising out of the use of the Software. ****************************************************************************** * * $Log: ogrfmelayercached.cpp,v $ * Revision 1.4 2005/02/22 12:57:19 fwarmerdam * use OGRLayer base spatial filter support * * Revision 1.3 2005/02/02 20:54:26 fwarmerdam * track m_nFeaturesRead * * Revision 1.2 2002/11/08 21:20:58 warmerda * ensure a query is issued if resetreading never called * * Revision 1.1 2002/05/24 06:23:57 warmerda * New * * Revision 1.7 2002/05/24 06:17:01 warmerda * clean up dependencies on strimp.h, and fme2ogrspatialref func * * Revision 1.6 2002/05/24 03:59:56 warmerda * added support for cache index and related stuff * * Revision 1.5 2002/05/06 14:06:37 warmerda * override coordsys from cached features if needed * * Revision 1.4 2002/04/10 20:10:38 warmerda * Added support for getting geometry extents * * Revision 1.3 2001/11/19 22:12:14 warmerda * avoid small memory leak * * Revision 1.2 2001/11/01 21:52:39 warmerda * added mutex to protect access to session * * Revision 1.1 2001/09/07 15:53:39 warmerda * New * */#include "fme2ogr.h"#include "cpl_conv.h"#include "cpl_string.h"CPL_CVSID("$Id: ogrfmelayercached.cpp,v 1.4 2005/02/22 12:57:19 fwarmerdam Exp $");/************************************************************************//* OGRFMELayerCached() *//************************************************************************/OGRFMELayerCached::OGRFMELayerCached( OGRFMEDataSource *poDSIn ) : OGRFMELayer( poDSIn ){ nPreviousFeature = -1; pszIndexBase = NULL; poIndex = NULL; memset( &sExtents, 0, sizeof(sExtents) ); bQueryActive = FALSE;}/************************************************************************//* ~OGRFMELayerCached() *//************************************************************************/OGRFMELayerCached::~OGRFMELayerCached(){ CPLFree( pszIndexBase ); if( poIndex != NULL ) {#ifdef SUPPORT_PERSISTENT_CACHE poIndex->close( FME_FALSE );#else poIndex->close( FME_TRUE );#endif poDS->GetFMESession()->destroySpatialIndex( poIndex ); }}/************************************************************************//* AssignIndex() *//* *//* Assign spatial index .. spatial index is opened for read *//* access. *//************************************************************************/int OGRFMELayerCached::AssignIndex( const char *pszBase, const OGREnvelope *psExtents, OGRSpatialReference *poSRS ) { CPLAssert( poIndex == NULL ); pszIndexBase = CPLStrdup( pszBase ); poIndex = poDS->GetFMESession()->createSpatialIndex( pszBase, "READ", NULL ); if( poIndex == NULL ) return FALSE; if( poIndex->open() != 0 ) { poDS->GetFMESession()->destroySpatialIndex( poIndex ); poIndex = NULL; return FALSE; } if( psExtents != NULL ) sExtents = *psExtents; if( poSRS != NULL ) { if( poSpatialRef != NULL ) delete poSpatialRef; poSpatialRef = poSRS; } return TRUE;}/************************************************************************//* TestCapability() *//************************************************************************/int OGRFMELayerCached::TestCapability( const char * pszCap ){ if( EQUAL(pszCap,OLCRandomRead) ) return FALSE; else if( EQUAL(pszCap,OLCSequentialWrite) || EQUAL(pszCap,OLCRandomWrite) ) return FALSE; else if( EQUAL(pszCap,OLCFastFeatureCount) ) return TRUE; else if( EQUAL(pszCap,OLCFastSpatialFilter) ) return TRUE; else if( EQUAL(pszCap,OLCFastGetExtent) ) return TRUE; else return FALSE;}/************************************************************************//* ReadNextIndexFeature() *//************************************************************************/OGRFeature *OGRFMELayerCached::ReadNextIndexFeature(){ OGRFeature *poOGRFeature = NULL; FME_Boolean endOfQuery; if( poIndex == NULL ) return NULL; if( !bQueryActive ) ResetReading(); poDS->AcquireSession(); if( poIndex->fetch( *poFMEFeature, endOfQuery ) == 0 && !endOfQuery ) { poOGRFeature = poDS->ProcessFeature( this, poFMEFeature ); if( poOGRFeature != NULL ) { poOGRFeature->SetFID( ++nPreviousFeature ); m_nFeaturesRead++; } } poDS->ReleaseSession(); return poOGRFeature;}/************************************************************************//* GetNextFeature() *//************************************************************************/OGRFeature *OGRFMELayerCached::GetNextFeature(){ OGRFeature *poFeature; while( TRUE ) { poFeature = ReadNextIndexFeature(); if( poFeature != NULL ) nPreviousFeature = poFeature->GetFID(); else break; if( m_poAttrQuery == NULL || poIndex == NULL || m_poAttrQuery->Evaluate( poFeature ) ) break; delete poFeature; } return poFeature;}/************************************************************************//* ResetReading() *//************************************************************************/ void OGRFMELayerCached::ResetReading(){ nPreviousFeature = -1; if( poIndex == NULL ) { CPLAssert( FALSE ); return; } poDS->AcquireSession(); if( m_poFilterGeom == NULL ) { poIndex->queryAll(); } else { OGREnvelope oEnvelope; m_poFilterGeom->getEnvelope( &oEnvelope );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -