Skip to content

Commit

Permalink
Fix retrieval of 4D geometries (XYZM) from postgres (fixes #17814)
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Jan 17, 2018
1 parent 0304708 commit 6a4b8b4
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 42 deletions.
19 changes: 0 additions & 19 deletions src/providers/postgres/qgspostgresconn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() )
Expand Down Expand Up @@ -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 );
Expand All @@ -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;

Expand Down
7 changes: 2 additions & 5 deletions src/providers/postgres/qgspostgresconn.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ struct QgsPostgresLayerProperty
QList<int> srids;
unsigned int nSpCols;
QString sql;
bool force2d;
QString relKind;
bool isView;
QString tableComment;
Expand Down Expand Up @@ -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;
Expand All @@ -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
};
Expand Down
13 changes: 0 additions & 13 deletions src/providers/postgres/qgspostgresfeatureiterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 )
Expand Down
1 change: 0 additions & 1 deletion src/providers/postgres/qgspostgresfeatureiterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 0 additions & 3 deletions src/providers/postgres/qgspostgresprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3523,7 +3523,6 @@ bool QgsPostgresProvider::getGeometryDetails()
}
layerProperty.geometryColName = mGeometryColumn;
layerProperty.geometryColType = mSpatialColType;
layerProperty.force2d = false;

QString delim;

Expand Down Expand Up @@ -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
Expand All @@ -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() );
Expand Down
1 change: 0 additions & 1 deletion src/providers/postgres/qgspostgresprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6a4b8b4

Please sign in to comment.