Navigation Menu

Skip to content

Commit

Permalink
Remove FeatureIterator simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuarte47 committed May 25, 2016
1 parent 322da8b commit 89597f3
Show file tree
Hide file tree
Showing 10 changed files with 4 additions and 563 deletions.
37 changes: 1 addition & 36 deletions src/core/qgsfeatureiterator.cpp
Expand Up @@ -15,7 +15,6 @@
#include "qgsfeatureiterator.h"
#include "qgslogger.h"

#include "qgsgeometrysimplifier.h"
#include "qgssimplifymethod.h"

#include "qgsexpressionsorter.h"
Expand All @@ -27,15 +26,12 @@ QgsAbstractFeatureIterator::QgsAbstractFeatureIterator( const QgsFeatureRequest&
, refs( 0 )
, mFetchedCount( 0 )
, mCompileStatus( NoCompilation )
, mGeometrySimplifier( nullptr )
, mLocalSimplification( false )
, mUseCachedFeatures( false )
{
}

QgsAbstractFeatureIterator::~QgsAbstractFeatureIterator()
{
delete mGeometrySimplifier;
}

bool QgsAbstractFeatureIterator::nextFeature( QgsFeature& f )
Expand Down Expand Up @@ -79,12 +75,6 @@ bool QgsAbstractFeatureIterator::nextFeature( QgsFeature& f )
}
}

// simplify the geometry using the simplifier configured
if ( dataOk && mLocalSimplification )
{
if ( f.constGeometry() )
simplify( f );
}
if ( dataOk )
mFetchedCount++;

Expand Down Expand Up @@ -138,18 +128,7 @@ void QgsAbstractFeatureIterator::deref()

bool QgsAbstractFeatureIterator::prepareSimplification( const QgsSimplifyMethod& simplifyMethod )
{
mLocalSimplification = false;

delete mGeometrySimplifier;
mGeometrySimplifier = nullptr;

// setup the simplification of geometries to fetch
if ( !( mRequest.flags() & QgsFeatureRequest::NoGeometry ) && simplifyMethod.methodType() != QgsSimplifyMethod::NoSimplification && ( simplifyMethod.forceLocalOptimization() || !providerCanSimplify( simplifyMethod.methodType() ) ) )
{
mGeometrySimplifier = QgsSimplifyMethod::createGeometrySimplifier( simplifyMethod );
mLocalSimplification = nullptr != mGeometrySimplifier;
return mLocalSimplification;
}
Q_UNUSED( simplifyMethod );
return false;
}

Expand Down Expand Up @@ -205,20 +184,6 @@ bool QgsAbstractFeatureIterator::providerCanSimplify( QgsSimplifyMethod::MethodT
return false;
}

bool QgsAbstractFeatureIterator::simplify( QgsFeature& feature )
{
// simplify locally the geometry using the configured simplifier
if ( mGeometrySimplifier )
{
QgsGeometry* geometry = feature.geometry();

QGis::GeometryType geometryType = geometry->type();
if ( geometryType == QGis::Line || geometryType == QGis::Polygon )
return mGeometrySimplifier->simplifyGeometry( geometry );
}
return false;
}

bool QgsAbstractFeatureIterator::prepareOrderBy( const QList<QgsFeatureRequest::OrderByClause>& orderBys )
{
Q_UNUSED( orderBys )
Expand Down
9 changes: 0 additions & 9 deletions src/core/qgsfeatureiterator.h
Expand Up @@ -19,7 +19,6 @@
#include "qgslogger.h"
#include "qgsindexedfeature.h"

class QgsAbstractGeometrySimplifier;

/** \ingroup core
* Interface that can be optionaly attached to an iterator so its
Expand Down Expand Up @@ -145,21 +144,13 @@ class CORE_EXPORT QgsAbstractFeatureIterator
virtual bool prepareSimplification( const QgsSimplifyMethod& simplifyMethod );

private:
//! optional object to locally simplify geometries fetched by this feature iterator
QgsAbstractGeometrySimplifier* mGeometrySimplifier;
//! this iterator runs local simplification
bool mLocalSimplification;

bool mUseCachedFeatures;
QList<QgsIndexedFeature> mCachedFeatures;
QList<QgsIndexedFeature>::ConstIterator mFeatureIterator;

//! returns whether the iterator supports simplify geometries on provider side
virtual bool providerCanSimplify( QgsSimplifyMethod::MethodType methodType ) const;

//! simplify the specified geometry if it was configured
virtual bool simplify( QgsFeature& feature );

/**
* Should be overwritten by providers which implement an own order by strategy
* If the own order by strategy is successful, return true, if not, return false
Expand Down
50 changes: 1 addition & 49 deletions src/core/qgsvectorlayerfeatureiterator.cpp
Expand Up @@ -35,8 +35,6 @@ QgsVectorLayerFeatureSource::QgsVectorLayerFeatureSource( QgsVectorLayer *layer
mExpressionFieldBuffer = new QgsExpressionFieldBuffer( *layer->mExpressionFieldBuffer );
mCrsId = layer->crs().srsid();

mCanBeSimplified = layer->hasGeometryType() && layer->geometryType() != QGis::Point;

mHasEditBuffer = layer->editBuffer();
if ( mHasEditBuffer )
{
Expand Down Expand Up @@ -93,7 +91,6 @@ QgsFeatureIterator QgsVectorLayerFeatureSource::getFeatures( const QgsFeatureReq
QgsVectorLayerFeatureIterator::QgsVectorLayerFeatureIterator( QgsVectorLayerFeatureSource* source, bool ownSource, const QgsFeatureRequest& request )
: QgsAbstractFeatureIteratorFromSource<QgsVectorLayerFeatureSource>( source, ownSource, request )
, mFetchedFid( false )
, mEditGeometrySimplifier( nullptr )
, mInterruptionChecker( nullptr )
{
prepareExpressions();
Expand Down Expand Up @@ -191,9 +188,6 @@ QgsVectorLayerFeatureIterator::QgsVectorLayerFeatureIterator( QgsVectorLayerFeat

QgsVectorLayerFeatureIterator::~QgsVectorLayerFeatureIterator()
{
delete mEditGeometrySimplifier;
mEditGeometrySimplifier = nullptr;

qDeleteAll( mExpressionFieldInfo );

close();
Expand Down Expand Up @@ -357,14 +351,6 @@ void QgsVectorLayerFeatureIterator::useAddedFeature( const QgsFeature& src, QgsF
if ( src.constGeometry() && !( mRequest.flags() & QgsFeatureRequest::NoGeometry ) )
{
f.setGeometry( new QgsGeometry( *src.constGeometry() ) );

// simplify the edited geometry using its simplifier configured
if ( mEditGeometrySimplifier )
{
QgsGeometry* geometry = f.geometry();
QGis::GeometryType geometryType = geometry->type();
if ( geometryType == QGis::Line || geometryType == QGis::Polygon ) mEditGeometrySimplifier->simplifyGeometry( geometry );
}
}

// TODO[MD]: if subset set just some attributes
Expand Down Expand Up @@ -439,14 +425,6 @@ void QgsVectorLayerFeatureIterator::useChangedAttributeFeature( QgsFeatureId fid
if ( !( mRequest.flags() & QgsFeatureRequest::NoGeometry ) )
{
f.setGeometry( geom );

// simplify the edited geometry using its simplifier configured
if ( mEditGeometrySimplifier )
{
QgsGeometry* geometry = f.geometry();
QGis::GeometryType geometryType = geometry->type();
if ( geometryType == QGis::Line || geometryType == QGis::Polygon ) mEditGeometrySimplifier->simplifyGeometry( geometry );
}
}

bool subsetAttrs = ( mRequest.flags() & QgsFeatureRequest::SubsetOfAttributes );
Expand Down Expand Up @@ -638,39 +616,13 @@ void QgsVectorLayerFeatureIterator::addVirtualAttributes( QgsFeature& f )

bool QgsVectorLayerFeatureIterator::prepareSimplification( const QgsSimplifyMethod& simplifyMethod )
{
delete mEditGeometrySimplifier;
mEditGeometrySimplifier = nullptr;

// setup simplification for edited geometries to fetch
if ( !( mRequest.flags() & QgsFeatureRequest::NoGeometry ) && simplifyMethod.methodType() != QgsSimplifyMethod::NoSimplification && mSource->mCanBeSimplified )
{
mEditGeometrySimplifier = QgsSimplifyMethod::createGeometrySimplifier( simplifyMethod );
return nullptr != mEditGeometrySimplifier;
}
Q_UNUSED( simplifyMethod );
return false;
}

bool QgsVectorLayerFeatureIterator::providerCanSimplify( QgsSimplifyMethod::MethodType methodType ) const
{
Q_UNUSED( methodType );
#if 0
// TODO[MD]: after merge
QgsVectorDataProvider* provider = L->dataProvider();

if ( provider && methodType != QgsSimplifyMethod::NoSimplification )
{
int capabilities = provider->capabilities();

if ( methodType == QgsSimplifyMethod::OptimizeForRendering )
{
return ( capabilities & QgsVectorDataProvider::SimplifyGeometries );
}
else if ( methodType == QgsSimplifyMethod::PreserveTopology )
{
return ( capabilities & QgsVectorDataProvider::SimplifyGeometriesWithTopologicalValidation );
}
}
#endif
return false;
}

Expand Down
7 changes: 1 addition & 6 deletions src/core/qgsvectorlayerfeatureiterator.h
Expand Up @@ -55,8 +55,6 @@ class QgsVectorLayerFeatureSource : public QgsAbstractFeatureSource

bool mHasEditBuffer;

bool mCanBeSimplified;

// A deep-copy is only performed, if the original maps change
// see here https://github.com/qgis/Quantum-GIS/pull/673
// for explanation
Expand Down Expand Up @@ -92,7 +90,7 @@ class CORE_EXPORT QgsVectorLayerFeatureIterator : public QgsAbstractFeatureItera

//! Overrides default method as we only need to filter features in the edit buffer
//! while for others filtering is left to the provider implementation.
inline virtual bool nextFeatureFilterExpression( QgsFeature &f ) override { return fetchFeature( f ); }
virtual bool nextFeatureFilterExpression( QgsFeature &f ) override { return fetchFeature( f ); }

//! Setup the simplification of geometries to fetch using the specified simplify method
virtual bool prepareSimplification( const QgsSimplifyMethod& simplifyMethod ) override;
Expand Down Expand Up @@ -176,9 +174,6 @@ class CORE_EXPORT QgsVectorLayerFeatureIterator : public QgsAbstractFeatureItera
bool mHasVirtualAttributes;

private:
//! optional object to locally simplify edited (changed or added) geometries fetched by this feature iterator
QgsAbstractGeometrySimplifier* mEditGeometrySimplifier;

QScopedPointer<QgsExpressionContext> mExpressionContext;

QgsInterruptionChecker* mInterruptionChecker;
Expand Down
2 changes: 1 addition & 1 deletion src/providers/ogr/CMakeLists.txt
@@ -1,5 +1,5 @@

SET (OGR_SRCS qgsogrprovider.cpp qgsogrdataitems.cpp qgsogrfeatureiterator.cpp qgsogrgeometrysimplifier.cpp qgsogrconnpool.cpp qgsogrexpressioncompiler.cpp)
SET (OGR_SRCS qgsogrprovider.cpp qgsogrdataitems.cpp qgsogrfeatureiterator.cpp qgsogrconnpool.cpp qgsogrexpressioncompiler.cpp)

SET(OGR_MOC_HDRS qgsogrprovider.h qgsogrdataitems.h qgsogrconnpool.h)

Expand Down
62 changes: 0 additions & 62 deletions src/providers/ogr/qgsogrfeatureiterator.cpp
Expand Up @@ -15,7 +15,6 @@
#include "qgsogrfeatureiterator.h"

#include "qgsogrprovider.h"
#include "qgsogrgeometrysimplifier.h"
#include "qgsogrexpressioncompiler.h"
#include "qgssqliteexpressioncompiler.h"

Expand Down Expand Up @@ -43,7 +42,6 @@ QgsOgrFeatureIterator::QgsOgrFeatureIterator( QgsOgrFeatureSource* source, bool
, ogrLayer( nullptr )
, mSubsetStringSet( false )
, mFetchGeometry( false )
, mGeometrySimplifier( nullptr )
, mExpressionCompiled( false )
{
mConn = QgsOgrConnPool::instance()->acquireConnection( mSource->mProvider->dataSourceUri() );
Expand Down Expand Up @@ -157,46 +155,9 @@ QgsOgrFeatureIterator::QgsOgrFeatureIterator( QgsOgrFeatureSource* source, bool

QgsOgrFeatureIterator::~QgsOgrFeatureIterator()
{
delete mGeometrySimplifier;
mGeometrySimplifier = nullptr;

close();
}

bool QgsOgrFeatureIterator::prepareSimplification( const QgsSimplifyMethod& simplifyMethod )
{
delete mGeometrySimplifier;
mGeometrySimplifier = nullptr;

// setup simplification of OGR-geometries fetched
if ( !( mRequest.flags() & QgsFeatureRequest::NoGeometry ) && simplifyMethod.methodType() != QgsSimplifyMethod::NoSimplification && !simplifyMethod.forceLocalOptimization() )
{
QgsSimplifyMethod::MethodType methodType = simplifyMethod.methodType();
Q_UNUSED( methodType );

#if defined(GDAL_VERSION_NUM) && defined(GDAL_COMPUTE_VERSION)
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(1,11,0)
if ( methodType == QgsSimplifyMethod::OptimizeForRendering )
{
int simplifyFlags = QgsMapToPixelSimplifier::SimplifyGeometry | QgsMapToPixelSimplifier::SimplifyEnvelope;
mGeometrySimplifier = new QgsOgrMapToPixelSimplifier( simplifyFlags, simplifyMethod.tolerance() );
return true;
}
#endif
#endif
#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1900
if ( methodType == QgsSimplifyMethod::PreserveTopology )
{
mGeometrySimplifier = new QgsOgrTopologyPreservingSimplifier( simplifyMethod.tolerance() );
return true;
}
#endif

QgsDebugMsg( QString( "Simplification method type (%1) is not recognised by OgrFeatureIterator class" ).arg( methodType ) );
}
return QgsAbstractFeatureIterator::prepareSimplification( simplifyMethod );
}

bool QgsOgrFeatureIterator::nextFeatureFilterExpression( QgsFeature& f )
{
if ( !mExpressionCompiled )
Expand All @@ -205,26 +166,6 @@ bool QgsOgrFeatureIterator::nextFeatureFilterExpression( QgsFeature& f )
return fetchFeature( f );
}

bool QgsOgrFeatureIterator::providerCanSimplify( QgsSimplifyMethod::MethodType methodType ) const
{
#if defined(GDAL_VERSION_NUM) && defined(GDAL_COMPUTE_VERSION)
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(1,11,0)
if ( methodType == QgsSimplifyMethod::OptimizeForRendering )
{
return true;
}
#endif
#endif
#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1900
if ( methodType == QgsSimplifyMethod::PreserveTopology )
{
return true;
}
#endif

return false;
}

bool QgsOgrFeatureIterator::fetchFeature( QgsFeature& feature )
{
feature.setValid( false );
Expand Down Expand Up @@ -337,9 +278,6 @@ bool QgsOgrFeatureIterator::readFeature( OGRFeatureH fet, QgsFeature& feature )

if ( geom )
{
if ( mGeometrySimplifier )
mGeometrySimplifier->simplifyGeometry( geom );

feature.setGeometry( QgsOgrUtils::ogrGeometryToQgsGeometry( geom ) );
}
else
Expand Down
10 changes: 0 additions & 10 deletions src/providers/ogr/qgsogrfeatureiterator.h
Expand Up @@ -22,7 +22,6 @@

class QgsOgrFeatureIterator;
class QgsOgrProvider;
class QgsOgrAbstractGeometrySimplifier;

class QgsOgrFeatureSource : public QgsAbstractFeatureSource
{
Expand Down Expand Up @@ -66,9 +65,6 @@ class QgsOgrFeatureIterator : public QgsAbstractFeatureIteratorFromSource<QgsOgr
//! fetch next feature, return true on success
virtual bool fetchFeature( QgsFeature& feature ) override;

//! Setup the simplification of geometries to fetch using the specified simplify method
virtual bool prepareSimplification( const QgsSimplifyMethod& simplifyMethod ) override;

//! fetch next feature filter expression
bool nextFeatureFilterExpression( QgsFeature& f ) override;

Expand All @@ -88,13 +84,7 @@ class QgsOgrFeatureIterator : public QgsAbstractFeatureIteratorFromSource<QgsOgr
bool mFetchGeometry;

private:
//! optional object to simplify OGR-geometries fecthed by this feature iterator
QgsOgrAbstractGeometrySimplifier* mGeometrySimplifier;

bool mExpressionCompiled;

//! returns whether the iterator supports simplify geometries on provider side
virtual bool providerCanSimplify( QgsSimplifyMethod::MethodType methodType ) const override;
};

#endif // QGSOGRFEATUREITERATOR_H

0 comments on commit 89597f3

Please sign in to comment.