Skip to content
Permalink
Browse files

Fix retrieval of 4D geometries (XYZM) from postgres (fixes #17814)

  • Loading branch information
wonder-sk committed Jan 8, 2018
1 parent 0304708 commit 6a4b8b4762278aec6c1175b9489b9b1d07ccffcd
@@ -536,12 +536,6 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP
layerProperty.relKind = relkind;
layerProperty.isView = isView;
layerProperty.tableComment = comment;
/*
* force2d may get a false negative value
* (dim == 2 but is not really constrained)
* http://trac.osgeo.org/postgis/ticket/3068
*/
layerProperty.force2d = dim > 3;
addColumnInfo( layerProperty, schemaName, tableName, isView );

if ( isView && layerProperty.pkCols.empty() )
@@ -1465,14 +1459,6 @@ void QgsPostgresConn::retrieveLayerTypes( QgsPostgresLayerProperty &layerPropert
query += QString::number( srid );
}

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

query += " FROM " + table;

//QgsDebugMsg( "Retrieving geometry types,srids and dims: " + query );
@@ -1486,11 +1472,6 @@ void QgsPostgresConn::retrieveLayerTypes( QgsPostgresLayerProperty &layerPropert
QString type = gresult.PQgetvalue( i, 0 );
QString srid = gresult.PQgetvalue( i, 1 );

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

if ( type.isEmpty() )
continue;

@@ -78,7 +78,6 @@ struct QgsPostgresLayerProperty
QList<int> srids;
unsigned int nSpCols;
QString sql;
bool force2d;
QString relKind;
bool isView;
QString tableComment;
@@ -109,7 +108,6 @@ struct QgsPostgresLayerProperty
property.pkCols = pkCols;
property.nSpCols = nSpCols;
property.sql = sql;
property.force2d = force2d;
property.relKind = relKind;
property.isView = isView;
property.tableComment = tableComment;
@@ -135,16 +133,15 @@ struct QgsPostgresLayerProperty
sridString += QString::number( srid );
}

return QStringLiteral( "%1.%2.%3 type=%4 srid=%5 pkCols=%6 sql=%7 nSpCols=%8 force2d=%9" )
return QStringLiteral( "%1.%2.%3 type=%4 srid=%5 pkCols=%6 sql=%7 nSpCols=%8" )
.arg( schemaName,
tableName,
geometryColName,
typeString,
sridString,
pkCols.join( QStringLiteral( "|" ) ),
sql )
.arg( nSpCols )
.arg( force2d ? "yes" : "no" );
.arg( nSpCols );
}
#endif
};
@@ -517,18 +517,6 @@ bool QgsPostgresFeatureIterator::declareCursor( const QString &whereClause, long
mSource->mSpatialColType == SctPcPatch )
geom += QLatin1String( "::geometry" );

if ( mSource->mForce2d )
{
geom = QStringLiteral( "%1(%2)" )
// Force_2D before 2.0
.arg( mConn->majorVersion() < 2 ? "force_2d"
// ST_Force2D since 2.1.0
: mConn->majorVersion() > 2 || mConn->minorVersion() > 0 ? "st_force2d"
// ST_Force_2D in 2.0.x
: "st_force_2d",
geom );
}

QgsWkbTypes::Type usedGeomType = mSource->mRequestedGeomType != QgsWkbTypes::Unknown
? mSource->mRequestedGeomType : mSource->mDetectedGeomType;

@@ -842,7 +830,6 @@ QgsPostgresFeatureSource::QgsPostgresFeatureSource( const QgsPostgresProvider *p
, mSpatialColType( p->mSpatialColType )
, mRequestedSrid( p->mRequestedSrid )
, mDetectedSrid( p->mDetectedSrid )
, mForce2d( p->mForce2d )
, mRequestedGeomType( p->mRequestedGeomType )
, mDetectedGeomType( p->mDetectedGeomType )
, mPrimaryKeyType( p->mPrimaryKeyType )
@@ -44,7 +44,6 @@ class QgsPostgresFeatureSource : public QgsAbstractFeatureSource
QgsPostgresGeometryColumnType mSpatialColType;
QString mRequestedSrid;
QString mDetectedSrid;
bool mForce2d;
QgsWkbTypes::Type mRequestedGeomType; //! geometry type requested in the uri
QgsWkbTypes::Type mDetectedGeomType; //! geometry type detected in the database
QgsPostgresPrimaryKeyType mPrimaryKeyType;
@@ -3523,7 +3523,6 @@ bool QgsPostgresProvider::getGeometryDetails()
}
layerProperty.geometryColName = mGeometryColumn;
layerProperty.geometryColType = mSpatialColType;
layerProperty.force2d = false;

QString delim;

@@ -3565,7 +3564,6 @@ bool QgsPostgresProvider::getGeometryDetails()
// only what we requested is available
mDetectedGeomType = layerProperty.types.at( 0 );
mDetectedSrid = QString::number( layerProperty.srids.at( 0 ) );
mForce2d = layerProperty.force2d;
}
}
else
@@ -3580,7 +3578,6 @@ bool QgsPostgresProvider::getGeometryDetails()
QgsDebugMsg( QString( "Requested SRID is %1" ).arg( mRequestedSrid ) );
QgsDebugMsg( QString( "Detected type is %1" ).arg( mDetectedGeomType ) );
QgsDebugMsg( QString( "Requested type is %1" ).arg( mRequestedGeomType ) );
QgsDebugMsg( QString( "Force to 2D %1" ).arg( mForce2d ? "Yes" : "No" ) );

mValid = ( mDetectedGeomType != QgsWkbTypes::Unknown || mRequestedGeomType != QgsWkbTypes::Unknown )
&& ( !mDetectedSrid.isEmpty() || !mRequestedSrid.isEmpty() );
@@ -370,7 +370,6 @@ class QgsPostgresProvider : public QgsVectorDataProvider
mutable QgsRectangle mLayerExtent; //! Rectangle that contains the extent (bounding box) of the layer

QgsWkbTypes::Type mDetectedGeomType = QgsWkbTypes::Unknown ; //! geometry type detected in the database
bool mForce2d = false; //! geometry type needs to be forced to 2d (e.g., ZM)
QgsWkbTypes::Type mRequestedGeomType = QgsWkbTypes::Unknown ; //! geometry type requested in the uri
QString mDetectedSrid; //! Spatial reference detected in the database
QString mRequestedSrid; //! Spatial reference requested in the uri

0 comments on commit 6a4b8b4

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