QGIS API Documentation  2.99.0-Master (d55fa22)
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 <QExplicitlySharedDataPointer>
21 
22 #include "qgis_core.h"
23 #include "qgis_sip.h"
25 
26 class QgsCoordinateTransformPrivate;
27 class QgsPoint;
28 class QgsRectangle;
29 class QPolygonF;
30 
45 class CORE_EXPORT QgsCoordinateTransform
46 {
47 
48  public:
49 
52  {
54  ReverseTransform
55  };
56 
59 
65  const QgsCoordinateReferenceSystem &destination );
66 
71 
75  QgsCoordinateTransform &operator=( const QgsCoordinateTransform &o );
76 
78 
84  bool isValid() const;
85 
92  void setSourceCrs( const QgsCoordinateReferenceSystem &crs );
93 
100  void setDestinationCrs( const QgsCoordinateReferenceSystem &crs );
101 
107  QgsCoordinateReferenceSystem sourceCrs() const;
108 
114  QgsCoordinateReferenceSystem destinationCrs() const;
115 
123  QgsPoint transform( const QgsPoint &point, TransformDirection direction = ForwardTransform ) const;
124 
133  QgsPoint transform( const double x, const double y, TransformDirection direction = ForwardTransform ) const;
134 
147  QgsRectangle transformBoundingBox( const QgsRectangle &rectangle, TransformDirection direction = ForwardTransform, const bool handle180Crossover = false ) const;
148 
159  void transformInPlace( double &x, double &y, double &z, TransformDirection direction = ForwardTransform ) const;
160 
172  void transformInPlace( float &x, float &y, double &z, TransformDirection direction = ForwardTransform ) const SIP_SKIP;
173 
185  void transformInPlace( float &x, float &y, float &z, TransformDirection direction = ForwardTransform ) const SIP_SKIP;
186 
198  void transformInPlace( QVector<float> &x, QVector<float> &y, QVector<float> &z,
199  TransformDirection direction = ForwardTransform ) const SIP_SKIP;
200 
212  void transformInPlace( QVector<double> &x, QVector<double> &y, QVector<double> &z,
213  TransformDirection direction = ForwardTransform ) const SIP_SKIP;
214 
219  void transformPolygon( QPolygonF &polygon, TransformDirection direction = ForwardTransform ) const;
220 
228  QgsRectangle transform( const QgsRectangle &rectangle, TransformDirection direction = ForwardTransform ) const SIP_SKIP;
229 
239  void transformCoords( int numPoint, double *x, double *y, double *z, TransformDirection direction = ForwardTransform ) const;
240 
243  bool isShortCircuited() const;
244 
248  static QList< QList< int > > datumTransformations( const QgsCoordinateReferenceSystem &srcCRS, const QgsCoordinateReferenceSystem &destinationCrs ) SIP_SKIP;
249 
250  static QString datumTransformString( int datumTransform );
251 
254  static bool datumTransformCrsInfo( int datumTransform, int &epsgNr, QString &srcProjection, QString &dstProjection, QString &remarks, QString &scope, bool &preferred, bool &deprecated );
255 
256  int sourceDatumTransform() const;
257  void setSourceDatumTransform( int dt );
258  int destinationDatumTransform() const;
259  void setDestinationDatumTransform( int dt );
260 
262  void initialize();
263 
269  bool readXml( const QDomNode &node );
270 
277  bool writeXml( QDomNode &node, QDomDocument &document ) const;
278 
279  private:
280 
281  static void searchDatumTransform( const QString &sql, QList< int > &transforms );
282 
283  mutable QExplicitlySharedDataPointer<QgsCoordinateTransformPrivate> d;
284 };
285 
287 #ifndef SIP_RUN
288 inline std::ostream &operator << ( std::ostream &os, const QgsCoordinateTransform &r )
289 {
290  QString mySummary( QStringLiteral( "\n%%%%%%%%%%%%%%%%%%%%%%%%\nCoordinate Transform def begins:" ) );
291  mySummary += QLatin1String( "\n\tInitialized? : " );
292  //prevent warnings
293  if ( r.isValid() )
294  {
295  //do nothing this is a dummy
296  }
297 
298 #if 0
299  if ( r.isValid() )
300  {
301  mySummary += "Yes";
302  }
303  else
304  {
305  mySummary += "No";
306  }
307  mySummary += "\n\tShort Circuit? : ";
308  if ( r.isShortCircuited() )
309  {
310  mySummary += "Yes";
311  }
312  else
313  {
314  mySummary += "No";
315  }
316 
317  mySummary += "\n\tSource Spatial Ref Sys : ";
318  if ( r.sourceCrs() )
319  {
320  mySummary << r.sourceCrs();
321  }
322  else
323  {
324  mySummary += "Undefined";
325  }
326 
327  mySummary += "\n\tDest Spatial Ref Sys : ";
328  if ( r.destCRS() )
329  {
330  mySummary << r.destCRS();
331  }
332  else
333  {
334  mySummary += "Undefined";
335  }
336 #endif
337 
338  mySummary += QLatin1String( "\nCoordinate Transform def ends \n%%%%%%%%%%%%%%%%%%%%%%%%\n" );
339  return os << mySummary.toLocal8Bit().data() << std::endl;
340 }
341 #endif
342 
343 
344 #endif // QGSCOORDINATETRANSFORM_H
A rectangle specified with double values.
Definition: qgsrectangle.h:38
TransformDirection
Enum used to indicate the direction (forward or inverse) of the transform.
bool isValid() const
Returns true if the coordinate transform is valid, ie both the source and destination CRS have been s...
QgsCoordinateReferenceSystem sourceCrs() const
Returns the source coordinate reference system, which the transform will transform coordinates from...
#define SIP_SKIP
Definition: qgis_sip.h:87
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.