mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-08 00:05:09 -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 );
|
QMutexLocker locker( mutex );
|
||||||
mOGRGeomType = getOgrGeomType( mGDALDriverName, ogrLayer );
|
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();
|
QgsOgrFeatureDefn &fdef = mOgrLayer->GetLayerDefn();
|
||||||
|
|
||||||
// Expose the OGR FID if it comes from a "real" column (typically GPKG)
|
// Expose the OGR FID if it comes from a "real" column (typically GPKG)
|
||||||
@ -3866,18 +3880,9 @@ QgsCoordinateReferenceSystem QgsOgrProvider::crs() const
|
|||||||
{
|
{
|
||||||
QgsCoordinateReferenceSystem srs;
|
QgsCoordinateReferenceSystem srs;
|
||||||
if ( !mValid || ( mOGRGeomType == wkbNone ) )
|
if ( !mValid || ( mOGRGeomType == wkbNone ) )
|
||||||
return srs;
|
return QgsCoordinateReferenceSystem();
|
||||||
|
|
||||||
if ( OGRSpatialReferenceH spatialRefSys = mOgrLayer->GetSpatialRef() )
|
return mCrs;
|
||||||
{
|
|
||||||
srs = QgsOgrUtils::OGRSpatialReferenceToCrs( spatialRefSys );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
QgsDebugMsgLevel( QStringLiteral( "no spatial reference found" ), 2 );
|
|
||||||
}
|
|
||||||
|
|
||||||
return srs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QgsOgrProvider::dataComment() const
|
QString QgsOgrProvider::dataComment() const
|
||||||
|
@ -304,6 +304,7 @@ class QgsOgrProvider final: public QgsVectorDataProvider
|
|||||||
bool mValid = false;
|
bool mValid = false;
|
||||||
|
|
||||||
OGRwkbGeometryType mOGRGeomType = wkbUnknown;
|
OGRwkbGeometryType mOGRGeomType = wkbUnknown;
|
||||||
|
QgsCoordinateReferenceSystem mCrs;
|
||||||
|
|
||||||
//! Whether the next call to featureCount() should refresh the feature count
|
//! Whether the next call to featureCount() should refresh the feature count
|
||||||
mutable bool mRefreshFeatureCount = true;
|
mutable bool mRefreshFeatureCount = true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user