Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 90616dd
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/analysis/processing/qgsalgorithmrasterize.cpp
Expand Up @@ -29,6 +29,7 @@
#include "qgsmaprenderercustompainterjob.h"
#include "gdal.h"
#include "qgsgdalutils.h"
#include "qgslayertree.h"

#include <QtConcurrent>

Expand Down Expand Up @@ -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( ) ) );
}
Expand Down

0 comments on commit 90616dd

Please sign in to comment.