Skip to content

Commit

Permalink
Simplify generation of SQL query for selecting features in a box.
Browse files Browse the repository at this point in the history
This is propedeutic to upcoming changes related to boxes in PostGIS 2.0
  • Loading branch information
Sandro Santilli authored and jef-n committed Nov 25, 2011
1 parent cbf6302 commit 7ef04f6
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions src/providers/postgres/qgspostgresprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1326,24 +1326,21 @@ void QgsPostgresProvider::select( QgsAttributeList fetchAttributes, QgsRectangle

if ( whereClause.isEmpty() )
{
QString qBox = QString( "%1('BOX3D(%2)'::box3d,%3)" )
.arg( connectionRO->majorVersion() < 2 ? "setsrid"
: "st_setsrid" )
.arg( rect.asWktCoordinates() )
.arg( srid );
whereClause = QString( "%1 && %2" )
.arg( quotedIdentifier( geometryColumn ) )
.arg( qBox );
if ( useIntersect )
{
// Contributed by #qgis irc "creeping"
// This version actually invokes PostGIS's use of spatial indexes
whereClause = QString( "%1 && %2('BOX3D(%3)'::box3d,%4) and %5(%1,%2('BOX3D(%3)'::box3d,%4))" )
whereClause += QString( " and %1(%2,%3))" )
.arg( connectionRO->majorVersion() < 2 ? "intersects"
: "st_intersects" )
.arg( quotedIdentifier( geometryColumn ) )
.arg( connectionRO->majorVersion() < 2 ? "setsrid" : "st_setsrid" )
.arg( rect.asWktCoordinates() )
.arg( srid )
.arg( connectionRO->majorVersion() < 2 ? "intersects" : "st_intersects" );
}
else
{
whereClause = QString( "%1 && %2('BOX3D(%3)'::box3d,%4)" )
.arg( quotedIdentifier( geometryColumn ) )
.arg( connectionRO->majorVersion() < 2 ? "setsrid" : "st_setsrid" )
.arg( rect.asWktCoordinates() )
.arg( srid );
.arg( qBox );
}
}
}
Expand Down

0 comments on commit 7ef04f6

Please sign in to comment.