ogrfmelayercached.cpp
来自「支持各种栅格图像和矢量图像读取的库」· C++ 代码 · 共 488 行 · 第 1/2 页
CPP
488 行
/****************************************************************************** * $Id: ogrfmelayercached.cpp 10646 2007-01-18 02:38:10Z warmerdam $ * * 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. ****************************************************************************/#include "fme2ogr.h"#include "cpl_conv.h"#include "cpl_string.h"CPL_CVSID("$Id: ogrfmelayercached.cpp 10646 2007-01-18 02:38:10Z warmerdam $");/************************************************************************//* 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 ); poFMEFeature->resetFeature(); poFMEFeature->setDimension( FME_TWO_D ); poFMEFeature->setGeometryType( FME_GEOM_LINE ); poFMEFeature->addCoordinate( oEnvelope.MinX, oEnvelope.MinY ); poFMEFeature->addCoordinate( oEnvelope.MaxX, oEnvelope.MaxY ); poIndex->queryEnvelope( *poFMEFeature ); } bQueryActive = TRUE; poDS->ReleaseSession();}/************************************************************************//* GetFeatureCount() *//************************************************************************/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?