Skip to content
Permalink
Browse files

#8725-R: refactoring of simplification API in FeatureIterators

  • Loading branch information
ahuarte47 authored and m-kuhn committed Jan 15, 2014
1 parent 1e781ff commit 4cc82e6288058d7568577458d62ea4019266de4d
@@ -55,16 +55,11 @@ bool QgsAbstractFeatureIterator::nextFeature( QgsFeature& f )
break;
}

// simplify locally the geometry using the simplifier defined in constructor
if ( dataOk && mGeometrySimplifier )
// simplify the geometry using the simplifier configured
if ( dataOk )
{
QgsGeometry* geometry = f.geometry();

if ( geometry )
{
QGis::GeometryType geometryType = geometry->type();
if ( geometryType == QGis::Line || geometryType == QGis::Polygon ) mGeometrySimplifier->simplifyGeometry( geometry );
}
if ( geometry ) simplify( f );
}
return dataOk;
}
@@ -101,10 +96,8 @@ void QgsAbstractFeatureIterator::deref()
delete this;
}

bool QgsAbstractFeatureIterator::prepareLocalSimplification()
bool QgsAbstractFeatureIterator::prepareSimplification( const QgsSimplifyMethod& simplifyMethod )
{
const QgsSimplifyMethod& simplifyMethod = mRequest.simplifyMethod();

if ( mGeometrySimplifier )
{
delete mGeometrySimplifier;
@@ -136,6 +129,22 @@ bool QgsAbstractFeatureIterator::prepareLocalSimplification()
return false;
}

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

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

///////

QgsFeatureIterator& QgsFeatureIterator::operator=( const QgsFeatureIterator & other )
@@ -87,12 +87,15 @@ class CORE_EXPORT QgsAbstractFeatureIterator
void deref(); //!< remove reference, delete if refs == 0
friend class QgsFeatureIterator;

//! setup if required the local simplification of geometries to fetch, it uses the settings of current FeatureRequest
virtual bool prepareLocalSimplification();
//! Setup the simplification of geometries to fetch using the specified simplify method
virtual bool prepareSimplification( const QgsSimplifyMethod& simplifyMethod );

private:
//! optional object to locally simplify geometries fetched by this feature iterator
QgsAbstractGeometrySimplifier* mGeometrySimplifier;

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


@@ -68,6 +68,15 @@ QgsVectorLayerFeatureIterator::QgsVectorLayerFeatureIterator( QgsVectorLayer* la
}
else // no filter or filter by rect
{
QgsSimplifyMethod simplifyMethod = request.simplifyMethod();

// if required, local simplification will be configured for all providers, then avoid simplify twice (this iterator and provider iterator)
if ( simplifyMethod.methodType() != QgsSimplifyMethod::NoSimplification && simplifyMethod.forceLocalOptimization() )
{
simplifyMethod.setMethodType( QgsSimplifyMethod::NoSimplification );
if ( L->editBuffer() ) mChangedFeaturesRequest.setSimplifyMethod( simplifyMethod ); else mProviderRequest.setSimplifyMethod( simplifyMethod );
}

if ( L->editBuffer() )
{
mChangedFeaturesIterator = L->dataProvider()->getFeatures( mChangedFeaturesRequest );
@@ -77,8 +86,8 @@ QgsVectorLayerFeatureIterator::QgsVectorLayerFeatureIterator( QgsVectorLayer* la
mProviderIterator = L->dataProvider()->getFeatures( mProviderRequest );
}

// setup if required the local simplification of geometries to fetch
prepareLocalSimplification();
// prepare if required the local simplification of geometries to fetch
prepareSimplification( request.simplifyMethod() );

rewindEditBuffer();
}
@@ -81,7 +81,7 @@ QgsOgrFeatureIterator::QgsOgrFeatureIterator( QgsOgrProvider* p, const QgsFeatur
}

//setup if required the simplification of OGR-geometries fetched
prepareProviderSimplification();
prepareSimplification( request.simplifyMethod() );

//start with first feature
rewind();
@@ -105,9 +105,9 @@ void QgsOgrFeatureIterator::ensureRelevantFields()
P->mRelevantFieldsForNextFeature = true;
}

bool QgsOgrFeatureIterator::prepareProviderSimplification()
bool QgsOgrFeatureIterator::prepareSimplification( const QgsSimplifyMethod& simplifyMethod )
{
const QgsSimplifyMethod& simplifyMethod = mRequest.simplifyMethod();
bool providerSimplification = false;

if ( mGeometrySimplifier )
{
@@ -124,20 +124,20 @@ bool QgsOgrFeatureIterator::prepareProviderSimplification()
{
int simplifyFlags = QgsMapToPixelSimplifier::SimplifyGeometry | QgsMapToPixelSimplifier::SimplifyEnvelope;
mGeometrySimplifier = new QgsOgrMapToPixelSimplifier( simplifyFlags, simplifyMethod.tolerance() );
return true;
providerSimplification = true;
}
else
if ( methodType == QgsSimplifyMethod::PreserveTopology )
{
mGeometrySimplifier = new QgsOgrTopologyPreservingSimplifier( simplifyMethod.tolerance() );
return true;
providerSimplification = true;
}
else
{
QgsDebugMsg( QString( "Simplification method type (%1) is not recognised by OgrFeatureIterator class" ).arg( methodType ) );
}
}
return false;
return QgsAbstractFeatureIterator::prepareSimplification( simplifyMethod ) || providerSimplification;
}

bool QgsOgrFeatureIterator::fetchFeature( QgsFeature& feature )
@@ -39,8 +39,8 @@ class QgsOgrFeatureIterator : public QgsAbstractFeatureIterator
//! fetch next feature, return true on success
virtual bool fetchFeature( QgsFeature& feature );

//! setup if required the simplification of OGR-geometries fetched, it uses the settings of current FeatureRequest
virtual bool prepareProviderSimplification();
//! Setup the simplification of geometries to fetch using the specified simplify method
virtual bool prepareSimplification( const QgsSimplifyMethod& simplifyMethod );

QgsOgrProvider* P;

@@ -81,7 +81,7 @@ QgsPostgresFeatureIterator::QgsPostgresFeatureIterator( QgsPostgresProvider* p,
}

//setup if required the simplification of geometries to fetch
prepareProviderSimplification();
prepareSimplification( request.simplifyMethod() );

mFetched = 0;
}
@@ -173,9 +173,9 @@ bool QgsPostgresFeatureIterator::fetchFeature( QgsFeature& feature )
return true;
}

bool QgsPostgresFeatureIterator::prepareProviderSimplification()
bool QgsPostgresFeatureIterator::prepareSimplification( const QgsSimplifyMethod& simplifyMethod )
{
const QgsSimplifyMethod& simplifyMethod = mRequest.simplifyMethod();
bool providerSimplification = false;

// validate settings of simplification of geometries to fetch
if ( simplifyMethod.methodType() != QgsSimplifyMethod::NoSimplification && !simplifyMethod.forceLocalOptimization() && !( mRequest.flags() & QgsFeatureRequest::NoGeometry ) )
@@ -184,14 +184,14 @@ bool QgsPostgresFeatureIterator::prepareProviderSimplification()

if ( methodType == QgsSimplifyMethod::OptimizeForRendering || methodType == QgsSimplifyMethod::PreserveTopology )
{
return true;
providerSimplification = true;
}
else
{
QgsDebugMsg( QString( "Simplification method type (%1) is not recognised by PostgresFeatureIterator" ).arg( methodType ) );
}
}
return false;
return QgsAbstractFeatureIterator::prepareSimplification( simplifyMethod ) || providerSimplification;
}

bool QgsPostgresFeatureIterator::rewind()
@@ -40,8 +40,8 @@ class QgsPostgresFeatureIterator : public QgsAbstractFeatureIterator
//! fetch next feature, return true on success
virtual bool fetchFeature( QgsFeature& feature );

//! setup if required the simplification of geometries to fetch, it uses the settings of current FeatureRequest
virtual bool prepareProviderSimplification();
//! Setup the simplification of geometries to fetch using the specified simplify method
virtual bool prepareSimplification( const QgsSimplifyMethod& simplifyMethod );

QgsPostgresProvider* P;

0 comments on commit 4cc82e6

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