QGIS API Documentation  2.0.1-Dufour
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgscoordinatetransform.h
Go to the documentation of this file.
1 /***************************************************************************
2  QgsCoordinateTransform.h - Coordinate Transforms
3  -------------------
4  begin : Dec 2004
5  copyright : (C) 2004 Tim Sutton
6  email : tim at linfiniti.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 #ifndef QGSCOORDINATETRANSFORM_H
18 #define QGSCOORDINATETRANSFORM_H
19 
20 //qt includes
21 #include <QObject>
22 
23 //qgis includes
24 #include "qgspoint.h"
25 #include "qgsrectangle.h"
26 #include "qgscsexception.h"
28 class QDomNode;
29 class QDomDocument;
30 class QPolygonF;
31 
32 //non qt includes
33 #include <iostream>
34 #include <vector>
35 
36 typedef void* projPJ;
37 class QString;
38 
52 class CORE_EXPORT QgsCoordinateTransform : public QObject
53 {
54  Q_OBJECT
55  public:
58 
64  const QgsCoordinateReferenceSystem& theDest );
65 
67  QgsCoordinateTransform( long theSourceSrsId, long theDestSrsId );
68 
75  QgsCoordinateTransform( QString theSourceWkt, QString theDestWkt );
76 
84  QgsCoordinateTransform( long theSourceSrid,
85  QString theDestWkt,
87 
90 
93  {
95  ReverseTransform
96  };
97 
102  void setSourceCrs( const QgsCoordinateReferenceSystem& theCRS );
103 
108  void setDestCRS( const QgsCoordinateReferenceSystem& theCRS );
109 
114  const QgsCoordinateReferenceSystem& sourceCrs() const { return mSourceCRS; }
115 
120  const QgsCoordinateReferenceSystem& destCRS() const { return mDestCRS; }
121 
129  QgsPoint transform( const QgsPoint p, TransformDirection direction = ForwardTransform ) const;
130 
139  QgsPoint transform( const double x, const double y, TransformDirection direction = ForwardTransform ) const;
140 
151  QgsRectangle transformBoundingBox( const QgsRectangle theRect, TransformDirection direction = ForwardTransform ) const;
152 
153  // Same as for the other transform() functions, but alters the x
154  // and y variables in place. The second one works with good old-fashioned
155  // C style arrays.
156  void transformInPlace( double& x, double& y, double &z, TransformDirection direction = ForwardTransform ) const;
157 
159  void transformInPlace( QVector<double>& x, QVector<double>& y, QVector<double>& z,
160  TransformDirection direction = ForwardTransform ) const;
161 
162  void transformPolygon( QPolygonF& poly, TransformDirection direction = ForwardTransform ) const;
163 
164 #ifdef ANDROID
165  void transformInPlace( float& x, float& y, float& z, TransformDirection direction = ForwardTransform ) const;
166 
167  void transformInPlace( QVector<float>& x, QVector<float>& y, QVector<float>& z,
168  TransformDirection direction = ForwardTransform ) const;
169 #endif
170 
178  QgsRectangle transform( const QgsRectangle theRect, TransformDirection direction = ForwardTransform ) const;
179 
190  void transformCoords( const int &numPoint, double *x, double *y, double *z, TransformDirection direction = ForwardTransform ) const;
191 
196  bool isInitialised() const {return mInitialisedFlag;};
197 
201  bool isShortCircuited() {return mShortCircuit;};
202 
212  void setDestCRSID( long theCRSID );
213 
214  public slots:
216  void initialise();
217 
222  bool readXML( QDomNode & theNode );
223 
229  bool writeXML( QDomNode & theNode, QDomDocument & theDoc );
230 
231  signals:
233  void invalidTransformInput() const;
234 
235  private:
236 
242 
247 
252 
257 
262 
267 
271  void setFinder();
272 };
273 
275 inline std::ostream& operator << ( std::ostream& os, const QgsCoordinateTransform &r )
276 {
277  QString mySummary( "\n%%%%%%%%%%%%%%%%%%%%%%%%\nCoordinate Transform def begins:" );
278  mySummary += "\n\tInitialised? : ";
279  //prevent warnings
280  if ( r.isInitialised() )
281  {
282  //do nothing this is a dummy
283  }
284 
285 #if 0
286  if ( r.isInitialised() )
287  {
288  mySummary += "Yes";
289  }
290  else
291  {
292  mySummary += "No" ;
293  }
294  mySummary += "\n\tShort Circuit? : " ;
295  if ( r.isShortCircuited() )
296  {
297  mySummary += "Yes";
298  }
299  else
300  {
301  mySummary += "No" ;
302  }
303 
304  mySummary += "\n\tSource Spatial Ref Sys : ";
305  if ( r.sourceCrs() )
306  {
307  mySummary << r.sourceCrs();
308  }
309  else
310  {
311  mySummary += "Undefined" ;
312  }
313 
314  mySummary += "\n\tDest Spatial Ref Sys : " ;
315  if ( r.destCRS() )
316  {
317  mySummary << r.destCRS();
318  }
319  else
320  {
321  mySummary += "Undefined" ;
322  }
323 #endif
324 
325  mySummary += ( "\nCoordinate Transform def ends \n%%%%%%%%%%%%%%%%%%%%%%%%\n" );
326  return os << mySummary.toLocal8Bit().data() << std::endl;
327 }
328 
329 
330 #endif // QGSCOORDINATETRANSFORM_H