Skip to content

Commit db1192f

Browse files
committedJan 31, 2014
#8725R: Replace ST_Simplify by ST_SnapToGrid
1 parent e4f410b commit db1192f

File tree

1 file changed

+1
-51
lines changed

1 file changed

+1
-51
lines changed
 

‎src/providers/postgres/qgspostgresfeatureiterator.cpp

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,6 @@ QString QgsPostgresFeatureIterator::whereClauseRect()
293293
bool QgsPostgresFeatureIterator::declareCursor( const QString& whereClause )
294294
{
295295
mFetchGeometry = !( mRequest.flags() & QgsFeatureRequest::NoGeometry ) && !P->mGeometryColumn.isNull();
296-
bool simplifyGeometry = false;
297296

298297
try
299298
{
@@ -304,11 +303,10 @@ bool QgsPostgresFeatureIterator::declareCursor( const QString& whereClause )
304303
if ( mFetchGeometry && !simplifyMethod.forceLocalOptimization() && simplifyMethod.methodType() != QgsSimplifyMethod::NoSimplification && QGis::flatType( QGis::singleType( P->geometryType() ) ) != QGis::WKBPoint )
305304
{
306305
QString simplifyFunctionName = simplifyMethod.methodType() == QgsSimplifyMethod::OptimizeForRendering
307-
? ( P->mConnectionRO->majorVersion() < 2 ? "simplify" : "st_simplify" )
306+
? ( P->mConnectionRO->majorVersion() < 2 ? "snaptogrid" : "st_snaptogrid" )
308307
: ( P->mConnectionRO->majorVersion() < 2 ? "simplifypreservetopology" : "st_simplifypreservetopology" );
309308

310309
double tolerance = simplifyMethod.tolerance() * 0.8; //-> Default factor for the maximum displacement distance for simplification, similar as GeoServer does
311-
simplifyGeometry = simplifyMethod.methodType() == QgsSimplifyMethod::OptimizeForRendering;
312310

313311
query += QString( "%1(%5(%2%3,%6),'%4')" )
314312
.arg( P->mConnectionRO->majorVersion() < 2 ? "asbinary" : "st_asbinary" )
@@ -369,17 +367,6 @@ bool QgsPostgresFeatureIterator::declareCursor( const QString& whereClause )
369367
query += delim + P->mConnectionRO->fieldExpression( P->field( idx ) );
370368
}
371369

372-
// query BBOX of geometries to redefine the geometries collapsed by ST_Simplify()
373-
if ( simplifyGeometry && !( P->mConnectionRO->majorVersion() >= 2 && P->mConnectionRO->minorVersion() >= 1 ) )
374-
{
375-
query += QString( ",%1(%5(%2)%3,'%4')" )
376-
.arg( P->mConnectionRO->majorVersion() < 2 ? "asbinary" : "st_asbinary" )
377-
.arg( P->quotedIdentifier( P->mGeometryColumn ) )
378-
.arg( P->mSpatialColType == sctGeography ? "::geometry" : "" )
379-
.arg( P->endianString() )
380-
.arg( P->mConnectionRO->majorVersion() < 2 ? "envelope" : "st_envelope" );
381-
}
382-
383370
query += " FROM " + P->mQuery;
384371

385372
if ( !whereClause.isEmpty() )
@@ -603,43 +590,6 @@ bool QgsPostgresFeatureIterator::getFeature( QgsPostgresResult &queryResult, int
603590
getFeatureAttribute( idx, queryResult, row, col, feature );
604591
}
605592

606-
// fix collapsed geometries by ST_Simplify() using the BBOX fetched from the current query
607-
const QgsSimplifyMethod& simplifyMethod = mRequest.simplifyMethod();
608-
if ( mFetchGeometry && !simplifyMethod.forceLocalOptimization() && simplifyMethod.methodType() == QgsSimplifyMethod::OptimizeForRendering && QGis::flatType( QGis::singleType( P->geometryType() ) ) != QGis::WKBPoint )
609-
{
610-
QgsGeometry* geometry = feature.geometry();
611-
612-
if ( !( P->mConnectionRO->majorVersion() >= 2 && P->mConnectionRO->minorVersion() >= 1 ) && ( !geometry || geometry->length() == 0 ) )
613-
{
614-
int returnedLength = ::PQgetlength( queryResult.result(), row, col );
615-
616-
if ( returnedLength > 0 )
617-
{
618-
unsigned char *featureGeom = new unsigned char[returnedLength + 1];
619-
memcpy( featureGeom, PQgetvalue( queryResult.result(), row, col ), returnedLength );
620-
memset( featureGeom + returnedLength, 0, 1 );
621-
622-
QgsGeometry *envelope = new QgsGeometry();
623-
envelope->fromWkb( featureGeom, returnedLength + 1 );
624-
625-
if ( QGis::flatType( QGis::singleType( P->geometryType() ) ) == QGis::WKBPolygon )
626-
{
627-
feature.setGeometry( envelope );
628-
}
629-
else
630-
{
631-
QgsPolyline polyline;
632-
polyline.append( envelope->vertexAt( 0 ) );
633-
polyline.append( envelope->vertexAt( 2 ) );
634-
delete envelope;
635-
636-
geometry = QgsGeometry::fromPolyline( polyline );
637-
feature.setGeometry( geometry );
638-
}
639-
}
640-
}
641-
}
642-
643593
return true;
644594
}
645595
catch ( QgsPostgresProvider::PGFieldNotFound )

0 commit comments

Comments
 (0)
Please sign in to comment.