Skip to content
Permalink
Browse files

[browser] Fix addition of PostGIS layers with unknown CRS

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 8b51c58ffd1634b99a9aeceb824cda251129053c
Showing with 7 additions and 2 deletions.
  1. +7 −2 src/providers/postgres/qgspostgresdataitems.cpp
@@ -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 );
@@ -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;

0 comments on commit 8b51c58

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