mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-05 00:09:32 -04:00
[ogr] Only retrieve layer crs once
Instead of retrieving and converting the layer crs with every call to ::crs(), just read it once when determining the layer properties and store for later retrieval. Speeds up construction of OGR feature sources, which occurs on the main thread when starting a new map render and adds significant cost to the map render preparation.
This commit is contained in:
parent
cd3a1d0710
commit
5142e4995a
@ -830,6 +830,20 @@ void QgsOgrProvider::loadFields()
|
||||
QMutexLocker locker( mutex );
|
||||
mOGRGeomType = getOgrGeomType( mGDALDriverName, ogrLayer );
|
||||
}
|
||||
|
||||
mCrs = QgsCoordinateReferenceSystem();
|
||||
if ( mOGRGeomType != wkbNone )
|
||||
{
|
||||
if ( OGRSpatialReferenceH spatialRefSys = mOgrLayer->GetSpatialRef() )
|
||||
{
|
||||
mCrs = QgsOgrUtils::OGRSpatialReferenceToCrs( spatialRefSys );
|
||||
}
|
||||
else
|
||||
{
|
||||
QgsDebugMsgLevel( QStringLiteral( "no spatial reference found" ), 2 );
|
||||
}
|
||||
}
|
||||
|
||||
QgsOgrFeatureDefn &fdef = mOgrLayer->GetLayerDefn();
|
||||
|
||||
// Expose the OGR FID if it comes from a "real" column (typically GPKG)
|
||||
@ -3866,18 +3880,9 @@ QgsCoordinateReferenceSystem QgsOgrProvider::crs() const
|
||||
{
|
||||
QgsCoordinateReferenceSystem srs;
|
||||
if ( !mValid || ( mOGRGeomType == wkbNone ) )
|
||||
return srs;
|
||||
return QgsCoordinateReferenceSystem();
|
||||
|
||||
if ( OGRSpatialReferenceH spatialRefSys = mOgrLayer->GetSpatialRef() )
|
||||
{
|
||||
srs = QgsOgrUtils::OGRSpatialReferenceToCrs( spatialRefSys );
|
||||
}
|
||||
else
|
||||
{
|
||||
QgsDebugMsgLevel( QStringLiteral( "no spatial reference found" ), 2 );
|
||||
}
|
||||
|
||||
return srs;
|
||||
return mCrs;
|
||||
}
|
||||
|
||||
QString QgsOgrProvider::dataComment() const
|
||||
|
@ -304,6 +304,7 @@ class QgsOgrProvider final: public QgsVectorDataProvider
|
||||
bool mValid = false;
|
||||
|
||||
OGRwkbGeometryType mOGRGeomType = wkbUnknown;
|
||||
QgsCoordinateReferenceSystem mCrs;
|
||||
|
||||
//! Whether the next call to featureCount() should refresh the feature count
|
||||
mutable bool mRefreshFeatureCount = true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user