Skip to content
Permalink
Browse files

Set filter on iterator:

  • Loading branch information
NathanW2 committed Jun 21, 2013
1 parent 6eadd80 commit 0c88963c65d3292e321578104505e8ecc69a6a68
@@ -32,8 +32,9 @@


QgsOgrFeatureIterator::QgsOgrFeatureIterator( QgsOgrProvider* p, const QgsFeatureRequest& request )
: QgsAbstractFeatureIterator( request ), P( p ), ogrDataSource(0), ogrLayer(0), ogrDriver(0)
: QgsAbstractFeatureIterator( request ), P( p ), ogrDataSource(0), ogrLayer(0), mSubsetStringSet(false)
{
mFeatureFetched = false;

ogrDataSource = OGROpen( TO8F( P->filePath() ), false, NULL );

@@ -46,7 +47,15 @@ QgsOgrFeatureIterator::QgsOgrFeatureIterator( QgsOgrProvider* p, const QgsFeatur
ogrLayer = OGR_DS_GetLayerByName( ogrDataSource, TO8( p->layerName() ) );
}

mFeatureFetched = false;
if ( !P->subsetString().isEmpty() )
{
QString sql = QString( "SELECT * FROM %1 WHERE %2" )
.arg( P->quotedIdentifier( FROM8( OGR_FD_GetName( OGR_L_GetLayerDefn( ogrLayer ) ) ) ) )
.arg( P->subsetString() );
QgsDebugMsg( QString( "SQL: %1" ).arg( sql ) );
ogrLayer = OGR_DS_ExecuteSQL( ogrDataSource, P->textEncoding()->fromUnicode( sql ).constData(), NULL, NULL );
mSubsetStringSet = true;
}

ensureRelevantFields();

@@ -150,6 +159,11 @@ bool QgsOgrFeatureIterator::close()
if ( mClosed )
return false;

if (mSubsetStringSet)
{
OGR_DS_ReleaseResultSet(ogrDataSource, ogrLayer );
}

OGR_DS_Destroy( ogrDataSource );

mClosed = true;
@@ -51,6 +51,8 @@ class QgsOgrFeatureIterator : public QgsAbstractFeatureIterator

OGRDataSourceH ogrDataSource;
OGRLayerH ogrLayer;

bool mSubsetStringSet;
};


@@ -15,6 +15,8 @@ email : sherman at mrcc.com
* *
***************************************************************************/

#include "QTextCodec"

#include "qgsrectangle.h"
#include "qgsvectordataprovider.h"
#include "qgsvectorfilewriter.h"
@@ -256,6 +258,10 @@ class QgsOgrProvider : public QgsVectorDataProvider

int layerIndex() { return mLayerIndex; }

QTextCodec* textEncoding() { return mEncoding; }

QString quotedIdentifier( QString field );

protected:
/** loads fields from input file to member attributeFields */
void loadFields();
@@ -329,8 +335,6 @@ class QgsOgrProvider : public QgsVectorDataProvider
/**Deletes one feature*/
bool deleteFeature( QgsFeatureId id );

QString quotedIdentifier( QString field );

/**Calls OGR_L_SyncToDisk and recreates the spatial index if present*/
bool syncToDisc();

0 comments on commit 0c88963

Please sign in to comment.
You can’t perform that action at this time.