QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 #include <gdal_version.h>
24 
26 
27 typedef void* GDALDatasetH;
28 
29 
39 class ANALYSIS_EXPORT QgsAlignRaster
40 {
41  public:
43 
45  struct ANALYSIS_EXPORT RasterInfo
46  {
47  public:
49  RasterInfo( const QString& layerpath );
50  ~RasterInfo();
51 
53  bool isValid() const { return nullptr != mDataset; }
54 
56  QString crs() const { return mCrsWkt; }
58  QSize rasterSize() const { return QSize( mXSize, mYSize ); }
60  int bandCount() const { return mBandCnt; }
62  QSizeF cellSize() const;
64  QPointF gridOffset() const;
66  QgsRectangle extent() const;
68  QPointF origin() const;
69 
71  void dump() const;
72 
74  double identify( double mx, double my );
75 
76  protected:
82  double mGeoTransform[6];
84  int mXSize, mYSize;
86  int mBandCnt;
87 
88  private:
89 
90  RasterInfo( const RasterInfo& rh );
91  RasterInfo& operator=( const RasterInfo& rh );
92 
93  friend class QgsAlignRaster;
94  };
95 
96 
100  {
103  RA_Cubic = 2,
107  RA_Mode = 6,
108  RA_Max = 8,
109  RA_Min = 9,
110  RA_Median = 10,
111  RA_Q1 = 11,
112  RA_Q3 = 12,
113  };
114 
116  struct Item
117  {
118  Item( const QString& input, const QString& output )
119  : inputFilename( input )
120  , outputFilename( output )
121  , resampleMethod( RA_NearestNeighbour )
122  , rescaleValues( false )
123  , srcCellSizeInDestCRS( 0.0 )
124  {}
125 
134 
135  // private part
136 
139  };
140  typedef QList<Item> List;
141 
144  {
148  virtual bool progress( double complete ) = 0;
149 
150  virtual ~ProgressHandler() {}
151  };
152 
154  void setProgressHandler( ProgressHandler* progressHandler ) { mProgressHandler = progressHandler; }
156  ProgressHandler* progressHandler() const { return mProgressHandler; }
157 
159  void setRasters( const List& list ) { mRasters = list; }
161  List rasters() const { return mRasters; }
162 
163  void setGridOffset( QPointF offset ) { mGridOffsetX = offset.x(); mGridOffsetY = offset.y(); }
164  QPointF gridOffset() const { return QPointF( mGridOffsetX, mGridOffsetY ); }
165 
167  void setCellSize( double x, double y ) { return setCellSize( QSizeF( x, y ) ); }
169  void setCellSize( QSizeF size ) { mCellSizeX = size.width(); mCellSizeY = size.height(); }
171  QSizeF cellSize() const { return QSizeF( mCellSizeX, mCellSizeY ); }
172 
174  void setDestinationCRS( const QString& crsWkt ) { mCrsWkt = crsWkt; }
176  QString destinationCRS() const { return mCrsWkt; }
177 
180  void setClipExtent( double xmin, double ymin, double xmax, double ymax );
183  void setClipExtent( const QgsRectangle& extent );
186  QgsRectangle clipExtent() const;
187 
197  bool setParametersFromRaster( const RasterInfo& rasterInfo, const QString& customCRSWkt = QString(), QSizeF customCellSize = QSizeF(), QPointF customGridOffset = QPointF( -1, -1 ) );
200  bool setParametersFromRaster( const QString& filename, const QString& customCRSWkt = QString(), QSizeF customCellSize = QSizeF(), QPointF customGridOffset = QPointF( -1, -1 ) );
201 
204  bool checkInputParameters();
205 
208  QSize alignedRasterSize() const;
211  QgsRectangle alignedRasterExtent() const;
212 
215  bool run();
216 
219  QString errorMessage() const { return mErrorMessage; }
220 
222  void dump() const;
223 
225  int suggestedReferenceLayer() const;
226 
227  protected:
228 
230  bool createAndWarp( const Item& raster );
231 
233  static bool suggestedWarpOutput( const RasterInfo& info, const QString& destWkt, QSizeF* cellSize = nullptr, QPointF* gridOffset = nullptr, QgsRectangle* rect = nullptr );
234 
235  protected:
236 
237  // set by the client
238 
241 
244 
246  List mRasters;
247 
251  double mCellSizeX, mCellSizeY;
253  double mGridOffsetX, mGridOffsetY;
254 
257  double mClipExtent[4];
258 
259  // derived data from other members
260 
262  double mGeoTransform[6];
264  int mXSize, mYSize;
265 
266 };
267 
268 
269 #endif // QGSALIGNRASTER_H
List rasters() const
Get list of rasters that will be aligned.
A rectangle specified with double values.
Definition: qgsrectangle.h:35
bool rescaleValues
rescaling of values according to the change of pixel size
Nearest neighbour (select on one input pixel)
QSize rasterSize() const
Return size of the raster grid in pixels.
List mRasters
List of rasters to be aligned (with their output files and other options)
QString errorMessage() const
Return error from a previous run() call.
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) ...
Median (selects the median of all non-NODATA contributing pixels)
Cubic Convolution Approximation (4x4 kernel)
int bandCount() const
Return number of raster bands in the file.
int mBandCnt
number of raster&#39;s bands
void setCellSize(QSizeF size)
Set output cell size.
qreal x() const
qreal y() const
QString crs() const
Return CRS in WKT format.
void setRasters(const List &list)
Set list of rasters that will be aligned.
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
void * GDALDatasetH
Third quartile (selects the third quartile of all non-NODATA contributing pixels) ...
QString mCrsWkt
CRS stored in WKT format.
ResampleAlg
Resampling algorithm to be used (equivalent to GDAL&#39;s enum GDALResampleAlg)
ProgressHandler * progressHandler() const
Get associated progress handler. May be nullptr (default)
Average (computes the average of all non-NODATA contributing pixels)
Maximum (selects the maximum of all non-NODATA contributing pixels)
Item(const QString &input, const QString &output)
void setDestinationCRS(const QString &crsWkt)
Set the output CRS in WKT format.
First quartile (selects the first quartile of all non-NODATA contributing pixels) ...
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.
bool isValid() const
Check whether the given path is a valid raster.
ResampleAlg resampleMethod
resampling method to be used
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)
qreal height() const
Minimum (selects the minimum of all non-NODATA contributing pixels)
QString destinationCRS() const
Get the output CRS in WKT format.
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.
QPointF gridOffset() const
qreal width() const
ProgressHandler * mProgressHandler
Object that facilitates reporting of progress / cancellation.
QSizeF cellSize() const
Get output cell size.