QGIS API Documentation  2.4.0-Chugiak
 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:
49  int theSrcDatumTransform,
50  int theDestDatumTransform,
51  QgsRectangle theDestExtent,
52  int theDestRows, int theDestCols,
53  double theMaxSrcXRes, double theMaxSrcYRes,
54  QgsRectangle theExtent
55  );
56 
60  QgsRectangle theDestExtent,
61  int theDestRows, int theDestCols,
62  double theMaxSrcXRes, double theMaxSrcYRes,
63  QgsRectangle theExtent
64  );
68  double theMaxSrcXRes, double theMaxSrcYRes,
69  QgsRectangle theExtent
70  );
73  // To avoid synthesized which fails on copy of QgsCoordinateTransform
74  // (QObject child) in Python bindings
75  QgsRasterProjector( const QgsRasterProjector &projector );
76 
79 
80  QgsRasterProjector & operator=( const QgsRasterProjector &projector );
81 
82  QgsRasterInterface *clone() const;
83 
84  int bandCount() const;
85 
86  QGis::DataType dataType( int bandNo ) const;
87 
89  void setCRS( const QgsCoordinateReferenceSystem & theSrcCRS, const QgsCoordinateReferenceSystem & theDestCRS,
90  int srcDatumTransform = -1, int destDatumTransform = -1 );
91 
93  QgsCoordinateReferenceSystem srcCrs() const { return mSrcCRS; }
94 
96  QgsCoordinateReferenceSystem destCrs() const { return mDestCRS; }
97 
99  void setMaxSrcRes( double theMaxSrcXRes, double theMaxSrcYRes )
100  {
101  mMaxSrcXRes = theMaxSrcXRes; mMaxSrcYRes = theMaxSrcYRes;
102  }
103 
104  QgsRasterBlock *block( int bandNo, const QgsRectangle & extent, int width, int height );
105 
106  private:
108  QgsRectangle srcExtent() { return mSrcExtent; }
109 
111  int srcRows() { return mSrcRows; }
112  int srcCols() { return mSrcCols; }
113  void setSrcRows( int theRows ) { mSrcRows = theRows; mSrcXRes = mSrcExtent.height() / mSrcRows; }
114  void setSrcCols( int theCols ) { mSrcCols = theCols; mSrcYRes = mSrcExtent.width() / mSrcCols; }
115 
120  bool srcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol, const QgsCoordinateTransform* ct );
121 
122  int dstRows() const { return mDestRows; }
123  int dstCols() const { return mDestCols; }
124 
126  void destPointOnCPMatrix( int theRow, int theCol, double *theX, double *theY );
127 
129  int matrixRow( int theDestRow );
130  int matrixCol( int theDestCol );
131 
133  QgsPoint srcPoint( int theRow, int theCol );
134 
136  inline bool preciseSrcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol, const QgsCoordinateTransform* ct );
137 
139  inline bool approximateSrcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol );
140 
142  void calc();
143 
145  void insertRows( const QgsCoordinateTransform* ct );
146 
148  void insertCols( const QgsCoordinateTransform* ct );
149 
150  /* calculate single control point in current matrix */
151  void calcCP( int theRow, int theCol, const QgsCoordinateTransform* ct );
152 
154  bool calcRow( int theRow, const QgsCoordinateTransform* ct );
155 
157  bool calcCol( int theCol, const QgsCoordinateTransform* ct );
158 
160  void calcSrcExtent();
161 
163  void calcSrcRowsCols();
164 
167  bool checkCols( const QgsCoordinateTransform* ct );
168 
171  bool checkRows( const QgsCoordinateTransform* ct );
172 
174  void calcHelper( int theMatrixRow, QgsPoint *thePoints );
175 
177  void nextHelper();
178 
180  QString cpToString();
181 
184 
187 
190 
193 
196 
199 
202 
205 
208 
210  double mDestXRes;
211 
213  double mDestYRes;
214 
216  int mSrcRows;
217 
219  int mSrcCols;
220 
222  double mSrcXRes;
223 
225  double mSrcYRes;
226 
229 
232 
234  QList< QList<QgsPoint> > mCPMatrix;
235 
237  /* Same size as mCPMatrix */
238  QList< QList<bool> > mCPLegalMatrix;
239 
241  /* Warning: using QList is slow on access */
243 
245  /* Warning: using QList is slow on access */
247 
250 
252  int mCPCols;
254  int mCPRows;
255 
258 
260  double mMaxSrcXRes;
261  double mMaxSrcYRes;
262 
265 };
266 
267 #endif
268 
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)
int mDestDatumTransform
Destination datum transformation id (or -1 if none)
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:204
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.
int mSrcDatumTransform
Source datum transformation id (or -1 if none)
QgsCoordinateReferenceSystem mSrcCRS
Source CRS.