Skip to content

Commit c5ce267

Browse files
author
Sandro Santilli
committedMar 4, 2015
Only scan for dimension if it is not already known as needing force2d
Also force 2d on 3d input
1 parent a525dbd commit c5ce267

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed
 

‎src/providers/postgres/qgspostgresconn.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -469,11 +469,12 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP
469469
layerProperty.types = QList<QGis::WkbType>() << ( QgsPostgresConn::wkbTypeFromPostgis( type ) );
470470
layerProperty.srids = QList<int>() << srid;
471471
layerProperty.sql = "";
472-
/* TODO: why not != 2 ?
473-
* Also note the value is not necessarely trustworthy:
472+
/*
473+
* NOTE: force2d may get a false negative value
474+
* (dim == 2 but is not really constrained)
474475
* http://trac.osgeo.org/postgis/ticket/3068
475476
*/
476-
layerProperty.force2d = dim == 4;
477+
layerProperty.force2d = dim > 2;
477478
addColumnInfo( layerProperty, schemaName, tableName, isView );
478479

479480
if ( isView && layerProperty.pkCols.empty() )
@@ -1303,11 +1304,14 @@ void QgsPostgresConn::retrieveLayerTypes( QgsPostgresLayerProperty &layerPropert
13031304
query += QString::number( srid );
13041305
}
13051306

1306-
query += ",";
1307-
query += QString( "%1(%2%3)" )
1308-
.arg( majorVersion() < 2 ? "ndims" : "st_ndims" )
1309-
.arg( quotedIdentifier( layerProperty.geometryColName ) )
1310-
.arg( layerProperty.geometryColType == sctGeography ? "::geometry" : "" );
1307+
if ( ! layerProperty.force2d )
1308+
{
1309+
query += ",";
1310+
query += QString( "%1(%2%3)" )
1311+
.arg( majorVersion() < 2 ? "ndims" : "st_ndims" )
1312+
.arg( quotedIdentifier( layerProperty.geometryColName ) )
1313+
.arg( layerProperty.geometryColType == sctGeography ? "::geometry" : "" );
1314+
}
13111315

13121316
query += " FROM " + table;
13131317

@@ -1321,9 +1325,12 @@ void QgsPostgresConn::retrieveLayerTypes( QgsPostgresLayerProperty &layerPropert
13211325
{
13221326
QString type = gresult.PQgetvalue( i, 0 );
13231327
QString srid = gresult.PQgetvalue( i, 1 );
1324-
QString ndims = gresult.PQgetvalue( i, 2 );
13251328

1326-
if ( ndims.toInt() > 2 ) layerProperty.force2d = true;
1329+
if ( ! layerProperty.force2d )
1330+
{
1331+
QString ndims = gresult.PQgetvalue( i, 2 );
1332+
if ( ndims.toInt() > 2 ) layerProperty.force2d = true;
1333+
}
13271334

13281335
if ( type.isEmpty() )
13291336
continue;

0 commit comments

Comments
 (0)
Please sign in to comment.