Skip to content
Permalink
Browse files

Add an actual parameter to geographicExtent to bypass the trust option

  • Loading branch information
pblottiere committed Mar 10, 2021
1 parent cb633ed commit 36b77764bf48d6dbd518a42d46c470b3fa47fd4d
Showing with 23 additions and 7 deletions.
  1. +1 −1 python/core/auto_generated/qgsmaplayer.sip.in
  2. +21 −5 src/core/qgsmaplayer.cpp
  3. +1 −1 src/core/qgsmaplayer.h
@@ -505,7 +505,7 @@ Returns new instance of :py:class:`QgsMapLayerRenderer` that will be used for re
Returns the extent of the layer.
%End

QgsRectangle geographicExtent() const;
QgsRectangle geographicExtent( bool actual = false ) const;
%Docstring
Returns the geographic extent (EPSG:4326) of the layer.

@@ -419,7 +419,7 @@ bool QgsMapLayer::writeLayerXml( QDomElement &layerElement, QDomDocument &docume
if ( !extent().isNull() )
{
layerElement.appendChild( QgsXmlUtils::writeRectangle( mExtent, document ) );
layerElement.appendChild( QgsXmlUtils::writeRectangle( mExtent, document, QStringLiteral( "geographicExtent" ) ) );
layerElement.appendChild( QgsXmlUtils::writeRectangle( geographicExtent( true ), document, QStringLiteral( "geographicExtent" ) ) );
}

layerElement.setAttribute( QStringLiteral( "autoRefreshTime" ), QString::number( mRefreshTimer->interval() ) );
@@ -1911,8 +1911,6 @@ void QgsMapLayer::emitStyleChanged()
void QgsMapLayer::setExtent( const QgsRectangle &extent )
{
mExtent = extent;
const QgsCoordinateTransform transformer { crs(), QgsCoordinateReferenceSystem::fromEpsgId( 4326 ), transformContext() };
mGeographicExtent = transformer.transform( extent );
}

bool QgsMapLayer::isReadOnly() const
@@ -2013,7 +2011,25 @@ void QgsMapLayer::onNotified( const QString &message )
}
}

QgsRectangle QgsMapLayer::geographicExtent() const
QgsRectangle QgsMapLayer::geographicExtent( bool actual ) const
{
return mGeographicExtent;
QgsRectangle geoExtent;

if ( mReadFlags & QgsMapLayer::ReadFlag::FlagTrustLayerMetadata and not actual )
{
geoExtent = mGeographicExtent;
}
else
{
const QgsCoordinateTransform transformer { crs(), QgsCoordinateReferenceSystem::fromOgcWmsCrs( geoEpsgCrsAuthId() ), transformContext() };
try
{
geoExtent = transformer.transformBoundingBox( mExtent );
}
catch ( const QgsCsException &cse )
{
geoExtent = QgsRectangle();
}
}
return geoExtent;
}
@@ -520,7 +520,7 @@ class CORE_EXPORT QgsMapLayer : public QObject
* \see setExtent()
* \since QGIS 3.18
*/
QgsRectangle geographicExtent() const;
QgsRectangle geographicExtent( bool actual = false ) const;

/**
* Returns the status of the layer. An invalid layer is one which has a bad datasource

0 comments on commit 36b7776

Please sign in to comment.