QGIS API Documentation  2.99.0-Master (314842d)
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 #include "qgis_core.h"
21 #include <QExplicitlySharedDataPointer>
23 
24 class QgsCoordinateTransformPrivate;
25 class QgsPoint;
26 class QgsRectangle;
27 class QPolygonF;
28 
43 class CORE_EXPORT QgsCoordinateTransform
44 {
45 
46  public:
47 
50  {
52  ReverseTransform
53  };
54 
57 
63  const QgsCoordinateReferenceSystem &destination );
64 
69 
73  QgsCoordinateTransform &operator=( const QgsCoordinateTransform &o );
74 
76 
82  bool isValid() const;
83 
90  void setSourceCrs( const QgsCoordinateReferenceSystem &crs );
91 
98  void setDestinationCrs( const QgsCoordinateReferenceSystem &crs );
99 
105  QgsCoordinateReferenceSystem sourceCrs() const;
106 
112  QgsCoordinateReferenceSystem destinationCrs() const;
113 
121  QgsPoint transform( const QgsPoint &point, TransformDirection direction = ForwardTransform ) const;
122 
131  QgsPoint transform( const double x, const double y, TransformDirection direction = ForwardTransform ) const;
132 
145  QgsRectangle transformBoundingBox( const QgsRectangle &rectangle, TransformDirection direction = ForwardTransform, const bool handle180Crossover = false ) const;
146 
157  void transformInPlace( double &x, double &y, double &z, TransformDirection direction = ForwardTransform ) const;
158 
170  void transformInPlace( float &x, float &y, double &z, TransformDirection direction = ForwardTransform ) const;
171 
183  void transformInPlace( float &x, float &y, float &z, TransformDirection direction = ForwardTransform ) const;
184 
196  void transformInPlace( QVector<float> &x, QVector<float> &y, QVector<float> &z,
197  TransformDirection direction = ForwardTransform ) const;
198 
210  void transformInPlace( QVector<double> &x, QVector<double> &y, QVector<double> &z,
211  TransformDirection direction = ForwardTransform ) const;
212 
217  void transformPolygon( QPolygonF &polygon, TransformDirection direction = ForwardTransform ) const;
218 
226  QgsRectangle transform( const QgsRectangle &rectangle, TransformDirection direction = ForwardTransform ) const;
227 
237  void transformCoords( int numPoint, double *x, double *y, double *z, TransformDirection direction = ForwardTransform ) const;
238 
241  bool isShortCircuited() const;
242 
246  static QList< QList< int > > datumTransformations( const QgsCoordinateReferenceSystem &srcCRS, const QgsCoordinateReferenceSystem &destinationCrs );
247  static QString datumTransformString( int datumTransform );
248 
251  static bool datumTransformCrsInfo( int datumTransform, int &epsgNr, QString &srcProjection, QString &dstProjection, QString &remarks, QString &scope, bool &preferred, bool &deprecated );
252 
253  int sourceDatumTransform() const;
254  void setSourceDatumTransform( int dt );
255  int destinationDatumTransform() const;
256  void setDestinationDatumTransform( int dt );
257 
259  void initialize();
260 
266  bool readXml( const QDomNode &node );
267 
274  bool writeXml( QDomNode &node, QDomDocument &document ) const;
275 
276  private:
277 
278  static void searchDatumTransform( const QString &sql, QList< int > &transforms );
279 
280  QExplicitlySharedDataPointer<QgsCoordinateTransformPrivate> d;
281 };
282 
284 inline std::ostream &operator << ( std::ostream &os, const QgsCoordinateTransform &r )
285 {
286  QString mySummary( QStringLiteral( "\n%%%%%%%%%%%%%%%%%%%%%%%%\nCoordinate Transform def begins:" ) );
287  mySummary += QLatin1String( "\n\tInitialized? : " );
288  //prevent warnings
289  if ( r.isValid() )
290  {
291  //do nothing this is a dummy
292  }
293 
294 #if 0
295  if ( r.isValid() )
296  {
297  mySummary += "Yes";
298  }
299  else
300  {
301  mySummary += "No";
302  }
303  mySummary += "\n\tShort Circuit? : ";
304  if ( r.isShortCircuited() )
305  {
306  mySummary += "Yes";
307  }
308  else
309  {
310  mySummary += "No";
311  }
312 
313  mySummary += "\n\tSource Spatial Ref Sys : ";
314  if ( r.sourceCrs() )
315  {
316  mySummary << r.sourceCrs();
317  }
318  else
319  {
320  mySummary += "Undefined";
321  }
322 
323  mySummary += "\n\tDest Spatial Ref Sys : ";
324  if ( r.destCRS() )
325  {
326  mySummary << r.destCRS();
327  }
328  else
329  {
330  mySummary += "Undefined";
331  }
332 #endif
333 
334  mySummary += QLatin1String( "\nCoordinate Transform def ends \n%%%%%%%%%%%%%%%%%%%%%%%%\n" );
335  return os << mySummary.toLocal8Bit().data() << std::endl;
336 }
337 
338 
339 #endif // QGSCOORDINATETRANSFORM_H
A rectangle specified with double values.
Definition: qgsrectangle.h:36
TransformDirection
Enum used to indicate the direction (forward or inverse) of the transform.
QgsCoordinateReferenceSystem sourceCrs() const
Returns the source coordinate reference system, which the transform will transform coordinates from...
bool isShortCircuited() const
Returns true if the transform short circuits because the source and destination are equivalent...
A class to represent a point.
Definition: qgspoint.h:37
This class represents a coordinate reference system (CRS).
Class for doing transforms between two map coordinate systems.
Transform from source to destination CRS.
std::ostream & operator<<(std::ostream &os, const QgsCoordinateTransform &r)
Output stream operator.