Quantum GIS API Documentation  1.7.5-Wroclaw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 /* $Id$ */
18 #ifndef QGSCOORDINATETRANSFORM_H
19 #define QGSCOORDINATETRANSFORM_H
20 
21 //qt includes
22 #include <QObject>
23 
24 //qgis includes
25 #include "qgspoint.h"
26 #include "qgsrectangle.h"
27 #include "qgscsexception.h"
29 class QDomNode;
30 class QDomDocument;
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 
158  void transformInPlace( std::vector<double>& x, std::vector<double>& y, std::vector<double>& z,
159  TransformDirection direction = ForwardTransform ) const;
160 
168  QgsRectangle transform( const QgsRectangle theRect, TransformDirection direction = ForwardTransform ) const;
169 
180  void transformCoords( const int &numPoint, double *x, double *y, double *z, TransformDirection direction = ForwardTransform ) const;
181 
186  bool isInitialised() const {return mInitialisedFlag;};
187 
191  bool isShortCircuited() {return mShortCircuit;};
192 
202  void setDestCRSID( long theCRSID );
203 
204  public slots:
206  void initialise();
207 
212  bool readXML( QDomNode & theNode );
213 
219  bool writeXML( QDomNode & theNode, QDomDocument & theDoc );
220 
221  signals:
223  void invalidTransformInput() const;
224 
225  private:
226 
232 
237 
242 
247 
252 
257 
261  void setFinder();
262 };
263 
265 inline std::ostream& operator << ( std::ostream& os, const QgsCoordinateTransform &r )
266 {
267  QString mySummary( "\n%%%%%%%%%%%%%%%%%%%%%%%%\nCoordinate Transform def begins:" );
268  mySummary += "\n\tInitialised? : ";
269  //prevent warnings
270  if ( r.isInitialised() )
271  {
272  //do nothing this is a dummy
273  }
274 
275 #if 0
276  if ( r.isInitialised() )
277  {
278  mySummary += "Yes";
279  }
280  else
281  {
282  mySummary += "No" ;
283  }
284  mySummary += "\n\tShort Circuit? : " ;
285  if ( r.isShortCircuited() )
286  {
287  mySummary += "Yes";
288  }
289  else
290  {
291  mySummary += "No" ;
292  }
293 
294  mySummary += "\n\tSource Spatial Ref Sys : ";
295  if ( r.sourceCrs() )
296  {
297  mySummary << r.sourceCrs();
298  }
299  else
300  {
301  mySummary += "Undefined" ;
302  }
303 
304  mySummary += "\n\tDest Spatial Ref Sys : " ;
305  if ( r.destCRS() )
306  {
307  mySummary << r.destCRS();
308  }
309  else
310  {
311  mySummary += "Undefined" ;
312  }
313 #endif
314 
315  mySummary += ( "\nCoordinate Transform def ends \n%%%%%%%%%%%%%%%%%%%%%%%%\n" );
316  return os << mySummary.toLocal8Bit().data() << std::endl;
317 }
318 
319 
320 #endif // QGSCOORDINATETRANSFORM_H