QGIS API Documentation  2.0.1-Dufour
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsrasterprojector.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrasterprojector.h - Raster projector
3  --------------------------------------
4  Date : Jan 16, 2011
5  Copyright : (C) 2005 by Radim Blazek
6  email : radim dot blazek at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 /* This code takes ideas from WarpBuilder in Geotools.
19  * Thank to Ing. Andrea Aime, Ing. Simone Giannecchini and GeoSolutions S.A.S.
20  * See : http://geo-solutions.blogspot.com/2011/01/developers-corner-improving.html
21  */
22 
23 #ifndef QGSRASTERPROJECTOR_H
24 #define QGSRASTERPROJECTOR_H
25 
26 #include <QVector>
27 #include <QList>
28 
29 #include "qgsrectangle.h"
31 #include "qgscoordinatetransform.h"
32 #include "qgsrasterinterface.h"
33 
34 #include <cmath>
35 
36 class QgsPoint;
37 
38 class CORE_EXPORT QgsRasterProjector : public QgsRasterInterface
39 {
40  public:
48  QgsRectangle theDestExtent,
49  int theDestRows, int theDestCols,
50  double theMaxSrcXRes, double theMaxSrcYRes,
51  QgsRectangle theExtent
52  );
56  double theMaxSrcXRes, double theMaxSrcYRes,
57  QgsRectangle theExtent
58  );
61  // To avoid synthesized which fails on copy of QgsCoordinateTransform
62  // (QObject child) in Python bindings
63  QgsRasterProjector( const QgsRasterProjector &projector );
64 
67 
68  QgsRasterProjector & operator=( const QgsRasterProjector &projector );
69 
70  QgsRasterInterface *clone() const;
71 
72  int bandCount() const;
73 
74  QGis::DataType dataType( int bandNo ) const;
75 
77  void setCRS( const QgsCoordinateReferenceSystem & theSrcCRS, const QgsCoordinateReferenceSystem & theDestCRS );
78 
80  QgsCoordinateReferenceSystem srcCrs() const { return mSrcCRS; }
81 
83  QgsCoordinateReferenceSystem destCrs() const { return mDestCRS; }
84 
86  void setMaxSrcRes( double theMaxSrcXRes, double theMaxSrcYRes )
87  {
88  mMaxSrcXRes = theMaxSrcXRes; mMaxSrcYRes = theMaxSrcYRes;
89  }
90 
91  QgsRasterBlock *block( int bandNo, const QgsRectangle & extent, int width, int height );
92 
93  private:
95  QgsRectangle srcExtent() { return mSrcExtent; }
96 
98  int srcRows() { return mSrcRows; }
99  int srcCols() { return mSrcCols; }
100  void setSrcRows( int theRows ) { mSrcRows = theRows; mSrcXRes = mSrcExtent.height() / mSrcRows; }
101  void setSrcCols( int theCols ) { mSrcCols = theCols; mSrcYRes = mSrcExtent.width() / mSrcCols; }
102 
104  void srcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol );
105 
106  int dstRows() const { return mDestRows; }
107  int dstCols() const { return mDestCols; }
108 
110  void destPointOnCPMatrix( int theRow, int theCol, double *theX, double *theY );
111 
113  int matrixRow( int theDestRow );
114  int matrixCol( int theDestCol );
115 
117  QgsPoint srcPoint( int theRow, int theCol );
118 
120  inline void preciseSrcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol );
121 
123  inline void approximateSrcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol );
124 
126  void calc();
127 
129  void insertRows();
130 
132  void insertCols();
133 
134  /* calculate single control point in current matrix */
135  void calcCP( int theRow, int theCol );
136 
138  bool calcRow( int theRow );
139 
141  bool calcCol( int theCol );
142 
144  void calcSrcExtent();
145 
147  void calcSrcRowsCols();
148 
151  bool checkCols();
152 
155  bool checkRows();
156 
158  void calcHelper( int theMatrixRow, QgsPoint *thePoints );
159 
161  void nextHelper();
162 
164  QString cpToString();
165 
168 
171 
174 
177 
180 
183 
186 
189 
191  double mDestXRes;
192 
194  double mDestYRes;
195 
197  int mSrcRows;
198 
200  int mSrcCols;
201 
203  double mSrcXRes;
204 
206  double mSrcYRes;
207 
210 
213 
215  QList< QList<QgsPoint> > mCPMatrix;
216 
218  /* Same size as mCPMatrix */
219  QList< QList<bool> > mCPLegalMatrix;
220 
222  /* Warning: using QList is slow on access */
224 
226  /* Warning: using QList is slow on access */
228 
231 
233  int mCPCols;
235  int mCPRows;
236 
239 
241  double mMaxSrcXRes;
242  double mMaxSrcYRes;
243 
246 };
247 
248 #endif
249 
virtual int bandCount() const =0
Get number of bands.
QgsPoint * pHelperTop
Array of source points for each destination column on top of current CPMatrix grid row...
void setMaxSrcRes(double theMaxSrcXRes, double theMaxSrcYRes)
set maximum source resolution
A rectangle specified with double values.
Definition: qgsrectangle.h:35
double mDestRowsPerMatrixRow
number of destination rows per matrix row
void setSrcRows(int theRows)
QgsCoordinateTransform mCoordinateTransform
Reverse coordinate transform (from destination to source)
bool mApproximate
Use approximation.
double mSqrTolerance
Maximum tolerance in destination units.
int mDestRows
Number of destination rows.
int mCPRows
Number of mCPMatrix rows.
QgsCoordinateReferenceSystem mDestCRS
Destination CRS.
int mSrcCols
Number of source columns.
int mHelperTopRow
Current mHelperTop matrix row.
double mSrcYRes
Source y resolution.
QList< QList< QgsPoint > > mCPMatrix
Grid of source control points.
double mSrcXRes
Source x resolution.
Raster data container.
double mMaxSrcXRes
Maximum source resolution.
void setSrcCols(int theCols)
QgsPoint * pHelperBottom
Array of source points for each destination column on bottom of current CPMatrix grid row...
int srcRows()
get/set source width/height
double mDestColsPerMatrixCol
number of destination cols per matrix col
QgsCoordinateReferenceSystem destCrs() const
Get destination CRS.
virtual QGis::DataType dataType(int bandNo) const =0
Returns data type for the band specified by number.
double mDestXRes
Destination x resolution.
Base class for processing filters like renderers, reprojector, resampler etc.
A class to represent a point geometry.
Definition: qgspoint.h:63
int mCPCols
Number of mCPMatrix columns.
QList< QList< bool > > mCPLegalMatrix
Grid of source control points transformation possible indicator.
int mSrcRows
Number of source rows.
QgsCoordinateReferenceSystem srcCrs() const
Get source CRS.
virtual QgsRasterInterface * clone() const =0
Clone itself, create deep copy.
QgsRectangle mExtent
Source raster extent.
Class for storing a coordinate reference system (CRS)
DataType
Raster data types.
Definition: qgis.h:163
virtual QgsRasterBlock * block(int bandNo, const QgsRectangle &extent, int width, int height)=0
Read block of data using given extent and size.
Class for doing transforms between two map coordinate systems.
QgsRectangle srcExtent()
get source extent
double mDestYRes
Destination y resolution.
QgsRectangle mSrcExtent
Source extent.
QgsRectangle mDestExtent
Destination extent.
int mDestCols
Number of destination columns.
QgsCoordinateReferenceSystem mSrcCRS
Source CRS.