QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
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#include "qgis_analysis.h"
25#include "qgis_sip.h"
26#include "qgsogrutils.h"
27#include "qgsalignrasterdata.h"
28
29class QgsRectangle;
30
31typedef void *GDALDatasetH SIP_SKIP;
32
33
44class ANALYSIS_EXPORT QgsAlignRaster
45{
46 //SIP_TYPEHEADER_INCLUDE( "gdal_version.h" );
47
48
49 public:
51
53 struct ANALYSIS_EXPORT RasterInfo
54 {
55 public:
57 RasterInfo( const QString &layerpath );
58
59 RasterInfo( const RasterInfo &rh ) = delete;
60 RasterInfo &operator=( const RasterInfo &rh ) = delete;
61
63 bool isValid() const { return nullptr != mDataset; }
64
66 QString crs() const { return mCrsWkt; }
68 QSize rasterSize() const { return QSize( mXSize, mYSize ); }
70 int bandCount() const { return mBandCnt; }
72 QSizeF cellSize() const;
74 QPointF gridOffset() const;
76 QgsRectangle extent() const;
78 QPointF origin() const;
79
81 void dump() const;
82
84 double identify( double mx, double my );
85
86 protected:
90 QString mCrsWkt;
92 double mGeoTransform[6];
94 int mXSize = 0;
96 int mYSize = 0;
98 int mBandCnt = 0;
99
100 private:
101#ifdef SIP_RUN
103#endif
104
105 friend class QgsAlignRaster;
106 };
107
110 typedef QList<QgsAlignRasterData::RasterItem> List;
111
114 {
120 virtual bool progress( double complete ) = 0;
121
122 virtual ~ProgressHandler() = default;
123 };
124
126 void setProgressHandler( ProgressHandler *progressHandler ) { mProgressHandler = progressHandler; }
128 ProgressHandler *progressHandler() const { return mProgressHandler; }
129
131 void setRasters( const List &list ) { mRasters = list; }
133 List rasters() const { return mRasters; }
134
135 void setGridOffset( QPointF offset )
136 {
137 mGridOffsetX = offset.x();
138 mGridOffsetY = offset.y();
139 }
140 QPointF gridOffset() const { return QPointF( mGridOffsetX, mGridOffsetY ); }
141
143 void setCellSize( double x, double y ) { setCellSize( QSizeF( x, y ) ); }
145 void setCellSize( QSizeF size )
146 {
147 mCellSizeX = size.width();
148 mCellSizeY = size.height();
149 }
151 QSizeF cellSize() const { return QSizeF( mCellSizeX, mCellSizeY ); }
152
154 void setDestinationCrs( const QString &crsWkt ) { mCrsWkt = crsWkt; }
156 QString destinationCrs() const { return mCrsWkt; }
157
162 void setClipExtent( double xmin, double ymin, double xmax, double ymax );
163
168 void setClipExtent( const QgsRectangle &extent );
169
174 QgsRectangle clipExtent() const;
175
187 bool setParametersFromRaster( const RasterInfo &rasterInfo, const QString &customCRSWkt = QString(), QSizeF customCellSize = QSizeF(), QPointF customGridOffset = QPointF( -1, -1 ) );
188
193 bool setParametersFromRaster( const QString &filename, const QString &customCRSWkt = QString(), QSizeF customCellSize = QSizeF(), QPointF customGridOffset = QPointF( -1, -1 ) );
194
199 bool checkInputParameters();
200
205 QSize alignedRasterSize() const;
206
211 QgsRectangle alignedRasterExtent() const;
212
217 bool run();
218
223 QString errorMessage() const { return mErrorMessage; }
224
226 void dump() const;
227
229 int suggestedReferenceLayer() const;
230
231 protected:
233 bool createAndWarp( const Item &raster );
234
236 static bool suggestedWarpOutput( const RasterInfo &info, const QString &destWkt, QSizeF *cellSize = nullptr, QPointF *gridOffset = nullptr, QgsRectangle *rect = nullptr );
237
238 protected:
239 // set by the client
240
242 ProgressHandler *mProgressHandler = nullptr;
243
246
249
251 QString mCrsWkt;
253 double mCellSizeX, mCellSizeY;
255 double mGridOffsetX, mGridOffsetY;
256
261 double mClipExtent[4];
262
263 // derived data from other members
264
266 double mGeoTransform[6];
269
272};
273
274#endif // QGSALIGNRASTER_H
GdalResampleAlgorithm
Resampling algorithm to be used (equivalent to GDAL's enum GDALResampleAlg)
Definition qgis.h:5383
QgsAlignRaster takes one or more raster layers and warps (resamples) them so they have the same:
ProgressHandler * progressHandler() const
Gets associated progress handler. May be nullptr (default)
int mYSize
Computed raster grid height.
QSizeF cellSize() const
Gets output cell size.
QPointF gridOffset() const
double mGridOffsetX
Destination grid offset - expected to be in interval <0,cellsize)
void setCellSize(QSizeF size)
Sets output cell size.
List mRasters
List of rasters to be aligned (with their output files and other options)
void setDestinationCrs(const QString &crsWkt)
Sets the output CRS in WKT format.
void setGridOffset(QPointF offset)
List rasters() const
Gets list of rasters that will be aligned.
QString mCrsWkt
Destination CRS - stored in well-known text (WKT) format.
int mXSize
Computed raster grid width.
QString destinationCrs() const
Gets the output CRS in WKT format.
double mCellSizeX
Destination cell size.
void setProgressHandler(ProgressHandler *progressHandler)
Assign a progress handler instance. Does not take ownership. nullptr can be passed.
QList< QgsAlignRasterData::RasterItem > List
QString errorMessage() const
Returns the error from a previous run() call.
QgsAlignRasterData::RasterItem Item
void setRasters(const List &list)
Sets list of rasters that will be aligned.
void setCellSize(double x, double y)
Sets output cell size.
QString mErrorMessage
Last error message from run()
Qgis::GdalResampleAlgorithm ResampleAlg
A rectangle specified with double values.
std::unique_ptr< std::remove_pointer< GDALDatasetH >::type, GDALDatasetCloser > dataset_unique_ptr
Scoped GDAL dataset.
#define SIP_SKIP
Definition qgis_sip.h:126
void * GDALDatasetH
Definition of one raster layer for alignment.
Helper struct to be sub-classed for progress reporting.
virtual ~ProgressHandler()=default
virtual bool progress(double complete)=0
Method to be overridden for progress reporting.
Utility class for gathering information about rasters.
QString crs() const
Returns the CRS in WKT format.
gdal::dataset_unique_ptr mDataset
handle to open GDAL dataset
int bandCount() const
Returns the number of raster bands in the file.
QSize rasterSize() const
Returns the size of the raster grid in pixels.
RasterInfo(const RasterInfo &rh)=delete
RasterInfo & operator=(const RasterInfo &rh)=delete
bool isValid() const
Check whether the given path is a valid raster.
QString mCrsWkt
CRS stored in WKT format.