Skip to content
Permalink
Browse files

Simplify code handling geography and support postgis-2.0 WKB (sqlmm; f…

…ixes #4767)
  • Loading branch information
Sandro Santilli authored and jef-n committed Jan 12, 2012
1 parent c6eb236 commit 8d65c9728065d5b34b4e8c0418ad7767ea6f514e
Showing with 16 additions and 18 deletions.
  1. +16 −18 src/providers/postgres/qgspostgresprovider.cpp
@@ -409,18 +409,13 @@ bool QgsPostgresProvider::declareCursor(

if ( fetchGeometry )
{
if ( isGeography )
{
query += QString( ",st_asbinary(%1)" )
.arg( quotedIdentifier( geometryColumn ) );
}
else
{
query += QString( ",%1(%2,'%3')" )
.arg( connectionRO->majorVersion() < 2 ? "asbinary" : "st_asbinary" )
.arg( quotedIdentifier( geometryColumn ) )
.arg( endianString() );
}
// The ::geometry cast is to deal cleanly with geography, see
// http://postgis.refractions.net/pipermail/postgis-devel/2012-January/017468.html
query += QString( ",%1(%2(%3::geometry),'%4')" )
.arg( connectionRO->majorVersion() < 2 ? "asbinary" : "st_asbinary" )
.arg( connectionRO->majorVersion() < 2 ? "force_2d" : "st_force_2d" )
.arg( quotedIdentifier( geometryColumn ) )
.arg( endianString() );
}

for ( QgsAttributeList::const_iterator it = fetchAttributes.constBegin(); it != fetchAttributes.constEnd(); ++it )
@@ -3190,10 +3185,11 @@ bool QgsPostgresProvider::getGeometryDetails()
// Didn't find what we need in the geometry_columns table, so
// get stuff from the relevant column instead. This may (will?)
// fail if there is no data in the relevant table.
sql = QString( "select %1(%2),upper(geometrytype(%2)) from %3" )
sql = QString( "select %1(%2),upper(geometrytype(%2%4)) from %3" )
.arg( connectionRO->majorVersion() < 2 ? "srid" : "st_srid" )
.arg( quotedIdentifier( geometryColumn ) )
.arg( mQuery );
.arg( mQuery )
.arg( isGeography ? "::geometry" : "" );

//it is possible that the where clause restricts the feature type
if ( !sqlWhereClause.isEmpty() )
@@ -3220,11 +3216,13 @@ bool QgsPostgresProvider::getGeometryDetails()
// check to see if there is a unique geometry type
sql = QString( "select distinct "
"case"
" when upper(geometrytype(%1)) IN ('POINT','MULTIPOINT') THEN 'POINT'"
" when upper(geometrytype(%1)) IN ('LINESTRING','MULTILINESTRING') THEN 'LINESTRING'"
" when upper(geometrytype(%1)) IN ('POLYGON','MULTIPOLYGON') THEN 'POLYGON'"
" when upper(geometrytype(%1%2)) IN ('POINT','MULTIPOINT') THEN 'POINT'"
" when upper(geometrytype(%1%2)) IN ('LINESTRING','MULTILINESTRING') THEN 'LINESTRING'"
" when upper(geometrytype(%1%2)) IN ('POLYGON','MULTIPOLYGON') THEN 'POLYGON'"
" end "
"from " ).arg( quotedIdentifier( geometryColumn ) );
"from " )
.arg( quotedIdentifier( geometryColumn ) )
.arg( isGeography ? "::geometry" : "" );
if ( mUseEstimatedMetadata )
{
sql += QString( "(select %1 from %2 where %1 is not null" )

0 comments on commit 8d65c97

Please sign in to comment.
You can’t perform that action at this time.