Skip to content
Permalink
Browse files

Fix wrong list of layers in Rasterize alg (Convert map to raster)

When not using a map theme nor explicit list of layers, the list of layers
is taken from the project. However the algorithm took a list of all layers
in the project, including the ones that were not visible, and the rendering
order was rather arbitrary (sorted by layer IDs I think).

It seems this has been broken since the port from Python to C++ in QGIS 3.12
  • Loading branch information
wonder-sk committed Mar 14, 2021
1 parent 64b869e commit 90616dd42e832cf4a4728a22ff295c72725c79d9
Showing with 11 additions and 2 deletions.
  1. +11 −2 src/analysis/processing/qgsalgorithmrasterize.cpp
@@ -29,6 +29,7 @@
#include "qgsmaprenderercustompainterjob.h"
#include "gdal.h"
#include "qgsgdalutils.h"
#include "qgslayertree.h"

#include <QtConcurrent>

@@ -333,8 +334,16 @@ bool QgsRasterizeAlgorithm::prepareAlgorithm( const QVariantMap &parameters, Qgs
// Still no layers? Get them all from the project
if ( mMapLayers.size() == 0 )
{
const auto constLayers { context.project()->mapLayers().values() };
for ( const QgsMapLayer *ml : constLayers )
QList<QgsMapLayer *> layers;
QgsLayerTree *root = context.project()->layerTreeRoot();
for ( QgsLayerTreeLayer *nodeLayer : root->findLayers() )
{
QgsMapLayer *layer = nodeLayer->layer();
if ( nodeLayer->isVisible() && root->layerOrder().contains( layer ) )
layers << layer;
}

for ( const QgsMapLayer *ml : qgis::as_const( layers ) )
{
mMapLayers.push_back( std::unique_ptr<QgsMapLayer>( ml->clone( ) ) );
}

0 comments on commit 90616dd

Please sign in to comment.