Skip to content
Permalink
Browse files

Only scan for dimension if it is not already known as needing force2d

Also force 2d on 3d input
  • Loading branch information
Sandro Santilli
Sandro Santilli committed Mar 3, 2015
1 parent 472fbbe commit bd311c89c56f9514c246442d92cf738376f746f1
Showing with 17 additions and 10 deletions.
  1. +17 −10 src/providers/postgres/qgspostgresconn.cpp
@@ -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() )
@@ -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;

@@ -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;

0 comments on commit bd311c8

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