QGIS API Documentation  2.2.0-Valmiera
 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 
91  QgsCoordinateTransform* clone() const;
92 
95  {
97  ReverseTransform
98  };
99 
104  void setSourceCrs( const QgsCoordinateReferenceSystem& theCRS );
105 
110  void setDestCRS( const QgsCoordinateReferenceSystem& theCRS );
111 
116  const QgsCoordinateReferenceSystem& sourceCrs() const { return mSourceCRS; }
117 
122  const QgsCoordinateReferenceSystem& destCRS() const { return mDestCRS; }
123 
131  QgsPoint transform( const QgsPoint p, TransformDirection direction = ForwardTransform ) const;
132 
141  QgsPoint transform( const double x, const double y, TransformDirection direction = ForwardTransform ) const;
142 
153  QgsRectangle transformBoundingBox( const QgsRectangle theRect, TransformDirection direction = ForwardTransform ) const;
154 
155  // Same as for the other transform() functions, but alters the x
156  // and y variables in place. The second one works with good old-fashioned
157  // C style arrays.
158  void transformInPlace( double& x, double& y, double &z, TransformDirection direction = ForwardTransform ) const;
159 
161  void transformInPlace( QVector<double>& x, QVector<double>& y, QVector<double>& z,
162  TransformDirection direction = ForwardTransform ) const;
163 
164  void transformPolygon( QPolygonF& poly, TransformDirection direction = ForwardTransform ) const;
165 
166 #ifdef ANDROID
167  void transformInPlace( float& x, float& y, float& z, TransformDirection direction = ForwardTransform ) const;
168 
169  void transformInPlace( QVector<float>& x, QVector<float>& y, QVector<float>& z,
170  TransformDirection direction = ForwardTransform ) const;
171 #endif
172 
180  QgsRectangle transform( const QgsRectangle theRect, TransformDirection direction = ForwardTransform ) const;
181 
192  void transformCoords( const int &numPoint, double *x, double *y, double *z, TransformDirection direction = ForwardTransform ) const;
193 
198  bool isInitialised() const {return mInitialisedFlag;};
199 
203  bool isShortCircuited() {return mShortCircuit;};
204 
214  void setDestCRSID( long theCRSID );
215 
219  static QList< QList< int > > datumTransformations( const QgsCoordinateReferenceSystem& srcCRS, const QgsCoordinateReferenceSystem& destCRS );
220  static QString datumTransformString( int datumTransform );
223  static bool datumTransformCrsInfo( int datumTransform, int& epsgNr, QString& srcProjection, QString& dstProjection, QString &remarks, QString &scope, bool &preferred, bool &deprecated );
224 
225  int sourceDatumTransform() const { return mSourceDatumTransform; }
226  void setSourceDatumTransform( int dt ) { mSourceDatumTransform = dt; }
227  int destinationDatumTransform() const { return mDestinationDatumTransform; }
228  void setDestinationDatumTransform( int dt ) { mDestinationDatumTransform = dt; }
229 
230  public slots:
232  void initialise();
233 
238  bool readXML( QDomNode & theNode );
239 
245  bool writeXML( QDomNode & theNode, QDomDocument & theDoc );
246 
247  signals:
249  void invalidTransformInput() const;
250 
251  private:
252 
258 
263 
268 
273 
278 
283 
286 
290  void setFinder();
291 
293  static QString stripDatumTransform( const QString& proj4 );
294  static void searchDatumTransform( const QString& sql, QList< int >& transforms );
296  void addNullGridShifts( QString& srcProjString, QString& destProjString );
297 };
298 
300 inline std::ostream& operator << ( std::ostream& os, const QgsCoordinateTransform &r )
301 {
302  QString mySummary( "\n%%%%%%%%%%%%%%%%%%%%%%%%\nCoordinate Transform def begins:" );
303  mySummary += "\n\tInitialised? : ";
304  //prevent warnings
305  if ( r.isInitialised() )
306  {
307  //do nothing this is a dummy
308  }
309 
310 #if 0
311  if ( r.isInitialised() )
312  {
313  mySummary += "Yes";
314  }
315  else
316  {
317  mySummary += "No" ;
318  }
319  mySummary += "\n\tShort Circuit? : " ;
320  if ( r.isShortCircuited() )
321  {
322  mySummary += "Yes";
323  }
324  else
325  {
326  mySummary += "No" ;
327  }
328 
329  mySummary += "\n\tSource Spatial Ref Sys : ";
330  if ( r.sourceCrs() )
331  {
332  mySummary << r.sourceCrs();
333  }
334  else
335  {
336  mySummary += "Undefined" ;
337  }
338 
339  mySummary += "\n\tDest Spatial Ref Sys : " ;
340  if ( r.destCRS() )
341  {
342  mySummary << r.destCRS();
343  }
344  else
345  {
346  mySummary += "Undefined" ;
347  }
348 #endif
349 
350  mySummary += ( "\nCoordinate Transform def ends \n%%%%%%%%%%%%%%%%%%%%%%%%\n" );
351  return os << mySummary.toLocal8Bit().data() << std::endl;
352 }
353 
354 
355 #endif // QGSCOORDINATETRANSFORM_H