Skip to content

Commit

Permalink
Read the geographic extent from project
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere committed Mar 10, 2021
1 parent b6e01f9 commit 476ebec
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 58 deletions.
37 changes: 10 additions & 27 deletions python/core/auto_generated/qgsmaplayer.sip.in
Expand Up @@ -503,6 +503,15 @@ Returns new instance of :py:class:`QgsMapLayerRenderer` that will be used for re
virtual QgsRectangle extent() const;
%Docstring
Returns the extent of the layer.
%End

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

.. seealso:: :py:func:`setExtent`

.. versionadded:: 3.18
%End

bool isValid() const;
Expand Down Expand Up @@ -1700,24 +1709,7 @@ Copies attributes like name, short name, ... into another layer.
Sets the ``extent`` in layer CRS.

If the layer CRS is not EPSG:4326 and the geographic extent is
known, using :py:func:`~QgsMapLayer.setExtents` is faster.

.. seealso:: :py:func:`setExtents`
%End

virtual void setExtents( const QgsRectangle &extent, const QgsRectangle &geographicExtent );
%Docstring
Simultaneously sets the ``extent`` and the ``geographicExtent``.

This call can be used to skip the costly coordinate transformation when setting
the layer extent in case the geographic extent is already known (e.g. when loading
a project).

.. seealso:: :py:func:`setExtent`

.. seealso:: :py:func:`geographicExtent`

.. versionadded:: 3.18
known.
%End

void setValid( bool valid );
Expand Down Expand Up @@ -1847,15 +1839,6 @@ this method is now deprecated and always return ``False``, because circular depe



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

.. seealso:: :py:func:`setExtent`

.. versionadded:: 3.18
%End

};

QFlags<QgsMapLayer::LayerFlag> operator|(QgsMapLayer::LayerFlag f1, QFlags<QgsMapLayer::LayerFlag> f2);
Expand Down
16 changes: 10 additions & 6 deletions src/core/qgsmaplayer.cpp
Expand Up @@ -392,6 +392,16 @@ bool QgsMapLayer::readLayerXml( const QDomElement &layerElement, QgsReadWriteCon
setRefreshOnNofifyMessage( layerElement.attribute( QStringLiteral( "refreshOnNotifyMessage" ), QString() ) );
setRefreshOnNotifyEnabled( layerElement.attribute( QStringLiteral( "refreshOnNotifyEnabled" ), QStringLiteral( "0" ) ).toInt() );

// geographic extent
// if ( mReadExtentFromXml )
// {
QDomNode geoExtentNode = layerElement.namedItem( QStringLiteral( "geographicExtent" ) );
if ( !geoExtentNode.isNull() )
{
mGeographicExtent = QgsXmlUtils::readRectangle( geoExtentNode.toElement() );
}
// }

return ! layerError;
} // bool QgsMapLayer::readLayerXML

Expand Down Expand Up @@ -1907,12 +1917,6 @@ void QgsMapLayer::setExtent( const QgsRectangle &extent )
mGeographicExtent = transformer.transform( extent );
}

void QgsMapLayer::setExtents( const QgsRectangle &extent, const QgsRectangle &geographicExtent )
{
mExtent = extent;
mGeographicExtent = geographicExtent;
}

bool QgsMapLayer::isReadOnly() const
{
return true;
Expand Down
34 changes: 9 additions & 25 deletions src/core/qgsmaplayer.h
Expand Up @@ -514,6 +514,14 @@ class CORE_EXPORT QgsMapLayer : public QObject
//! Returns the extent of the layer.
virtual QgsRectangle extent() const;

/**
* Returns the geographic extent (EPSG:4326) of the layer.
*
* \see setExtent()
* \since QGIS 3.18
*/
QgsRectangle geographicExtent() const;

/**
* Returns the status of the layer. An invalid layer is one which has a bad datasource
* or other problem. Child classes set this flag when initialized.
Expand Down Expand Up @@ -1516,26 +1524,10 @@ class CORE_EXPORT QgsMapLayer : public QObject
* Sets the \a extent in layer CRS.
*
* If the layer CRS is not EPSG:4326 and the geographic extent is
* known, using setExtents() is faster.
*
* \see setExtents()
* known.
*/
virtual void setExtent( const QgsRectangle &extent );

/**
* Simultaneously sets the \a extent and the \a geographicExtent.
*
* This call can be used to skip the costly coordinate transformation when setting
* the layer extent in case the geographic extent is already known (e.g. when loading
* a project).
*
* \see setExtent()
* \see geographicExtent()
*
* \since QGIS 3.18
*/
virtual void setExtents( const QgsRectangle &extent, const QgsRectangle &geographicExtent );

//! Sets whether layer is valid or not
void setValid( bool valid );

Expand Down Expand Up @@ -1700,14 +1692,6 @@ class CORE_EXPORT QgsMapLayer : public QObject
*/
double mLayerOpacity = 1.0;

/**
* Returns the geographic extent (EPSG:4326) of the layer.
*
* \see setExtent()
* \since QGIS 3.18
*/
QgsRectangle geographicExtent() const;

private:

virtual QString baseURI( PropertyType type ) const;
Expand Down

0 comments on commit 476ebec

Please sign in to comment.