Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
#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 3b6ed3b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/providers/postgres/qgspostgresfeatureiterator.cpp
Expand Up @@ -80,6 +80,9 @@ QgsPostgresFeatureIterator::QgsPostgresFeatureIterator( QgsPostgresProvider* p,
return; return;
} }


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

mFetched = 0; mFetched = 0;
} }


Expand Down Expand Up @@ -170,6 +173,26 @@ bool QgsPostgresFeatureIterator::fetchFeature( QgsFeature& feature )
return true; 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() bool QgsPostgresFeatureIterator::rewind()
{ {
Expand Down Expand Up @@ -272,8 +295,34 @@ bool QgsPostgresFeatureIterator::declareCursor( const QString& whereClause )


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

QString query = "SELECT ", delim = ""; 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 ) if ( mFetchGeometry )
{ {
query += QString( "%1(%2%3,'%4')" ) query += QString( "%1(%2%3,'%4')" )
Expand Down
3 changes: 3 additions & 0 deletions src/providers/postgres/qgspostgresfeatureiterator.h
Expand Up @@ -40,6 +40,9 @@ class QgsPostgresFeatureIterator : public QgsAbstractFeatureIterator
//! fetch next feature, return true on success //! fetch next feature, return true on success
virtual bool fetchFeature( QgsFeature& feature ); 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; QgsPostgresProvider* P;


QString whereClauseRect(); QString whereClauseRect();
Expand Down
3 changes: 3 additions & 0 deletions src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -993,6 +993,9 @@ bool QgsPostgresProvider::hasSufficientPermsAndCapabilities()
} }
} }


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

return true; return true;
} }


Expand Down

0 comments on commit 3b6ed3b

Please sign in to comment.