Skip to content

Commit b6bc1ee

Browse files
committedApr 17, 2019
Tweak QgsProcessingUtils::combineLayerExtents for future proofing, remove deprecated usage
1 parent 82f2cb1 commit b6bc1ee

File tree

15 files changed

+26
-24
lines changed

15 files changed

+26
-24
lines changed
 

‎python/core/auto_generated/processing/qgsprocessingutils.sip.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,11 @@ temporary layer store.
177177
%End
178178

179179

180-
static QgsRectangle combineLayerExtents( const QList<QgsMapLayer *> &layers, const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &transformContext );
180+
static QgsRectangle combineLayerExtents( const QList<QgsMapLayer *> &layers, const QgsCoordinateReferenceSystem &crs, QgsProcessingContext &context );
181181
%Docstring
182182
Combines the extent of several map ``layers``. If specified, the target ``crs``
183183
will be used to transform the layer's extent to the desired output reference system
184-
using the specified ``transformContext``.
184+
using the specified ``context``.
185185

186186
.. versionadded:: 3.10
187187
%End

‎python/plugins/processing/algs/grass7/Grass7Algorithm.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -489,9 +489,9 @@ def processInputs(self, parameters, context, feedback):
489489
elif layer.type() == QgsMapLayerType.VectorLayer:
490490
self.loadVectorLayer(layerName, layer, external=None, feedback=feedback)
491491

492-
self.postInputs()
492+
self.postInputs(context)
493493

494-
def postInputs(self):
494+
def postInputs(self, context):
495495
"""
496496
After layer imports, we need to update some internal parameters
497497
"""
@@ -500,7 +500,7 @@ def postInputs(self):
500500

501501
# Build GRASS region
502502
if self.region.isEmpty():
503-
self.region = QgsProcessingUtils.combineLayerExtents(self.inputLayers)
503+
self.region = QgsProcessingUtils.combineLayerExtents(self.inputLayers, context)
504504
command = 'g.region n={} s={} e={} w={}'.format(
505505
self.region.yMaximum(), self.region.yMinimum(),
506506
self.region.xMaximum(), self.region.xMinimum()

‎python/plugins/processing/algs/grass7/ext/r_blend_combine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def processInputs(alg, parameters, context, feedback):
3333
# Use v.in.ogr
3434
for name in ['first', 'second']:
3535
alg.loadRasterLayerFromParameter(name, parameters, context, False, None)
36-
alg.postInputs()
36+
alg.postInputs(context)
3737

3838

3939
def processOutputs(alg, parameters, context, feedback):

‎python/plugins/processing/algs/grass7/ext/r_blend_rgb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def processInputs(alg, parameters, context, feedback):
3737
# Use v.in.ogr
3838
for name in ['first', 'second']:
3939
alg.loadRasterLayerFromParameter(name, parameters, context, False, None)
40-
alg.postInputs()
40+
alg.postInputs(context)
4141

4242

4343
def processCommand(alg, parameters, context, feedback):

‎python/plugins/processing/algs/grass7/ext/r_category.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def processInputs(alg, parameters, context, feedback):
5252
parameters, context,
5353
False, None)
5454
alg.loadRasterLayerFromParameter('map', parameters, context)
55-
alg.postInputs()
55+
alg.postInputs(context)
5656

5757

5858
def processCommand(alg, parameters, context, feedback):

‎python/plugins/processing/algs/grass7/ext/r_colors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def processInputs(alg, parameters, context, feedback):
5454
if raster:
5555
alg.loadRasterLayerFromParameter('raster', parameters, context, False, None)
5656

57-
alg.postInputs()
57+
alg.postInputs(context)
5858

5959

6060
def processCommand(alg, parameters, context, feedback):

‎python/plugins/processing/algs/grass7/ext/r_colors_stddev.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def processInputs(alg, parameters, context, feedback):
3535

3636
# We need to import all the bands and color tables of the input raster
3737
alg.loadRasterLayerFromParameter('map', parameters, context, False, None)
38-
alg.postInputs()
38+
alg.postInputs(context)
3939

4040

4141
def processCommand(alg, parameters, context, feedback):

‎python/plugins/processing/algs/grass7/ext/r_null.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def processInputs(alg, parameters, context, feedback):
4242

4343
# We need to import without r.external
4444
alg.loadRasterLayerFromParameter('map', parameters, context, False)
45-
alg.postInputs()
45+
alg.postInputs(context)
4646

4747

4848
def processCommand(alg, parameters, context, feedback):

‎python/plugins/processing/algs/grass7/ext/r_rgb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def processInputs(alg, parameters, context, feedback):
3232

3333
# We need to import all the bands and color tables of the input raster
3434
alg.loadRasterLayerFromParameter('input', parameters, context, False, None)
35-
alg.postInputs()
35+
alg.postInputs(context)
3636

3737

3838
def processCommand(alg, parameters, context, feedback):

‎python/plugins/processing/algs/grass7/ext/v_sample.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ def processInputs(alg, parameters, context, feedback):
3434
# and we can use r.external for the raster
3535
alg.loadVectorLayerFromParameter('input', parameters, context, feedback, False)
3636
alg.loadRasterLayerFromParameter('raster', parameters, context, True)
37-
alg.postInputs()
37+
alg.postInputs(context)

‎python/plugins/processing/algs/grass7/ext/v_to_3d.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ def processInputs(alg, parameters, context, feedback):
4242

4343
# We need to import the vector layer with v.in.ogr
4444
alg.loadVectorLayerFromParameter('input', parameters, context, feedback, False)
45-
alg.postInputs()
45+
alg.postInputs(context)

‎python/plugins/processing/algs/qgis/RasterCalculator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def processAlgorithm(self, parameters, context, feedback):
127127
bbox = transform.transformBoundingBox(bbox)
128128

129129
if bbox.isNull() and layers:
130-
bbox = QgsProcessingUtils.combineLayerExtents(layers, crs)
130+
bbox = QgsProcessingUtils.combineLayerExtents(layers, crs, context)
131131

132132
cellsize = self.parameterAsDouble(parameters, self.CELLSIZE, context)
133133
if cellsize == 0 and not layers:

‎src/core/processing/qgsprocessingutils.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ void QgsProcessingUtils::createFeatureSinkPython( QgsFeatureSink **sink, QString
627627
}
628628

629629

630-
QgsRectangle QgsProcessingUtils::combineLayerExtents( const QList<QgsMapLayer *> &layers, const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &transformContext )
630+
QgsRectangle QgsProcessingUtils::combineLayerExtents( const QList<QgsMapLayer *> &layers, const QgsCoordinateReferenceSystem &crs, QgsProcessingContext &context )
631631
{
632632
QgsRectangle extent;
633633
for ( const QgsMapLayer *layer : layers )
@@ -638,7 +638,7 @@ QgsRectangle QgsProcessingUtils::combineLayerExtents( const QList<QgsMapLayer *>
638638
if ( crs.isValid() )
639639
{
640640
//transform layer extent to target CRS
641-
QgsCoordinateTransform ct( layer->crs(), crs, transformContext );
641+
QgsCoordinateTransform ct( layer->crs(), crs, context.transformContext() );
642642
try
643643
{
644644
QgsRectangle reprojExtent = ct.transformBoundingBox( layer->extent() );
@@ -662,7 +662,8 @@ QgsRectangle QgsProcessingUtils::combineLayerExtents( const QList<QgsMapLayer *>
662662
// Deprecated
663663
QgsRectangle QgsProcessingUtils::combineLayerExtents( const QList<QgsMapLayer *> &layers, const QgsCoordinateReferenceSystem &crs )
664664
{
665-
return QgsProcessingUtils::combineLayerExtents( layers, crs, QgsCoordinateTransformContext( ) );
665+
QgsProcessingContext context;
666+
return QgsProcessingUtils::combineLayerExtents( layers, crs, context );
666667
}
667668

668669
QVariant QgsProcessingUtils::generateIteratingDestination( const QVariant &input, const QVariant &id, QgsProcessingContext &context )

‎src/core/processing/qgsprocessingutils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,10 @@ class CORE_EXPORT QgsProcessingUtils
217217
/**
218218
* Combines the extent of several map \a layers. If specified, the target \a crs
219219
* will be used to transform the layer's extent to the desired output reference system
220-
* using the specified \a transformContext.
220+
* using the specified \a context.
221221
* \since QGIS 3.10
222222
*/
223-
static QgsRectangle combineLayerExtents( const QList<QgsMapLayer *> &layers, const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &transformContext );
223+
static QgsRectangle combineLayerExtents( const QList<QgsMapLayer *> &layers, const QgsCoordinateReferenceSystem &crs, QgsProcessingContext &context );
224224

225225
/**
226226
* Combines the extent of several map \a layers. If specified, the target \a crs

‎tests/src/analysis/testqgsprocessing.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6236,7 +6236,8 @@ void TestQgsProcessing::checkParamValues()
62366236

62376237
void TestQgsProcessing::combineLayerExtent()
62386238
{
6239-
QgsRectangle ext = QgsProcessingUtils::combineLayerExtents( QList< QgsMapLayer *>() );
6239+
QgsProcessingContext context;
6240+
QgsRectangle ext = QgsProcessingUtils::combineLayerExtents( QList< QgsMapLayer *>(), context );
62406241
QVERIFY( ext.isNull() );
62416242

62426243
QString testDataDir = QStringLiteral( TEST_DATA_DIR ) + '/'; //defined in CmakeLists.txt
@@ -6248,20 +6249,20 @@ void TestQgsProcessing::combineLayerExtent()
62486249
QFileInfo fi2( raster2 );
62496250
std::unique_ptr< QgsRasterLayer > r2( new QgsRasterLayer( fi2.filePath(), "R2" ) );
62506251

6251-
ext = QgsProcessingUtils::combineLayerExtents( QList< QgsMapLayer *>() << r1.get() );
6252+
ext = QgsProcessingUtils::combineLayerExtents( QList< QgsMapLayer *>() << r1.get(), context );
62526253
QGSCOMPARENEAR( ext.xMinimum(), 1535375.000000, 10 );
62536254
QGSCOMPARENEAR( ext.xMaximum(), 1535475, 10 );
62546255
QGSCOMPARENEAR( ext.yMinimum(), 5083255, 10 );
62556256
QGSCOMPARENEAR( ext.yMaximum(), 5083355, 10 );
62566257

6257-
ext = QgsProcessingUtils::combineLayerExtents( QList< QgsMapLayer *>() << r1.get() << r2.get() );
6258+
ext = QgsProcessingUtils::combineLayerExtents( QList< QgsMapLayer *>() << r1.get() << r2.get(), context );
62586259
QGSCOMPARENEAR( ext.xMinimum(), 781662, 10 );
62596260
QGSCOMPARENEAR( ext.xMaximum(), 1535475, 10 );
62606261
QGSCOMPARENEAR( ext.yMinimum(), 3339523, 10 );
62616262
QGSCOMPARENEAR( ext.yMaximum(), 5083355, 10 );
62626263

62636264
// with reprojection
6264-
ext = QgsProcessingUtils::combineLayerExtents( QList< QgsMapLayer *>() << r1.get() << r2.get(), QgsCoordinateReferenceSystem::fromEpsgId( 3785 ) );
6265+
ext = QgsProcessingUtils::combineLayerExtents( QList< QgsMapLayer *>() << r1.get() << r2.get(), QgsCoordinateReferenceSystem::fromEpsgId( 3785 ), context );
62656266
QGSCOMPARENEAR( ext.xMinimum(), 1995320, 10 );
62666267
QGSCOMPARENEAR( ext.xMaximum(), 2008833, 10 );
62676268
QGSCOMPARENEAR( ext.yMinimum(), 3523084, 10 );

0 commit comments

Comments
 (0)
Please sign in to comment.