Skip to content
Permalink
Browse files

[postgis] Cache unknown CRS information

CRS information is queried when setting up a new feature source. This
happens on the main thread (read: blocking). With this patch, at least
this only happens once per srid.
  • Loading branch information
m-kuhn committed Jul 31, 2017
1 parent a3bd321 commit 29b8853046ac9a2b11f88e9a8a543f232572c6c5
Showing with 15 additions and 3 deletions.
  1. +15 −3 src/providers/postgres/qgspostgresprovider.cpp
@@ -3950,9 +3950,21 @@ QgsCoordinateReferenceSystem QgsPostgresProvider::crs() const
srs.createFromSrid( srid );
if ( !srs.isValid() )
{
QgsPostgresResult result( connectionRO()->PQexec( QStringLiteral( "SELECT proj4text FROM spatial_ref_sys WHERE srid=%1" ).arg( srid ) ) );
if ( result.PQresultStatus() == PGRES_TUPLES_OK )
srs = QgsCoordinateReferenceSystem::fromProj4( result.PQgetvalue( 0, 0 ) );
static QMap<int, QgsCoordinateReferenceSystem> sCrsCache;
if ( sCrsCache.contains( srid ) )
srs = sCrsCache.value( srid );
else
{
QgsPostgresConn *conn = connectionRO();
conn->lock();
QgsPostgresResult result( conn->PQexec( QStringLiteral( "SELECT proj4text FROM spatial_ref_sys WHERE srid=%1" ).arg( srid ) ) );
conn->unlock();
if ( result.PQresultStatus() == PGRES_TUPLES_OK )
{
srs = QgsCoordinateReferenceSystem::fromProj4( result.PQgetvalue( 0, 0 ) );
sCrsCache.insert( srid, srs );
}
}
}
return srs;
}

0 comments on commit 29b8853

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