QGIS API Documentation  2.14.0-Essen
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 nullptr != mDataset; }
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  private:
88 
89  RasterInfo( const RasterInfo& rh );
90  RasterInfo& operator=( const RasterInfo& rh );
91 
92  friend class QgsAlignRaster;
93  };
94 
95 
98  {
101  RA_Cubic = 2,
105  RA_Mode = 6
106  };
107 
109  struct Item
110  {
111  Item( const QString& input, const QString& output )
112  : inputFilename( input )
113  , outputFilename( output )
114  , resampleMethod( RA_NearestNeighbour )
115  , rescaleValues( false )
116  , srcCellSizeInDestCRS( 0.0 )
117  {}
118 
127 
128  // private part
129 
132  };
133  typedef QList<Item> List;
134 
137  {
141  virtual bool progress( double complete ) = 0;
142 
143  virtual ~ProgressHandler() {}
144  };
145 
147  void setProgressHandler( ProgressHandler* progressHandler ) { mProgressHandler = progressHandler; }
149  ProgressHandler* progressHandler() const { return mProgressHandler; }
150 
152  void setRasters( const List& list ) { mRasters = list; }
154  List rasters() const { return mRasters; }
155 
156  void setGridOffset( QPointF offset ) { mGridOffsetX = offset.x(); mGridOffsetY = offset.y(); }
157  QPointF gridOffset() const { return QPointF( mGridOffsetX, mGridOffsetY ); }
158 
160  void setCellSize( double x, double y ) { return setCellSize( QSizeF( x, y ) ); }
162  void setCellSize( QSizeF size ) { mCellSizeX = size.width(); mCellSizeY = size.height(); }
164  QSizeF cellSize() const { return QSizeF( mCellSizeX, mCellSizeY ); }
165 
167  void setDestinationCRS( const QString& crsWkt ) { mCrsWkt = crsWkt; }
169  QString destinationCRS() const { return mCrsWkt; }
170 
173  void setClipExtent( double xmin, double ymin, double xmax, double ymax );
176  void setClipExtent( const QgsRectangle& extent );
179  QgsRectangle clipExtent() const;
180 
190  bool setParametersFromRaster( const RasterInfo& rasterInfo, const QString& customCRSWkt = QString(), QSizeF customCellSize = QSizeF(), QPointF customGridOffset = QPointF( -1, -1 ) );
193  bool setParametersFromRaster( const QString& filename, const QString& customCRSWkt = QString(), QSizeF customCellSize = QSizeF(), QPointF customGridOffset = QPointF( -1, -1 ) );
194 
197  bool checkInputParameters();
198 
201  QSize alignedRasterSize() const;
204  QgsRectangle alignedRasterExtent() const;
205 
208  bool run();
209 
212  QString errorMessage() const { return mErrorMessage; }
213 
215  void dump() const;
216 
218  int suggestedReferenceLayer() const;
219 
220  protected:
221 
223  bool createAndWarp( const Item& raster );
224 
226  static bool suggestedWarpOutput( const RasterInfo& info, const QString& destWkt, QSizeF* cellSize = nullptr, QPointF* gridOffset = nullptr, QgsRectangle* rect = nullptr );
227 
228  protected:
229 
230  // set by the client
231 
234 
237 
239  List mRasters;
240 
244  double mCellSizeX, mCellSizeY;
246  double mGridOffsetX, mGridOffsetY;
247 
250  double mClipExtent[4];
251 
252  // derived data from other members
253 
255  double mGeoTransform[6];
257  int mXSize, mYSize;
258 
259 };
260 
261 
262 #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)
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&#39;s bands
void setCellSize(QSizeF size)
Set output cell size.
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 nullptr (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)
void setGridOffset(QPointF offset)
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&#39;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. nullptr 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
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.