Skip to content

Commit

Permalink
Only scan for dimension if it is not already known as needing force2d
Browse files Browse the repository at this point in the history
Also force 2d on 3d input
  • Loading branch information
Sandro Santilli committed Mar 3, 2015
1 parent 472fbbe commit bd311c8
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/providers/postgres/qgspostgresconn.cpp
Expand Up @@ -469,11 +469,12 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP
layerProperty.types = QList<QGis::WkbType>() << ( QgsPostgresConn::wkbTypeFromPostgis( type ) );
layerProperty.srids = QList<int>() << srid;
layerProperty.sql = "";
/* TODO: why not != 2 ?
* Also note the value is not necessarely trustworthy:
/*
* NOTE: force2d may get a false negative value
* (dim == 2 but is not really constrained)
* http://trac.osgeo.org/postgis/ticket/3068
*/
layerProperty.force2d = dim == 4;
layerProperty.force2d = dim > 2;
addColumnInfo( layerProperty, schemaName, tableName, isView );

if ( isView && layerProperty.pkCols.empty() )
Expand Down Expand Up @@ -1302,11 +1303,14 @@ void QgsPostgresConn::retrieveLayerTypes( QgsPostgresLayerProperty &layerPropert
query += QString::number( srid );
}

query += ",";
query += QString( "%1(%2%3)" )
.arg( majorVersion() < 2 ? "ndims" : "st_ndims" )
.arg( quotedIdentifier( layerProperty.geometryColName ) )
.arg( layerProperty.geometryColType == sctGeography ? "::geometry" : "" );
if ( ! layerProperty.force2d )
{
query += ",";
query += QString( "%1(%2%3)" )
.arg( majorVersion() < 2 ? "ndims" : "st_ndims" )
.arg( quotedIdentifier( layerProperty.geometryColName ) )
.arg( layerProperty.geometryColType == sctGeography ? "::geometry" : "" );
}

query += " FROM " + table;

Expand All @@ -1320,9 +1324,12 @@ void QgsPostgresConn::retrieveLayerTypes( QgsPostgresLayerProperty &layerPropert
{
QString type = gresult.PQgetvalue( i, 0 );
QString srid = gresult.PQgetvalue( i, 1 );
QString ndims = gresult.PQgetvalue( i, 2 );

if ( ndims.toInt() > 2 ) layerProperty.force2d = true;
if ( ! layerProperty.force2d )
{
QString ndims = gresult.PQgetvalue( i, 2 );
if ( ndims.toInt() > 2 ) layerProperty.force2d = true;
}

if ( type.isEmpty() )
continue;
Expand Down

0 comments on commit bd311c8

Please sign in to comment.