Skip to content

Commit

Permalink
[FEATURE] Allow rendering raster layers outside the reported extent
Browse files Browse the repository at this point in the history
The extent reported by raster layers may be smaller than the area
which can be rendered.
Notably for WMS with symbology that takes more space than the data.

Fix #30251
  • Loading branch information
m-kuhn committed Jul 20, 2019
1 parent 5f96783 commit 6ae23a1
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 44 deletions.
20 changes: 20 additions & 0 deletions python/core/auto_generated/raster/qgsrasterlayer.sip.in
Expand Up @@ -382,6 +382,26 @@ Writes the symbology of the layer into the document provided in SLD 1.0.0 format
.. versionadded:: 3.6
%End

bool ignoreExtent() const;
%Docstring
If the ignoreExtent flag is set, the layer will also render outside the
bounding box reported by the data provider.
To be used for example for WMS layers with labels or symbology that happens
to be drawn outside the data extent.

.. versionadded:: 3.10
%End

void setIgnoreExtent( bool ignoreExtent );
%Docstring
If the ignoreExtent flag is set, the layer will also render outside the
bounding box reported by the data provider.
To be used for example for WMS layers with labels or symbology that happens
to be drawn outside the data extent.

.. versionadded:: 3.10
%End


public slots:
void showStatusMessage( const QString &message );
Expand Down
16 changes: 16 additions & 0 deletions src/core/raster/qgsrasterlayer.cpp
Expand Up @@ -922,6 +922,16 @@ void QgsRasterLayer::computeMinMax( int band,

}

bool QgsRasterLayer::ignoreExtent() const
{
return mIgnoreExtent;
}

void QgsRasterLayer::setIgnoreExtent( bool ignoreExtent )
{
mIgnoreExtent = ignoreExtent;
}


void QgsRasterLayer::setContrastEnhancement( QgsContrastEnhancement::ContrastEnhancementAlgorithm algorithm, QgsRasterMinMaxOrigin::Limits limits, const QgsRectangle &extent, int sampleSize, bool generateLookupTableFlag )
{
Expand Down Expand Up @@ -1702,6 +1712,9 @@ bool QgsRasterLayer::readSymbology( const QDomNode &layer_node, QString &errorMe
setBlendMode( QgsPainting::getCompositionMode( static_cast< QgsPainting::BlendMode >( e.text().toInt() ) ) );
}

QDomElement ignoreExtentElement = layer_node.namedItem( QStringLiteral( "ignoreExtent" ) ).toElement();
mIgnoreExtent = ignoreExtentElement.text() == QStringLiteral( "1" );

readCustomProperties( layer_node );

return true;
Expand Down Expand Up @@ -1892,6 +1905,9 @@ bool QgsRasterLayer::writeSymbology( QDomNode &layer_node, QDomDocument &documen
QDomText blendModeText = document.createTextNode( QString::number( QgsPainting::getBlendModeEnum( blendMode() ) ) );
blendModeElement.appendChild( blendModeText );
layer_node.appendChild( blendModeElement );
QDomElement ignoreExtentElement = document.createElement( QStringLiteral( "ignoreExtent" ) );
ignoreExtentElement.appendChild( document.createTextNode( mIgnoreExtent ? QStringLiteral( "1" ) : QStringLiteral( "0" ) ) );
layer_node.appendChild( ignoreExtentElement );

return true;
}
Expand Down
22 changes: 22 additions & 0 deletions src/core/raster/qgsrasterlayer.h
Expand Up @@ -434,6 +434,26 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
*/
bool writeSld( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsStringMap &props = QgsStringMap() ) const;

/**
* If the ignoreExtent flag is set, the layer will also render outside the
* bounding box reported by the data provider.
* To be used for example for WMS layers with labels or symbology that happens
* to be drawn outside the data extent.
*
* \since QGIS 3.10
*/
bool ignoreExtent() const;

/**
* If the ignoreExtent flag is set, the layer will also render outside the
* bounding box reported by the data provider.
* To be used for example for WMS layers with labels or symbology that happens
* to be drawn outside the data extent.
*
* \since QGIS 3.10
*/
void setIgnoreExtent( bool ignoreExtent );


public slots:
void showStatusMessage( const QString &message );
Expand Down Expand Up @@ -501,6 +521,8 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer

//! To save computations and possible infinite cycle of notifications
QgsRectangle mLastRectangleUsedByRefreshContrastEnhancementIfNeeded;

bool mIgnoreExtent = false;
};

// clazy:excludeall=qstring-allocations
Expand Down
2 changes: 1 addition & 1 deletion src/core/raster/qgsrasterlayerrenderer.cpp
Expand Up @@ -134,7 +134,7 @@ QgsRasterLayerRenderer::QgsRasterLayerRenderer( QgsRasterLayer *layer, QgsRender
}

// clip raster extent to view extent
QgsRectangle myRasterExtent = myProjectedViewExtent.intersect( myProjectedLayerExtent );
QgsRectangle myRasterExtent = layer->ignoreExtent() ? myProjectedViewExtent : myProjectedViewExtent.intersect( myProjectedLayerExtent );
if ( myRasterExtent.isEmpty() )
{
QgsDebugMsg( QStringLiteral( "draw request outside view extent." ) );
Expand Down
68 changes: 25 additions & 43 deletions src/ui/qgsrasterlayerpropertiesbase.ui
Expand Up @@ -239,7 +239,7 @@
</sizepolicy>
</property>
<property name="currentIndex">
<number>2</number>
<number>5</number>
</property>
<widget class="QWidget" name="mOptsPage_Information">
<layout class="QVBoxLayout" name="verticalLayout_20">
Expand Down Expand Up @@ -275,8 +275,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>643</width>
<height>729</height>
<width>652</width>
<height>723</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
Expand Down Expand Up @@ -381,8 +381,8 @@ border-radius: 2px;</string>
<rect>
<x>0</x>
<y>0</y>
<width>643</width>
<height>729</height>
<width>679</width>
<height>709</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_10">
Expand Down Expand Up @@ -969,8 +969,8 @@ border-radius: 2px;</string>
<rect>
<x>0</x>
<y>0</y>
<width>348</width>
<height>446</height>
<width>652</width>
<height>723</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
Expand Down Expand Up @@ -1316,8 +1316,8 @@ border-radius: 2px;</string>
<rect>
<x>0</x>
<y>0</y>
<width>86</width>
<height>42</height>
<width>652</width>
<height>723</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_16">
Expand Down Expand Up @@ -1439,6 +1439,16 @@ border-radius: 2px;</string>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="mIgnoreProviderExtent">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Always render full canvas extent and ignore extent reported by provider&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Activating this option will always request the complete canvas extent when rendering. Even when the extent announced by the provider is smaller than the canvas extent or outside the canvas extent.&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;This is useful if a WMS server announes the extent of the data, but the symbology or labelling takes additional space outside the bounding box.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Always render full canvas extent</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_6">
<property name="orientation">
Expand Down Expand Up @@ -1481,8 +1491,8 @@ border-radius: 2px;</string>
<rect>
<x>0</x>
<y>0</y>
<width>553</width>
<height>193</height>
<width>658</width>
<height>709</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_12">
Expand Down Expand Up @@ -1545,8 +1555,8 @@ border-radius: 2px;</string>
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Cantarell'; font-size:11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Cantarell'; font-size:11pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -1681,8 +1691,8 @@ p, li { white-space: pre-wrap; }
<rect>
<x>0</x>
<y>0</y>
<width>643</width>
<height>729</height>
<width>638</width>
<height>759</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_12">
Expand Down Expand Up @@ -2245,34 +2255,6 @@ p, li { white-space: pre-wrap; }
</tabstops>
<resources>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
</resources>
<connections>
<connection>
Expand Down

0 comments on commit 6ae23a1

Please sign in to comment.