QGIS API Documentation  2.12.0-Lyon
qgsalignraster.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsalignraster.h
3  --------------------------------------
4  Date : June 2015
5  Copyright : (C) 2015 by Martin Dobias
6  Email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSALIGNRASTER_H
17 #define QGSALIGNRASTER_H
18 
19 #include <QList>
20 #include <QPointF>
21 #include <QSizeF>
22 #include <QString>
23 
25 
26 typedef void* GDALDatasetH;
27 
28 
38 class ANALYSIS_EXPORT QgsAlignRaster
39 {
40  public:
42 
44  struct ANALYSIS_EXPORT RasterInfo
45  {
46  public:
48  RasterInfo( const QString& layerpath );
49  ~RasterInfo();
50 
52  bool isValid() const { return mDataset != 0; }
53 
55  QString crs() const { return mCrsWkt; }
57  QSize rasterSize() const { return QSize( mXSize, mYSize ); }
59  int bandCount() const { return mBandCnt; }
61  QSizeF cellSize() const;
63  QPointF gridOffset() const;
65  QgsRectangle extent() const;
67  QPointF origin() const;
68 
70  void dump() const;
71 
73  double identify( double mx, double my );
74 
75  protected:
81  double mGeoTransform[6];
83  int mXSize, mYSize;
85  int mBandCnt;
86 
87  friend class QgsAlignRaster;
88  };
89 
90 
93  {
96  RA_Cubic = 2,
98  RA_Lanczos = 4,
99  RA_Average = 5,
100  RA_Mode = 6
101  };
102 
104  struct Item
105  {
106  Item( const QString& input, const QString& output )
107  : inputFilename( input )
108  , outputFilename( output )
109  , resampleMethod( RA_NearestNeighbour )
110  , rescaleValues( false )
111  , srcCellSizeInDestCRS( 0.0 )
112  {}
113 
122 
123  // private part
124 
127  };
128  typedef QList<Item> List;
129 
132  {
136  virtual bool progress( double complete ) = 0;
137 
138  virtual ~ProgressHandler() {}
139  };
140 
142  void setProgressHandler( ProgressHandler* progressHandler ) { mProgressHandler = progressHandler; }
144  ProgressHandler* progressHandler() const { return mProgressHandler; }
145 
147  void setRasters( const List& list ) { mRasters = list; }
149  List rasters() const { return mRasters; }
150 
151  void setGridOffset( const QPointF& offset ) { mGridOffsetX = offset.x(); mGridOffsetY = offset.y(); }
152  QPointF gridOffset() const { return QPointF( mGridOffsetX, mGridOffsetY ); }
153 
155  void setCellSize( double x, double y ) { return setCellSize( QSizeF( x, y ) ); }
157  void setCellSize( const QSizeF& size ) { mCellSizeX = size.width(); mCellSizeY = size.height(); }
159  QSizeF cellSize() const { return QSizeF( mCellSizeX, mCellSizeY ); }
160 
162  void setDestinationCRS( const QString& crsWkt ) { mCrsWkt = crsWkt; }
164  QString destinationCRS() const { return mCrsWkt; }
165 
168  void setClipExtent( double xmin, double ymin, double xmax, double ymax );
171  void setClipExtent( const QgsRectangle& extent );
174  QgsRectangle clipExtent() const;
175 
185  bool setParametersFromRaster( const RasterInfo& rasterInfo, const QString& customCRSWkt = QString(), QSizeF customCellSize = QSizeF(), QPointF customGridOffset = QPointF( -1, -1 ) );
188  bool setParametersFromRaster( const QString& filename, const QString& customCRSWkt = QString(), QSizeF customCellSize = QSizeF(), QPointF customGridOffset = QPointF( -1, -1 ) );
189 
192  bool checkInputParameters();
193 
196  QSize alignedRasterSize() const;
199  QgsRectangle alignedRasterExtent() const;
200 
203  bool run();
204 
207  QString errorMessage() const { return mErrorMessage; }
208 
210  void dump() const;
211 
213  int suggestedReferenceLayer() const;
214 
215  protected:
216 
218  bool createAndWarp( const Item& raster );
219 
221  static bool suggestedWarpOutput( const RasterInfo& info, const QString& destWkt, QSizeF* cellSize = 0, QPointF* gridOffset = 0, QgsRectangle* rect = 0 );
222 
223  protected:
224 
225  // set by the client
226 
229 
232 
234  List mRasters;
235 
239  double mCellSizeX, mCellSizeY;
241  double mGridOffsetX, mGridOffsetY;
242 
245  double mClipExtent[4];
246 
247  // derived data from other members
248 
250  double mGeoTransform[6];
252  int mXSize, mYSize;
253 
254 };
255 
256 
257 #endif // QGSALIGNRASTER_H
A rectangle specified with double values.
Definition: qgsrectangle.h:35
QPointF gridOffset() const
QSizeF cellSize() const
Get output cell size.
bool rescaleValues
rescaling of values according to the change of pixel size
Nearest neighbour (select on one input pixel)
List mRasters
List of rasters to be aligned (with their output files and other options)
void setGridOffset(const QPointF &offset)
Bilinear (2x2 kernel)
Mode (selects the value which appears most often of all the sampled points)
QString outputFilename
filename of the newly created aligned raster (will be overwritten if exists already) ...
Cubic Convolution Approximation (4x4 kernel)
int mBandCnt
number of raster's bands
qreal x() const
qreal y() const
void setRasters(const List &list)
Set list of rasters that will be aligned.
ProgressHandler * progressHandler() const
Get associated progress handler. May be NULL (default)
QSize rasterSize() const
Return size of the raster grid in pixels.
Definition of one raster layer for alignment.
QgsAlignRaster takes one or more raster layers and warps (resamples) them so they have the same: ...
Helper struct to be sub-classed for progress reporting.
double srcCellSizeInDestCRS
used for rescaling of values (if necessary)
QList< Item > List
bool isValid() const
Check whether the given path is a valid raster.
void * GDALDatasetH
QString mCrsWkt
CRS stored in WKT format.
ResampleAlg
Resampling algorithm to be used (equivalent to GDAL's enum GDALResampleAlg)
Average (computes the average of all non-NODATA contributing pixels)
int bandCount() const
Return number of raster bands in the file.
QString errorMessage() const
Return error from a previous run() call.
Item(const QString &input, const QString &output)
void setDestinationCRS(const QString &crsWkt)
Set the output CRS in WKT format.
void setProgressHandler(ProgressHandler *progressHandler)
Assign a progress handler instance. Does not take ownership. NULL can be passed.
void setCellSize(double x, double y)
Set output cell size.
ResampleAlg resampleMethod
resampling method to be used
QString destinationCRS() const
Get the output CRS in WKT format.
QString mErrorMessage
Last error message from run()
Cubic B-Spline Approximation (4x4 kernel)
QString inputFilename
filename of the source raster
void setCellSize(const QSizeF &size)
Set output cell size.
Lanczos windowed sinc interpolation (6x6 kernel)
QString crs() const
Return CRS in WKT format.
qreal height() const
List rasters() const
Get list of rasters that will be aligned.
GDALDatasetH mDataset
handle to open GDAL dataset
Utility class for gathering information about rasters.
QString mCrsWkt
Destination CRS - stored in well-known text (WKT) format.
qreal width() const
ProgressHandler * mProgressHandler
Object that facilitates reporting of progress / cancellation.