Skip to content

Commit

Permalink
[browser] Fix addition of PostGIS layers with unknown CRS
Browse files Browse the repository at this point in the history
When a PostGIS table does not have CRS specified (srid == 0) then
it was not possible to correctly load it from browser (but it worked
from DB manager). The problem was that browser item used negative
srid in layer URI, messing up everything.

Also fixed the display of srid in tooltip (it says "unknown" rather
than showing -2147483648)

(cherry picked from commit 6c79fff)
  • Loading branch information
wonder-sk committed Mar 10, 2019
1 parent 6bccc8e commit 8b51c58
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/providers/postgres/qgspostgresdataitems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ QString QgsPGLayerItem::createUri()
QgsDataSourceUri uri( QgsPostgresConn::connUri( connItem->name() ).connectionInfo( false ) );
uri.setDataSource( mLayerProperty.schemaName, mLayerProperty.tableName, mLayerProperty.geometryColName, mLayerProperty.sql, pkColName );
uri.setWkbType( mLayerProperty.types.at( 0 ) );
if ( uri.wkbType() != QgsWkbTypes::NoGeometry )
if ( uri.wkbType() != QgsWkbTypes::NoGeometry && mLayerProperty.srids.at( 0 ) != std::numeric_limits<int>::min() )
uri.setSrid( QString::number( mLayerProperty.srids.at( 0 ) ) );
QgsDebugMsg( QStringLiteral( "layer uri: %1" ).arg( uri.uri( false ) ) );
return uri.uri( false );
Expand Down Expand Up @@ -740,7 +740,12 @@ QgsPGLayerItem *QgsPGSchemaItem::createLayer( QgsPostgresLayerProperty layerProp
tip = tr( "Table" );
}
QgsWkbTypes::Type wkbType = layerProperty.types.at( 0 );
tip += tr( "\n%1 as %2 in %3" ).arg( layerProperty.geometryColName, QgsPostgresConn::displayStringForWkbType( wkbType ) ).arg( layerProperty.srids.at( 0 ) );
tip += tr( "\n%1 as %2" ).arg( layerProperty.geometryColName, QgsPostgresConn::displayStringForWkbType( wkbType ) );
if ( layerProperty.srids.at( 0 ) != std::numeric_limits<int>::min() )
tip += tr( " (srid %1)" ).arg( layerProperty.srids.at( 0 ) );
else
tip += tr( " (unknown srid)" );

if ( !layerProperty.tableComment.isEmpty() )
{
tip = layerProperty.tableComment + '\n' + tip;
Expand Down

0 comments on commit 8b51c58

Please sign in to comment.