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 #ifdef QT_ARCH_ARM
158  void transformInPlace( qreal& x, qreal& y, double &z, TransformDirection direction = ForwardTransform ) const;
159 #endif
160 
162  void transformInPlace( QVector<double>& x, QVector<double>& y, QVector<double>& z,
163  TransformDirection direction = ForwardTransform ) const;
164 
165  void transformPolygon( QPolygonF& poly, TransformDirection direction = ForwardTransform ) const;
166 
167 #ifdef ANDROID
168  void transformInPlace( float& x, float& y, float& z, TransformDirection direction = ForwardTransform ) const;
169 
170  void transformInPlace( QVector<float>& x, QVector<float>& y, QVector<float>& z,
171  TransformDirection direction = ForwardTransform ) const;
172 #endif
173 
181  QgsRectangle transform( const QgsRectangle theRect, TransformDirection direction = ForwardTransform ) const;
182 
193  void transformCoords( const int &numPoint, double *x, double *y, double *z, TransformDirection direction = ForwardTransform ) const;
194 
199  bool isInitialised() const {return mInitialisedFlag;};
200 
204  bool isShortCircuited() {return mShortCircuit;};
205 
215  void setDestCRSID( long theCRSID );
216 
217  public slots:
219  void initialise();
220 
225  bool readXML( QDomNode & theNode );
226 
232  bool writeXML( QDomNode & theNode, QDomDocument & theDoc );
233 
234  signals:
236  void invalidTransformInput() const;
237 
238  private:
239 
245 
250 
255 
260 
265 
270 
274  void setFinder();
275 };
276 
278 inline std::ostream& operator << ( std::ostream& os, const QgsCoordinateTransform &r )
279 {
280  QString mySummary( "\n%%%%%%%%%%%%%%%%%%%%%%%%\nCoordinate Transform def begins:" );
281  mySummary += "\n\tInitialised? : ";
282  //prevent warnings
283  if ( r.isInitialised() )
284  {
285  //do nothing this is a dummy
286  }
287 
288 #if 0
289  if ( r.isInitialised() )
290  {
291  mySummary += "Yes";
292  }
293  else
294  {
295  mySummary += "No" ;
296  }
297  mySummary += "\n\tShort Circuit? : " ;
298  if ( r.isShortCircuited() )
299  {
300  mySummary += "Yes";
301  }
302  else
303  {
304  mySummary += "No" ;
305  }
306 
307  mySummary += "\n\tSource Spatial Ref Sys : ";
308  if ( r.sourceCrs() )
309  {
310  mySummary << r.sourceCrs();
311  }
312  else
313  {
314  mySummary += "Undefined" ;
315  }
316 
317  mySummary += "\n\tDest Spatial Ref Sys : " ;
318  if ( r.destCRS() )
319  {
320  mySummary << r.destCRS();
321  }
322  else
323  {
324  mySummary += "Undefined" ;
325  }
326 #endif
327 
328  mySummary += ( "\nCoordinate Transform def ends \n%%%%%%%%%%%%%%%%%%%%%%%%\n" );
329  return os << mySummary.toLocal8Bit().data() << std::endl;
330 }
331 
332 
333 #endif // QGSCOORDINATETRANSFORM_H
const QgsCoordinateReferenceSystem & sourceCrs() const
A rectangle specified with double values.
Definition: qgsrectangle.h:35
TransformDirection
Enum used to indicate the direction (forward or inverse) of the transform.
QgsCoordinateReferenceSystem mSourceCRS
A class to represent a point geometry.
Definition: qgspoint.h:63
QgsCoordinateReferenceSystem mDestCRS
void * projPJ
Class for storing a coordinate reference system (CRS)
Class for doing transforms between two map coordinate systems.
const QgsCoordinateReferenceSystem & destCRS() const
std::ostream & operator<<(std::ostream &os, const QgsCoordinateTransform &r)
Output stream operator.