Quantum GIS API Documentation  1.7.4
src/core/qgsrasterprojector.h
Go to the documentation of this file.
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 /* $Id: qgsrasterprojector.h 15005 2011-01-08 16:35:21Z rblazek $ */
00018 
00019 /* This code takes ideas from WarpBuilder in Geotools.
00020  * Thank you to Ing. Andrea Aime, Ing. Simone Giannecchini and GeoSolutions S.A.S.
00021  * See : http://geo-solutions.blogspot.com/2011/01/developers-corner-improving.html
00022  */
00023 
00024 #ifndef QGSRASTERPROJECTOR_H
00025 #define QGSRASTERPROJECTOR_H
00026 
00027 #include <QVector>
00028 #include <QList>
00029 
00030 
00031 #include "qgsrectangle.h"
00032 #include "qgscoordinatereferencesystem.h"
00033 #include "qgscoordinatetransform.h"
00034 
00035 #include <cmath>
00036 
00037 //class QgsRectangle;
00038 class QgsPoint;
00039 
00040 //class CORE_EXPORT QgsRasterProjector
00041 class QgsRasterProjector
00042 {
00043 //    Q_OBJECT
00044   public:
00049     QgsRasterProjector(
00050       QgsCoordinateReferenceSystem theSrcCRS,
00051       QgsCoordinateReferenceSystem theDestCRS,
00052       QgsRectangle theDestExtent,
00053       int theDestRows, int theDestCols,
00054       double theMaxSrcXRes, double theMaxSrcYRes,
00055       QgsRectangle theExtent
00056     );
00057 
00059     ~QgsRasterProjector();
00060 
00061 
00063     void destPointOnCPMatrix( int theRow, int theCol, double *theX, double *theY );
00064 
00066     int matrixRow( int theDestRow );
00067     int matrixCol( int theDestCol );
00068 
00070     QgsPoint srcPoint( int theRow, int theCol );
00071 
00073     inline void preciseSrcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol );
00074 
00076     inline void approximateSrcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol );
00077 
00079     void srcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol );
00080 
00082     void insertRows();
00083 
00085     void insertCols();
00086 
00087     /* calculate single control point in current matrix */
00088     void calcCP( int theRow, int theCol );
00089 
00091     bool calcRow( int theRow );
00092 
00094     bool calcCol( int theCol );
00095 
00097     void calcSrcExtent();
00098 
00100     void calcSrcRowsCols();
00101 
00104     bool checkCols();
00105 
00108     bool checkRows();
00109 
00111     //void calcHelper ( int theMatrixRow, QList<QgsPoint> *thePoints );
00112     void calcHelper( int theMatrixRow, QgsPoint *thePoints );
00113 
00115     void nextHelper();
00116 
00118     QgsRectangle srcExtent() { return mSrcExtent; }
00119 
00121     int srcRows() { return mSrcRows; }
00122     int srcCols() { return mSrcCols; }
00123     void setSrcRows( int theRows ) { mSrcRows = theRows; mSrcXRes = mSrcExtent.height() / mSrcRows; }
00124     void setSrcCols( int theCols ) { mSrcCols = theCols; mSrcYRes = mSrcExtent.width() / mSrcCols; }
00125 
00127     QString cpToString();
00128 
00129   private:
00131     QgsCoordinateReferenceSystem mSrcCRS;
00132 
00134     QgsCoordinateReferenceSystem mDestCRS;
00135 
00137     QgsCoordinateTransform mCoordinateTransform;
00138 
00140     QgsRectangle mDestExtent;
00141 
00143     QgsRectangle mSrcExtent;
00144 
00146     QgsRectangle mExtent;
00147 
00149     int mDestRows;
00150 
00152     int mDestCols;
00153 
00155     double mDestXRes;
00156 
00158     double mDestYRes;
00159 
00161     int mSrcRows;
00162 
00164     int mSrcCols;
00165 
00167     double mSrcXRes;
00168 
00170     double mSrcYRes;
00171 
00173     double mDestRowsPerMatrixRow;
00174 
00176     double mDestColsPerMatrixCol;
00177 
00179     QList< QList<QgsPoint> > mCPMatrix;
00180 
00182     /* Warning: using QList is slow on access */
00183     QgsPoint *pHelperTop;
00184 
00186     /* Warning: using QList is slow on access */
00187     QgsPoint *pHelperBottom;
00188 
00190     int mHelperTopRow;
00191 
00193     int mCPCols;
00195     int mCPRows;
00196 
00198     double mSqrTolerance;
00199 
00201     double mMaxSrcXRes;
00202     double mMaxSrcYRes;
00203     
00205     bool mApproximate;
00206 };
00207 
00208 #endif
00209 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines