Skip to content
Permalink
Browse files

#8725-R: PostgresProvider simplifies on provider side

PostgresFeatureIterator implements simplification on provider side
  • Loading branch information
ahuarte47 authored and m-kuhn committed Jan 15, 2014
1 parent dcaf0b5 commit 3b6ed3bfc81ae079fd30b3a382f11c2435bdddd5
@@ -80,6 +80,9 @@ QgsPostgresFeatureIterator::QgsPostgresFeatureIterator( QgsPostgresProvider* p,
return;
}

//setup if required the simplification of geometries to fetch
prepareProviderSimplification();

mFetched = 0;
}

@@ -170,6 +173,26 @@ bool QgsPostgresFeatureIterator::fetchFeature( QgsFeature& feature )
return true;
}

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

// validate settings of simplification of geometries to fetch
if ( simplifyMethod.methodType() != QgsSimplifyMethod::NoSimplification && !simplifyMethod.forceLocalOptimization() && !( mRequest.flags() & QgsFeatureRequest::NoGeometry ) )
{
QgsSimplifyMethod::MethodType methodType = simplifyMethod.methodType();

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

bool QgsPostgresFeatureIterator::rewind()
{
@@ -272,8 +295,34 @@ bool QgsPostgresFeatureIterator::declareCursor( const QString& whereClause )

try
{
const QgsSimplifyMethod& simplifyMethod = mRequest.simplifyMethod();

QString query = "SELECT ", delim = "";

if ( mFetchGeometry && !simplifyMethod.forceLocalOptimization() && simplifyMethod.methodType() != QgsSimplifyMethod::NoSimplification )
{
QString simplifyFunctionName = simplifyMethod.methodType() == QgsSimplifyMethod::OptimizeForRendering
?
( P->mConnectionRO->majorVersion() < 2 ? "simplify" : "st_simplify" )
:
( P->mConnectionRO->majorVersion() < 2 ? "simplifypreservetopology" : "st_simplifypreservetopology" );

double tolerance = simplifyMethod.methodType() == QgsSimplifyMethod::OptimizeForRendering
?
simplifyMethod.tolerance() / 5.0f /* experimental */
:
simplifyMethod.tolerance();

query += QString( "%1(%5(%2%3,%6),'%4')" )
.arg( P->mConnectionRO->majorVersion() < 2 ? "asbinary" : "st_asbinary" )
.arg( P->quotedIdentifier( P->mGeometryColumn ) )
.arg( P->mSpatialColType == sctGeography ? "::geometry" : "" )
.arg( P->endianString() )
.arg( simplifyFunctionName )
.arg( tolerance );
delim = ",";
}
else
if ( mFetchGeometry )
{
query += QString( "%1(%2%3,'%4')" )
@@ -40,6 +40,9 @@ 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();

QgsPostgresProvider* P;

QString whereClauseRect();
@@ -993,6 +993,9 @@ bool QgsPostgresProvider::hasSufficientPermsAndCapabilities()
}
}

// supports geometry simplification on provider side
mEnabledCapabilities |= QgsVectorDataProvider::SimplifyGeometries;

return true;
}

0 comments on commit 3b6ed3b

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