QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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 <gdal_version.h>
20
21#include "qgis_analysis.h"
22#include "qgis_sip.h"
23#include "qgsalignrasterdata.h"
24#include "qgsogrutils.h"
25
26#include <QList>
27#include <QPointF>
28#include <QSizeF>
29#include <QString>
30
31class QgsRectangle;
32
33typedef void *GDALDatasetH SIP_SKIP;
34
35
47class ANALYSIS_EXPORT QgsAlignRaster
48{
49 //SIP_TYPEHEADER_INCLUDE( "gdal_version.h" );
50
51
52 public:
54
56 struct ANALYSIS_EXPORT RasterInfo
57 {
58 public:
60 RasterInfo( const QString &layerpath );
61
62 RasterInfo( const RasterInfo &rh ) = delete;
63 RasterInfo &operator=( const RasterInfo &rh ) = delete;
64
66 bool isValid() const { return nullptr != mDataset; }
67
69 QString crs() const { return mCrsWkt; }
71 QSize rasterSize() const { return QSize( mXSize, mYSize ); }
73 int bandCount() const { return mBandCnt; }
75 QSizeF cellSize() const;
77 QPointF gridOffset() const;
79 QgsRectangle extent() const;
81 QPointF origin() const;
82
84 void dump() const;
85
87 double identify( double mx, double my );
88
89 protected:
93 QString mCrsWkt;
95 double mGeoTransform[6];
97 int mXSize = 0;
99 int mYSize = 0;
101 int mBandCnt = 0;
102
103 private:
104#ifdef SIP_RUN
106#endif
107
108 friend class QgsAlignRaster;
109 };
110
113 typedef QList<QgsAlignRasterData::RasterItem> List;
114
117 {
123 virtual bool progress( double complete ) = 0;
124
125 virtual ~ProgressHandler() = default;
126 };
127
132
134 void setRasters( const List &list ) { mRasters = list; }
136 List rasters() const { return mRasters; }
137
138 void setGridOffset( QPointF offset )
139 {
140 mGridOffsetX = offset.x();
141 mGridOffsetY = offset.y();
142 }
143 QPointF gridOffset() const { return QPointF( mGridOffsetX, mGridOffsetY ); }
144
146 void setCellSize( double x, double y ) { setCellSize( QSizeF( x, y ) ); }
148 void setCellSize( QSizeF size )
149 {
150 mCellSizeX = size.width();
151 mCellSizeY = size.height();
152 }
153
154 QSizeF cellSize() const { return QSizeF( mCellSizeX, mCellSizeY ); }
155
157 void setDestinationCrs( const QString &crsWkt ) { mCrsWkt = crsWkt; }
159 QString destinationCrs() const { return mCrsWkt; }
160
165 void setClipExtent( double xmin, double ymin, double xmax, double ymax );
166
171 void setClipExtent( const QgsRectangle &extent );
172
177 QgsRectangle clipExtent() const;
178
190 bool setParametersFromRaster( const RasterInfo &rasterInfo, const QString &customCRSWkt = QString(), QSizeF customCellSize = QSizeF(), QPointF customGridOffset = QPointF( -1, -1 ) );
191
196 bool setParametersFromRaster( const QString &filename, const QString &customCRSWkt = QString(), QSizeF customCellSize = QSizeF(), QPointF customGridOffset = QPointF( -1, -1 ) );
197
202 bool checkInputParameters();
203
208 QSize alignedRasterSize() const;
209
214 QgsRectangle alignedRasterExtent() const;
215
220 bool run();
221
226 QString errorMessage() const { return mErrorMessage; }
227
229 void dump() const;
230
232 int suggestedReferenceLayer() const;
233
234 protected:
236 bool createAndWarp( const Item &raster );
237
239 static bool suggestedWarpOutput( const RasterInfo &info, const QString &destWkt, QSizeF *cellSize = nullptr, QPointF *gridOffset = nullptr, QgsRectangle *rect = nullptr );
240
241 protected:
242 // set by the client
243
246
249
252
254 QString mCrsWkt;
259
264 double mClipExtent[4];
265
266 // derived data from other members
267
269 double mGeoTransform[6];
272
275};
276
277#endif // QGSALIGNRASTER_H
GdalResampleAlgorithm
Resampling algorithm to be used (equivalent to GDAL's enum GDALResampleAlg).
Definition qgis.h:5722
ProgressHandler * progressHandler() const
Gets associated progress handler. May be nullptr (default).
void dump() const
write contents of the object to standard error stream - for debugging
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).
ProgressHandler * mProgressHandler
Object that facilitates reporting of progress / cancellation.
double mClipExtent[4]
Optional clip extent: sets "requested area" which be extended to fit the raster grid.
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.
double mGeoTransform[6]
Computed geo-transform.
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:134
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.
int mYSize
raster grid size Y
gdal::dataset_unique_ptr mDataset
handle to open GDAL dataset
RasterInfo(const QString &layerpath)
Construct raster info with a path to a raster file.
double mGeoTransform[6]
geotransform coefficients
int bandCount() const
Returns the number of raster bands in the file.
int mXSize
raster grid size X
QSize rasterSize() const
Returns the size of the raster grid in pixels.
int mBandCnt
number of raster's bands
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.