Skip to content

Commit 3b6ed3b

Browse files
ahuarte47m-kuhn
authored andcommittedJan 15, 2014
#8725-R: PostgresProvider simplifies on provider side
PostgresFeatureIterator implements simplification on provider side
1 parent dcaf0b5 commit 3b6ed3b

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed
 

‎src/providers/postgres/qgspostgresfeatureiterator.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ QgsPostgresFeatureIterator::QgsPostgresFeatureIterator( QgsPostgresProvider* p,
8080
return;
8181
}
8282

83+
//setup if required the simplification of geometries to fetch
84+
prepareProviderSimplification();
85+
8386
mFetched = 0;
8487
}
8588

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

176+
bool QgsPostgresFeatureIterator::prepareProviderSimplification()
177+
{
178+
const QgsSimplifyMethod& simplifyMethod = mRequest.simplifyMethod();
179+
180+
// validate settings of simplification of geometries to fetch
181+
if ( simplifyMethod.methodType() != QgsSimplifyMethod::NoSimplification && !simplifyMethod.forceLocalOptimization() && !( mRequest.flags() & QgsFeatureRequest::NoGeometry ) )
182+
{
183+
QgsSimplifyMethod::MethodType methodType = simplifyMethod.methodType();
184+
185+
if ( methodType == QgsSimplifyMethod::OptimizeForRendering || methodType == QgsSimplifyMethod::PreserveTopology )
186+
{
187+
return true;
188+
}
189+
else
190+
{
191+
QgsDebugMsg( QString( "Simplification method type (%1) is not recognised by PostgresFeatureIterator" ).arg( methodType ) );
192+
}
193+
}
194+
return false;
195+
}
173196

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

273296
try
274297
{
298+
const QgsSimplifyMethod& simplifyMethod = mRequest.simplifyMethod();
299+
275300
QString query = "SELECT ", delim = "";
276301

302+
if ( mFetchGeometry && !simplifyMethod.forceLocalOptimization() && simplifyMethod.methodType() != QgsSimplifyMethod::NoSimplification )
303+
{
304+
QString simplifyFunctionName = simplifyMethod.methodType() == QgsSimplifyMethod::OptimizeForRendering
305+
?
306+
( P->mConnectionRO->majorVersion() < 2 ? "simplify" : "st_simplify" )
307+
:
308+
( P->mConnectionRO->majorVersion() < 2 ? "simplifypreservetopology" : "st_simplifypreservetopology" );
309+
310+
double tolerance = simplifyMethod.methodType() == QgsSimplifyMethod::OptimizeForRendering
311+
?
312+
simplifyMethod.tolerance() / 5.0f /* experimental */
313+
:
314+
simplifyMethod.tolerance();
315+
316+
query += QString( "%1(%5(%2%3,%6),'%4')" )
317+
.arg( P->mConnectionRO->majorVersion() < 2 ? "asbinary" : "st_asbinary" )
318+
.arg( P->quotedIdentifier( P->mGeometryColumn ) )
319+
.arg( P->mSpatialColType == sctGeography ? "::geometry" : "" )
320+
.arg( P->endianString() )
321+
.arg( simplifyFunctionName )
322+
.arg( tolerance );
323+
delim = ",";
324+
}
325+
else
277326
if ( mFetchGeometry )
278327
{
279328
query += QString( "%1(%2%3,'%4')" )

‎src/providers/postgres/qgspostgresfeatureiterator.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ class QgsPostgresFeatureIterator : public QgsAbstractFeatureIterator
4040
//! fetch next feature, return true on success
4141
virtual bool fetchFeature( QgsFeature& feature );
4242

43+
//! setup if required the simplification of geometries to fetch, it uses the settings of current FeatureRequest
44+
virtual bool prepareProviderSimplification();
45+
4346
QgsPostgresProvider* P;
4447

4548
QString whereClauseRect();

‎src/providers/postgres/qgspostgresprovider.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,9 @@ bool QgsPostgresProvider::hasSufficientPermsAndCapabilities()
993993
}
994994
}
995995

996+
// supports geometry simplification on provider side
997+
mEnabledCapabilities |= QgsVectorDataProvider::SimplifyGeometries;
998+
996999
return true;
9971000
}
9981001

0 commit comments

Comments
 (0)
Please sign in to comment.