Skip to content

Commit

Permalink
[FEATURE] Add extra resampling methods to align raster tool which are
Browse files Browse the repository at this point in the history
available in GDAL >= 2.0 (max, min, median, q1 and q3)
  • Loading branch information
nyalldawson committed Mar 31, 2016
1 parent a30bf95 commit 6545746
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 22 deletions.
21 changes: 14 additions & 7 deletions python/analysis/raster/qgsalignraster.sip
Expand Up @@ -3,6 +3,7 @@ class QgsAlignRaster
{
%TypeHeaderCode
#include <qgsalignraster.h>
#include <gdal_version.h>
%End

public:
Expand Down Expand Up @@ -47,15 +48,21 @@ class QgsAlignRaster


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

//! Definition of one raster layer for alignment
Expand Down
9 changes: 8 additions & 1 deletion src/analysis/raster/qgsalignraster.h
Expand Up @@ -20,6 +20,7 @@
#include <QPointF>
#include <QSizeF>
#include <QString>
#include <gdal_version.h>

class QgsRectangle;

Expand Down Expand Up @@ -94,6 +95,7 @@ class ANALYSIS_EXPORT QgsAlignRaster


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

//! Definition of one raster layer for alignment
Expand Down
31 changes: 20 additions & 11 deletions src/app/qgsalignrasterdialog.cpp
Expand Up @@ -239,7 +239,7 @@ void QgsAlignRasterDialog::addLayer()
QgsAlignRaster::List list = mAlign->rasters();

QgsAlignRaster::Item item( d.inputFilename(), d.outputFilename() );
item.resampleMethod = ( QgsAlignRaster::ResampleAlg ) d.resampleMethod();
item.resampleMethod = d.resampleMethod();
item.rescaleValues = d.rescaleValues();
list.append( item );

Expand Down Expand Up @@ -276,7 +276,7 @@ void QgsAlignRasterDialog::editLayer()
return;

QgsAlignRaster::Item itemNew( d.inputFilename(), d.outputFilename() );
itemNew.resampleMethod = ( QgsAlignRaster::ResampleAlg ) d.resampleMethod();
itemNew.resampleMethod = d.resampleMethod();
itemNew.rescaleValues = d.rescaleValues();
list[current.row()] = itemNew;
mAlign->setRasters( list );
Expand Down Expand Up @@ -386,11 +386,20 @@ QgsAlignRasterLayerConfigDialog::QgsAlignRasterLayerConfigDialog()
cboLayers->setFilters( QgsMapLayerProxyModel::RasterLayer );

cboResample = new QComboBox( this );
QStringList methods;
methods << tr( "Nearest neighbour" ) << tr( "Bilinear (2x2 kernel)" )
<< tr( "Cubic (4x4 kernel)" ) << tr( "Cubic B-Spline (4x4 kernel)" ) << tr( "Lanczos (6x6 kernel)" )
<< tr( "Average" ) << tr( "Mode" );
cboResample->addItems( methods );
cboResample->addItem( tr( "Nearest neighbour" ), QgsAlignRaster::RA_NearestNeighbour );
cboResample->addItem( tr( "Bilinear (2x2 kernel)" ), QgsAlignRaster::RA_Bilinear );
cboResample->addItem( tr( "Cubic (4x4 kernel)" ), QgsAlignRaster::RA_Cubic );
cboResample->addItem( tr( "Cubic B-Spline (4x4 kernel)" ), QgsAlignRaster::RA_CubicSpline );
cboResample->addItem( tr( "Lanczos (6x6 kernel)" ), QgsAlignRaster::RA_Lanczos );
cboResample->addItem( tr( "Average" ), QgsAlignRaster::RA_Average );
cboResample->addItem( tr( "Mode" ), QgsAlignRaster::RA_Mode );
#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 2000000
cboResample->addItem( tr( "Maximum" ), QgsAlignRaster::RA_Max );
cboResample->addItem( tr( "Minimum" ), QgsAlignRaster::RA_Min );
cboResample->addItem( tr( "Median" ), QgsAlignRaster::RA_Median );
cboResample->addItem( tr( "First Quartile (Q1)" ), QgsAlignRaster::RA_Q1 );
cboResample->addItem( tr( "Third Quartile (Q3)" ), QgsAlignRaster::RA_Q3 );
#endif

editOutput = new QLineEdit( this );
btnBrowse = new QPushButton( tr( "Browse..." ), this );
Expand Down Expand Up @@ -428,9 +437,9 @@ QString QgsAlignRasterLayerConfigDialog::outputFilename() const
return editOutput->text();
}

int QgsAlignRasterLayerConfigDialog::resampleMethod() const
QgsAlignRaster::ResampleAlg QgsAlignRasterLayerConfigDialog::resampleMethod() const
{
return cboResample->currentIndex();
return static_cast< QgsAlignRaster::ResampleAlg >( cboResample->itemData( cboResample->currentIndex() ).toInt() );
}

bool QgsAlignRasterLayerConfigDialog::rescaleValues() const
Expand All @@ -439,11 +448,11 @@ bool QgsAlignRasterLayerConfigDialog::rescaleValues() const
}

void QgsAlignRasterLayerConfigDialog::setItem( const QString& inputFilename, const QString& outputFilename,
int resampleMethod, bool rescaleValues )
QgsAlignRaster::ResampleAlg resampleMethod, bool rescaleValues )
{
cboLayers->setLayer( _rasterLayer( inputFilename ) );
editOutput->setText( outputFilename );
cboResample->setCurrentIndex( resampleMethod );
cboResample->setCurrentIndex( cboResample->findData( resampleMethod ) );
chkRescale->setChecked( rescaleValues );
}

Expand Down
6 changes: 3 additions & 3 deletions src/app/qgsalignrasterdialog.h
Expand Up @@ -16,7 +16,7 @@
#define QGSALIGNRASTERDIALOG_H

#include <QDialog>

#include "qgsalignraster.h"
#include "ui_qgsalignrasterdialog.h"

class QgsAlignRaster;
Expand Down Expand Up @@ -71,10 +71,10 @@ class QgsAlignRasterLayerConfigDialog : public QDialog

QString inputFilename() const;
QString outputFilename() const;
int resampleMethod() const;
QgsAlignRaster::ResampleAlg resampleMethod() const;
bool rescaleValues() const;

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

protected slots:
void browseOutputFilename();
Expand Down

1 comment on commit 6545746

@gioman
Copy link
Contributor

@gioman gioman commented on 6545746 Apr 5, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be exposed also in Processing?

Please sign in to comment.