Skip to content

Commit 6545746

Browse files
committed
[FEATURE] Add extra resampling methods to align raster tool which are
available in GDAL >= 2.0 (max, min, median, q1 and q3)
1 parent a30bf95 commit 6545746

File tree

4 files changed

+45
-22
lines changed

4 files changed

+45
-22
lines changed

python/analysis/raster/qgsalignraster.sip

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ class QgsAlignRaster
33
{
44
%TypeHeaderCode
55
#include <qgsalignraster.h>
6+
#include <gdal_version.h>
67
%End
78

89
public:
@@ -47,15 +48,21 @@ class QgsAlignRaster
4748

4849

4950
//! Resampling algorithm to be used (equivalent to GDAL's enum GDALResampleAlg)
51+
//! @note RA_Max, RA_Min, RA_Median, RA_Q1 and RA_Q3 are available on GDAL >= 2.0 builds only
5052
enum ResampleAlg
5153
{
52-
RA_NearestNeighbour = 0, //!< Nearest neighbour (select on one input pixel)
53-
RA_Bilinear = 1, //!< Bilinear (2x2 kernel)
54-
RA_Cubic = 2, //!< Cubic Convolution Approximation (4x4 kernel)
55-
RA_CubicSpline = 3, //!< Cubic B-Spline Approximation (4x4 kernel)
56-
RA_Lanczos = 4, //!< Lanczos windowed sinc interpolation (6x6 kernel)
57-
RA_Average = 5, //!< Average (computes the average of all non-NODATA contributing pixels)
58-
RA_Mode = 6 //!< Mode (selects the value which appears most often of all the sampled points)
54+
RA_NearestNeighbour, //!< Nearest neighbour (select on one input pixel)
55+
RA_Bilinear, //!< Bilinear (2x2 kernel)
56+
RA_Cubic, //!< Cubic Convolution Approximation (4x4 kernel)
57+
RA_CubicSpline, //!< Cubic B-Spline Approximation (4x4 kernel)
58+
RA_Lanczos, //!< Lanczos windowed sinc interpolation (6x6 kernel)
59+
RA_Average, //!< Average (computes the average of all non-NODATA contributing pixels)
60+
RA_Mode, //!< Mode (selects the value which appears most often of all the sampled points)
61+
RA_Max, //!< Maximum (selects the maximum of all non-NODATA contributing pixels)
62+
RA_Min, //!< Minimum (selects the minimum of all non-NODATA contributing pixels)
63+
RA_Median, //!< Median (selects the median of all non-NODATA contributing pixels)
64+
RA_Q1, //!< First quartile (selects the first quartile of all non-NODATA contributing pixels)
65+
RA_Q3, //!< Third quartile (selects the third quartile of all non-NODATA contributing pixels)
5966
};
6067

6168
//! Definition of one raster layer for alignment

src/analysis/raster/qgsalignraster.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <QPointF>
2121
#include <QSizeF>
2222
#include <QString>
23+
#include <gdal_version.h>
2324

2425
class QgsRectangle;
2526

@@ -94,6 +95,7 @@ class ANALYSIS_EXPORT QgsAlignRaster
9495

9596

9697
//! Resampling algorithm to be used (equivalent to GDAL's enum GDALResampleAlg)
98+
//! @note RA_Max, RA_Min, RA_Median, RA_Q1 and RA_Q3 are available on GDAL >= 2.0 builds only
9799
enum ResampleAlg
98100
{
99101
RA_NearestNeighbour = 0, //!< Nearest neighbour (select on one input pixel)
@@ -102,7 +104,12 @@ class ANALYSIS_EXPORT QgsAlignRaster
102104
RA_CubicSpline = 3, //!< Cubic B-Spline Approximation (4x4 kernel)
103105
RA_Lanczos = 4, //!< Lanczos windowed sinc interpolation (6x6 kernel)
104106
RA_Average = 5, //!< Average (computes the average of all non-NODATA contributing pixels)
105-
RA_Mode = 6 //!< Mode (selects the value which appears most often of all the sampled points)
107+
RA_Mode = 6, //!< Mode (selects the value which appears most often of all the sampled points)
108+
RA_Max = 8, //!< Maximum (selects the maximum of all non-NODATA contributing pixels)
109+
RA_Min = 9, //!< Minimum (selects the minimum of all non-NODATA contributing pixels)
110+
RA_Median = 10, //!< Median (selects the median of all non-NODATA contributing pixels)
111+
RA_Q1 = 11, //!< First quartile (selects the first quartile of all non-NODATA contributing pixels)
112+
RA_Q3 = 12, //!< Third quartile (selects the third quartile of all non-NODATA contributing pixels)
106113
};
107114

108115
//! Definition of one raster layer for alignment

src/app/qgsalignrasterdialog.cpp

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ void QgsAlignRasterDialog::addLayer()
239239
QgsAlignRaster::List list = mAlign->rasters();
240240

241241
QgsAlignRaster::Item item( d.inputFilename(), d.outputFilename() );
242-
item.resampleMethod = ( QgsAlignRaster::ResampleAlg ) d.resampleMethod();
242+
item.resampleMethod = d.resampleMethod();
243243
item.rescaleValues = d.rescaleValues();
244244
list.append( item );
245245

@@ -276,7 +276,7 @@ void QgsAlignRasterDialog::editLayer()
276276
return;
277277

278278
QgsAlignRaster::Item itemNew( d.inputFilename(), d.outputFilename() );
279-
itemNew.resampleMethod = ( QgsAlignRaster::ResampleAlg ) d.resampleMethod();
279+
itemNew.resampleMethod = d.resampleMethod();
280280
itemNew.rescaleValues = d.rescaleValues();
281281
list[current.row()] = itemNew;
282282
mAlign->setRasters( list );
@@ -386,11 +386,20 @@ QgsAlignRasterLayerConfigDialog::QgsAlignRasterLayerConfigDialog()
386386
cboLayers->setFilters( QgsMapLayerProxyModel::RasterLayer );
387387

388388
cboResample = new QComboBox( this );
389-
QStringList methods;
390-
methods << tr( "Nearest neighbour" ) << tr( "Bilinear (2x2 kernel)" )
391-
<< tr( "Cubic (4x4 kernel)" ) << tr( "Cubic B-Spline (4x4 kernel)" ) << tr( "Lanczos (6x6 kernel)" )
392-
<< tr( "Average" ) << tr( "Mode" );
393-
cboResample->addItems( methods );
389+
cboResample->addItem( tr( "Nearest neighbour" ), QgsAlignRaster::RA_NearestNeighbour );
390+
cboResample->addItem( tr( "Bilinear (2x2 kernel)" ), QgsAlignRaster::RA_Bilinear );
391+
cboResample->addItem( tr( "Cubic (4x4 kernel)" ), QgsAlignRaster::RA_Cubic );
392+
cboResample->addItem( tr( "Cubic B-Spline (4x4 kernel)" ), QgsAlignRaster::RA_CubicSpline );
393+
cboResample->addItem( tr( "Lanczos (6x6 kernel)" ), QgsAlignRaster::RA_Lanczos );
394+
cboResample->addItem( tr( "Average" ), QgsAlignRaster::RA_Average );
395+
cboResample->addItem( tr( "Mode" ), QgsAlignRaster::RA_Mode );
396+
#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 2000000
397+
cboResample->addItem( tr( "Maximum" ), QgsAlignRaster::RA_Max );
398+
cboResample->addItem( tr( "Minimum" ), QgsAlignRaster::RA_Min );
399+
cboResample->addItem( tr( "Median" ), QgsAlignRaster::RA_Median );
400+
cboResample->addItem( tr( "First Quartile (Q1)" ), QgsAlignRaster::RA_Q1 );
401+
cboResample->addItem( tr( "Third Quartile (Q3)" ), QgsAlignRaster::RA_Q3 );
402+
#endif
394403

395404
editOutput = new QLineEdit( this );
396405
btnBrowse = new QPushButton( tr( "Browse..." ), this );
@@ -428,9 +437,9 @@ QString QgsAlignRasterLayerConfigDialog::outputFilename() const
428437
return editOutput->text();
429438
}
430439

431-
int QgsAlignRasterLayerConfigDialog::resampleMethod() const
440+
QgsAlignRaster::ResampleAlg QgsAlignRasterLayerConfigDialog::resampleMethod() const
432441
{
433-
return cboResample->currentIndex();
442+
return static_cast< QgsAlignRaster::ResampleAlg >( cboResample->itemData( cboResample->currentIndex() ).toInt() );
434443
}
435444

436445
bool QgsAlignRasterLayerConfigDialog::rescaleValues() const
@@ -439,11 +448,11 @@ bool QgsAlignRasterLayerConfigDialog::rescaleValues() const
439448
}
440449

441450
void QgsAlignRasterLayerConfigDialog::setItem( const QString& inputFilename, const QString& outputFilename,
442-
int resampleMethod, bool rescaleValues )
451+
QgsAlignRaster::ResampleAlg resampleMethod, bool rescaleValues )
443452
{
444453
cboLayers->setLayer( _rasterLayer( inputFilename ) );
445454
editOutput->setText( outputFilename );
446-
cboResample->setCurrentIndex( resampleMethod );
455+
cboResample->setCurrentIndex( cboResample->findData( resampleMethod ) );
447456
chkRescale->setChecked( rescaleValues );
448457
}
449458

src/app/qgsalignrasterdialog.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#define QGSALIGNRASTERDIALOG_H
1717

1818
#include <QDialog>
19-
19+
#include "qgsalignraster.h"
2020
#include "ui_qgsalignrasterdialog.h"
2121

2222
class QgsAlignRaster;
@@ -71,10 +71,10 @@ class QgsAlignRasterLayerConfigDialog : public QDialog
7171

7272
QString inputFilename() const;
7373
QString outputFilename() const;
74-
int resampleMethod() const;
74+
QgsAlignRaster::ResampleAlg resampleMethod() const;
7575
bool rescaleValues() const;
7676

77-
void setItem( const QString& inputFilename, const QString& outputFilename, int resampleMethod, bool rescaleValues );
77+
void setItem( const QString& inputFilename, const QString& outputFilename, QgsAlignRaster::ResampleAlg resampleMethod, bool rescaleValues );
7878

7979
protected slots:
8080
void browseOutputFilename();

0 commit comments

Comments
 (0)