Skip to content

Commit

Permalink
[postgis] Cache unknown CRS information
Browse files Browse the repository at this point in the history
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 Aug 5, 2017
1 parent a3bd321 commit 29b8853
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/providers/postgres/qgspostgresprovider.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3950,9 +3950,21 @@ QgsCoordinateReferenceSystem QgsPostgresProvider::crs() const
srs.createFromSrid( srid ); srs.createFromSrid( srid );
if ( !srs.isValid() ) if ( !srs.isValid() )
{ {
QgsPostgresResult result( connectionRO()->PQexec( QStringLiteral( "SELECT proj4text FROM spatial_ref_sys WHERE srid=%1" ).arg( srid ) ) ); static QMap<int, QgsCoordinateReferenceSystem> sCrsCache;
if ( result.PQresultStatus() == PGRES_TUPLES_OK ) if ( sCrsCache.contains( srid ) )
srs = QgsCoordinateReferenceSystem::fromProj4( result.PQgetvalue( 0, 0 ) ); 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; return srs;
} }
Expand Down

0 comments on commit 29b8853

Please sign in to comment.