QGIS API Documentation  2.8.2-Wien
 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 
155  QgsRectangle transformBoundingBox( const QgsRectangle &theRect, TransformDirection direction = ForwardTransform, const bool handle180Crossover = false ) const;
156 
157  // Same as for the other transform() functions, but alters the x
158  // and y variables in place. The second one works with good old-fashioned
159  // C style arrays.
160  void transformInPlace( double& x, double& y, double &z, TransformDirection direction = ForwardTransform ) const;
161 #ifdef QT_ARCH_ARM
162  void transformInPlace( qreal& x, qreal& y, double &z, TransformDirection direction = ForwardTransform ) const;
163 #endif
164 
166  void transformInPlace( QVector<double>& x, QVector<double>& y, QVector<double>& z,
167  TransformDirection direction = ForwardTransform ) const;
168 
169  void transformPolygon( QPolygonF& poly, TransformDirection direction = ForwardTransform ) const;
170 
171 #ifdef ANDROID
172  void transformInPlace( float& x, float& y, float& z, TransformDirection direction = ForwardTransform ) const;
173 
174  void transformInPlace( QVector<float>& x, QVector<float>& y, QVector<float>& z,
175  TransformDirection direction = ForwardTransform ) const;
176 #endif
177 
185  QgsRectangle transform( const QgsRectangle &theRect, TransformDirection direction = ForwardTransform ) const;
186 
197  void transformCoords( const int &numPoint, double *x, double *y, double *z, TransformDirection direction = ForwardTransform ) const;
198 
203  bool isInitialised() const {return mInitialisedFlag;}
204 
208  bool isShortCircuited() {return mShortCircuit;}
209 
219  void setDestCRSID( long theCRSID );
220 
224  static QList< QList< int > > datumTransformations( const QgsCoordinateReferenceSystem& srcCRS, const QgsCoordinateReferenceSystem& destCRS );
225  static QString datumTransformString( int datumTransform );
228  static bool datumTransformCrsInfo( int datumTransform, int& epsgNr, QString& srcProjection, QString& dstProjection, QString &remarks, QString &scope, bool &preferred, bool &deprecated );
229 
230  int sourceDatumTransform() const { return mSourceDatumTransform; }
231  void setSourceDatumTransform( int dt ) { mSourceDatumTransform = dt; }
232  int destinationDatumTransform() const { return mDestinationDatumTransform; }
233  void setDestinationDatumTransform( int dt ) { mDestinationDatumTransform = dt; }
234 
235  public slots:
237  void initialise();
238 
243  bool readXML( QDomNode & theNode );
244 
250  bool writeXML( QDomNode & theNode, QDomDocument & theDoc );
251 
252  signals:
254  void invalidTransformInput() const;
255 
256  private:
257 
262  bool mShortCircuit;
263 
267  bool mInitialisedFlag;
268 
272  QgsCoordinateReferenceSystem mSourceCRS;
273 
278 
282  projPJ mSourceProjection;
283 
287  projPJ mDestinationProjection;
288 
289  int mSourceDatumTransform;
290  int mDestinationDatumTransform;
291 
295  void setFinder();
296 
298  static QString stripDatumTransform( const QString& proj4 );
299  static void searchDatumTransform( const QString& sql, QList< int >& transforms );
301  void addNullGridShifts( QString& srcProjString, QString& destProjString );
302 };
303 
305 inline std::ostream& operator << ( std::ostream& os, const QgsCoordinateTransform &r )
306 {
307  QString mySummary( "\n%%%%%%%%%%%%%%%%%%%%%%%%\nCoordinate Transform def begins:" );
308  mySummary += "\n\tInitialised? : ";
309  //prevent warnings
310  if ( r.isInitialised() )
311  {
312  //do nothing this is a dummy
313  }
314 
315 #if 0
316  if ( r.isInitialised() )
317  {
318  mySummary += "Yes";
319  }
320  else
321  {
322  mySummary += "No";
323  }
324  mySummary += "\n\tShort Circuit? : ";
325  if ( r.isShortCircuited() )
326  {
327  mySummary += "Yes";
328  }
329  else
330  {
331  mySummary += "No";
332  }
333 
334  mySummary += "\n\tSource Spatial Ref Sys : ";
335  if ( r.sourceCrs() )
336  {
337  mySummary << r.sourceCrs();
338  }
339  else
340  {
341  mySummary += "Undefined";
342  }
343 
344  mySummary += "\n\tDest Spatial Ref Sys : ";
345  if ( r.destCRS() )
346  {
347  mySummary << r.destCRS();
348  }
349  else
350  {
351  mySummary += "Undefined";
352  }
353 #endif
354 
355  mySummary += ( "\nCoordinate Transform def ends \n%%%%%%%%%%%%%%%%%%%%%%%%\n" );
356  return os << mySummary.toLocal8Bit().data() << std::endl;
357 }
358 
359 
360 #endif // QGSCOORDINATETRANSFORM_H