Skip to content
Permalink
Browse files

[FEATURE] Add extra resampling methods to align raster tool which are

available in GDAL >= 2.0 (max, min, median, q1 and q3)
  • Loading branch information
nyalldawson committed Mar 31, 2016
1 parent a30bf95 commit 6545746fc6a26cd3b7764d0dd1546c5661ef0d1d
@@ -3,6 +3,7 @@ class QgsAlignRaster
{
%TypeHeaderCode
#include <qgsalignraster.h>
#include <gdal_version.h>
%End

public:
@@ -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
@@ -20,6 +20,7 @@
#include <QPointF>
#include <QSizeF>
#include <QString>
#include <gdal_version.h>

class QgsRectangle;

@@ -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)
@@ -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
@@ -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 );

@@ -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 );
@@ -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 );
@@ -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
@@ -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 );
}

@@ -16,7 +16,7 @@
#define QGSALIGNRASTERDIALOG_H

#include <QDialog>

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

class QgsAlignRaster;
@@ -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();

1 comment on commit 6545746

@gioman

This comment has been minimized.

Copy link
Contributor

@gioman gioman commented on 6545746 Apr 5, 2016

Could this be exposed also in Processing?

Please sign in to comment.
You can’t perform that action at this time.