Skip to content

Commit

Permalink
Add an actual parameter to geographicExtent to bypass the trust option
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere committed Mar 10, 2021
1 parent cb633ed commit 36b7776
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion python/core/auto_generated/qgsmaplayer.sip.in
Expand Up @@ -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.

Expand Down
26 changes: 21 additions & 5 deletions src/core/qgsmaplayer.cpp
Expand Up @@ -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() ) );
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion src/core/qgsmaplayer.h
Expand Up @@ -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
Expand Down

0 comments on commit 36b7776

Please sign in to comment.