|
QGIS API Documentation
master-3f58142
|
00001 /*************************************************************************** 00002 qgsrasterprojector.h - Raster projector 00003 -------------------------------------- 00004 Date : Jan 16, 2011 00005 Copyright : (C) 2005 by Radim Blazek 00006 email : radim dot blazek at gmail dot com 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 /* This code takes ideas from WarpBuilder in Geotools. 00019 * Thank to Ing. Andrea Aime, Ing. Simone Giannecchini and GeoSolutions S.A.S. 00020 * See : http://geo-solutions.blogspot.com/2011/01/developers-corner-improving.html 00021 */ 00022 00023 #ifndef QGSRASTERPROJECTOR_H 00024 #define QGSRASTERPROJECTOR_H 00025 00026 #include <QVector> 00027 #include <QList> 00028 00029 #include "qgsrectangle.h" 00030 #include "qgscoordinatereferencesystem.h" 00031 #include "qgscoordinatetransform.h" 00032 #include "qgsrasterinterface.h" 00033 00034 #include <cmath> 00035 00036 class QgsPoint; 00037 00038 class CORE_EXPORT QgsRasterProjector : public QgsRasterInterface 00039 { 00040 public: 00045 QgsRasterProjector( 00046 QgsCoordinateReferenceSystem theSrcCRS, 00047 QgsCoordinateReferenceSystem theDestCRS, 00048 QgsRectangle theDestExtent, 00049 int theDestRows, int theDestCols, 00050 double theMaxSrcXRes, double theMaxSrcYRes, 00051 QgsRectangle theExtent 00052 ); 00053 QgsRasterProjector( 00054 QgsCoordinateReferenceSystem theSrcCRS, 00055 QgsCoordinateReferenceSystem theDestCRS, 00056 double theMaxSrcXRes, double theMaxSrcYRes, 00057 QgsRectangle theExtent 00058 ); 00059 QgsRasterProjector(); 00061 // To avoid synthesized which fails on copy of QgsCoordinateTransform 00062 // (QObject child) in Python bindings 00063 QgsRasterProjector( const QgsRasterProjector &projector ); 00064 00066 ~QgsRasterProjector(); 00067 00068 QgsRasterProjector & operator=( const QgsRasterProjector &projector ); 00069 00070 QgsRasterInterface *clone() const; 00071 00072 int bandCount() const; 00073 00074 QGis::DataType dataType( int bandNo ) const; 00075 00077 void setCRS( const QgsCoordinateReferenceSystem & theSrcCRS, const QgsCoordinateReferenceSystem & theDestCRS ); 00078 00080 QgsCoordinateReferenceSystem srcCrs() const { return mSrcCRS; } 00081 00083 QgsCoordinateReferenceSystem destCrs() const { return mDestCRS; } 00084 00086 void setMaxSrcRes( double theMaxSrcXRes, double theMaxSrcYRes ) 00087 { 00088 mMaxSrcXRes = theMaxSrcXRes; mMaxSrcYRes = theMaxSrcYRes; 00089 } 00090 00091 QgsRasterBlock *block( int bandNo, const QgsRectangle & extent, int width, int height ); 00092 00093 private: 00095 QgsRectangle srcExtent() { return mSrcExtent; } 00096 00098 int srcRows() { return mSrcRows; } 00099 int srcCols() { return mSrcCols; } 00100 void setSrcRows( int theRows ) { mSrcRows = theRows; mSrcXRes = mSrcExtent.height() / mSrcRows; } 00101 void setSrcCols( int theCols ) { mSrcCols = theCols; mSrcYRes = mSrcExtent.width() / mSrcCols; } 00102 00104 void srcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol ); 00105 00106 int dstRows() const { return mDestRows; } 00107 int dstCols() const { return mDestCols; } 00108 00110 void destPointOnCPMatrix( int theRow, int theCol, double *theX, double *theY ); 00111 00113 int matrixRow( int theDestRow ); 00114 int matrixCol( int theDestCol ); 00115 00117 QgsPoint srcPoint( int theRow, int theCol ); 00118 00120 inline void preciseSrcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol ); 00121 00123 inline void approximateSrcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol ); 00124 00126 void calc(); 00127 00129 void insertRows(); 00130 00132 void insertCols(); 00133 00134 /* calculate single control point in current matrix */ 00135 void calcCP( int theRow, int theCol ); 00136 00138 bool calcRow( int theRow ); 00139 00141 bool calcCol( int theCol ); 00142 00144 void calcSrcExtent(); 00145 00147 void calcSrcRowsCols(); 00148 00151 bool checkCols(); 00152 00155 bool checkRows(); 00156 00158 void calcHelper( int theMatrixRow, QgsPoint *thePoints ); 00159 00161 void nextHelper(); 00162 00164 QString cpToString(); 00165 00167 QgsCoordinateReferenceSystem mSrcCRS; 00168 00170 QgsCoordinateReferenceSystem mDestCRS; 00171 00173 QgsCoordinateTransform mCoordinateTransform; 00174 00176 QgsRectangle mDestExtent; 00177 00179 QgsRectangle mSrcExtent; 00180 00182 QgsRectangle mExtent; 00183 00185 int mDestRows; 00186 00188 int mDestCols; 00189 00191 double mDestXRes; 00192 00194 double mDestYRes; 00195 00197 int mSrcRows; 00198 00200 int mSrcCols; 00201 00203 double mSrcXRes; 00204 00206 double mSrcYRes; 00207 00209 double mDestRowsPerMatrixRow; 00210 00212 double mDestColsPerMatrixCol; 00213 00215 QList< QList<QgsPoint> > mCPMatrix; 00216 00218 /* Same size as mCPMatrix */ 00219 QList< QList<bool> > mCPLegalMatrix; 00220 00222 /* Warning: using QList is slow on access */ 00223 QgsPoint *pHelperTop; 00224 00226 /* Warning: using QList is slow on access */ 00227 QgsPoint *pHelperBottom; 00228 00230 int mHelperTopRow; 00231 00233 int mCPCols; 00235 int mCPRows; 00236 00238 double mSqrTolerance; 00239 00241 double mMaxSrcXRes; 00242 double mMaxSrcYRes; 00243 00245 bool mApproximate; 00246 }; 00247 00248 #endif 00249