Skip to content
Permalink
Browse files
Simplify generation of SQL query for selecting features in a box.
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 7ef04f69ca980c01f6a35591015ab72c23083dca
Showing with 12 additions and 15 deletions.
  1. +12 −15 src/providers/postgres/qgspostgresprovider.cpp
@@ -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 );
}
}
}

0 comments on commit 7ef04f6

Please sign in to comment.