Skip to content
Permalink
Browse files

Read the geographic extent from project

  • Loading branch information
pblottiere committed Mar 10, 2021
1 parent b6e01f9 commit 476ebecbe2319293787c1fbd5644cc028331a06d
Showing with 29 additions and 58 deletions.
  1. +10 −27 python/core/auto_generated/qgsmaplayer.sip.in
  2. +10 −6 src/core/qgsmaplayer.cpp
  3. +9 −25 src/core/qgsmaplayer.h
@@ -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;
@@ -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 );
@@ -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);
@@ -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

@@ -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;
@@ -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.
@@ -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 );

@@ -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;

0 comments on commit 476ebec

Please sign in to comment.