QGIS API Documentation  2.17.0-Master (bf77d09)
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( const QString& theSourceWkt, const QString& theDestWkt );
76 
84  QgsCoordinateTransform( long theSourceSrid,
85  const 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 
163  void transformInPlace( float& x, float& y, double &z, TransformDirection direction = ForwardTransform ) const;
165  void transformInPlace( float& x, float& y, float& z, TransformDirection direction = ForwardTransform ) const;
167  void transformInPlace( QVector<float>& x, QVector<float>& y, QVector<float>& z,
168  TransformDirection direction = ForwardTransform ) const;
169 
171  void transformInPlace( QVector<double>& x, QVector<double>& y, QVector<double>& z,
172  TransformDirection direction = ForwardTransform ) const;
173 
174  void transformPolygon( QPolygonF& poly, TransformDirection direction = ForwardTransform ) const;
175 
183  QgsRectangle transform( const QgsRectangle &theRect, TransformDirection direction = ForwardTransform ) const;
184 
195  void transformCoords( int numPoint, double *x, double *y, double *z, TransformDirection direction = ForwardTransform ) const;
196 
201  bool isInitialised() const { return mInitialisedFlag; }
202 
206  bool isShortCircuited() const { return mShortCircuit; }
207 
217  void setDestCRSID( long theCRSID );
218 
222  static QList< QList< int > > datumTransformations( const QgsCoordinateReferenceSystem& srcCRS, const QgsCoordinateReferenceSystem& destCRS );
223  static QString datumTransformString( int datumTransform );
226  static bool datumTransformCrsInfo( int datumTransform, int& epsgNr, QString& srcProjection, QString& dstProjection, QString &remarks, QString &scope, bool &preferred, bool &deprecated );
227 
228  int sourceDatumTransform() const { return mSourceDatumTransform; }
229  void setSourceDatumTransform( int dt ) { mSourceDatumTransform = dt; }
230  int destinationDatumTransform() const { return mDestinationDatumTransform; }
231  void setDestinationDatumTransform( int dt ) { mDestinationDatumTransform = dt; }
232 
233  public slots:
235  void initialise();
236 
241  bool readXML( QDomNode & theNode );
242 
248  bool writeXML( QDomNode & theNode, QDomDocument & theDoc );
249 
250  signals:
252  void invalidTransformInput() const;
253 
254  private:
255 
260  bool mShortCircuit;
261 
265  bool mInitialisedFlag;
266 
270  QgsCoordinateReferenceSystem mSourceCRS;
271 
276 
280  projPJ mSourceProjection;
281 
285  projPJ mDestinationProjection;
286 
287  int mSourceDatumTransform;
288  int mDestinationDatumTransform;
289 
293  void setFinder();
294 
296  static QString stripDatumTransform( const QString& proj4 );
297  static void searchDatumTransform( const QString& sql, QList< int >& transforms );
299  void addNullGridShifts( QString& srcProjString, QString& destProjString );
300 };
301 
303 inline std::ostream& operator << ( std::ostream& os, const QgsCoordinateTransform &r )
304 {
305  QString mySummary( "\n%%%%%%%%%%%%%%%%%%%%%%%%\nCoordinate Transform def begins:" );
306  mySummary += "\n\tInitialised? : ";
307  //prevent warnings
308  if ( r.isInitialised() )
309  {
310  //do nothing this is a dummy
311  }
312 
313 #if 0
314  if ( r.isInitialised() )
315  {
316  mySummary += "Yes";
317  }
318  else
319  {
320  mySummary += "No";
321  }
322  mySummary += "\n\tShort Circuit? : ";
323  if ( r.isShortCircuited() )
324  {
325  mySummary += "Yes";
326  }
327  else
328  {
329  mySummary += "No";
330  }
331 
332  mySummary += "\n\tSource Spatial Ref Sys : ";
333  if ( r.sourceCrs() )
334  {
335  mySummary << r.sourceCrs();
336  }
337  else
338  {
339  mySummary += "Undefined";
340  }
341 
342  mySummary += "\n\tDest Spatial Ref Sys : ";
343  if ( r.destCRS() )
344  {
345  mySummary << r.destCRS();
346  }
347  else
348  {
349  mySummary += "Undefined";
350  }
351 #endif
352 
353  mySummary += ( "\nCoordinate Transform def ends \n%%%%%%%%%%%%%%%%%%%%%%%%\n" );
354  return os << mySummary.toLocal8Bit().data() << std::endl;
355 }
356 
357 
358 #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.
bool isShortCircuited() const
See if the transform short circuits because src and dest are equivalent.
A class to represent a point.
Definition: qgspoint.h:117
QByteArray toLocal8Bit() const
void * projPJ
Class for storing a coordinate reference system (CRS)
Class for doing transforms between two map coordinate systems.
char * data()
const QgsCoordinateReferenceSystem & destCRS() const
std::ostream & operator<<(std::ostream &os, const QgsCoordinateTransform &r)
Output stream operator.