QGIS API Documentation  2.99.0-Master (9fdd060)
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 QgsPointXY;
28 class QgsRectangle;
29 class QPolygonF;
30 
46 class CORE_EXPORT QgsCoordinateTransform
47 {
48 
49  public:
50 
53  {
55  ReverseTransform
56  };
57 
60 
67  const QgsCoordinateReferenceSystem &destination );
68 
73 
77  QgsCoordinateTransform &operator=( const QgsCoordinateTransform &o );
78 
80 
86  bool isValid() const;
87 
94  void setSourceCrs( const QgsCoordinateReferenceSystem &crs );
95 
102  void setDestinationCrs( const QgsCoordinateReferenceSystem &crs );
103 
110  QgsCoordinateReferenceSystem sourceCrs() const;
111 
118  QgsCoordinateReferenceSystem destinationCrs() const;
119 
128  QgsPointXY transform( const QgsPointXY &point, TransformDirection direction = ForwardTransform ) const;
129 
139  QgsPointXY transform( const double x, const double y, TransformDirection direction = ForwardTransform ) const;
140 
154  QgsRectangle transformBoundingBox( const QgsRectangle &rectangle, TransformDirection direction = ForwardTransform, const bool handle180Crossover = false ) const;
155 
167  void transformInPlace( double &x, double &y, double &z, TransformDirection direction = ForwardTransform ) const;
168 
181  void transformInPlace( float &x, float &y, double &z, TransformDirection direction = ForwardTransform ) const SIP_SKIP;
182 
195  void transformInPlace( float &x, float &y, float &z, TransformDirection direction = ForwardTransform ) const SIP_SKIP;
196 
209  void transformInPlace( QVector<float> &x, QVector<float> &y, QVector<float> &z,
210  TransformDirection direction = ForwardTransform ) const SIP_SKIP;
211 
224  void transformInPlace( QVector<double> &x, QVector<double> &y, QVector<double> &z,
225  TransformDirection direction = ForwardTransform ) const SIP_SKIP;
226 
232  void transformPolygon( QPolygonF &polygon, TransformDirection direction = ForwardTransform ) const;
233 
242  QgsRectangle transform( const QgsRectangle &rectangle, TransformDirection direction = ForwardTransform ) const SIP_SKIP;
243 
254  void transformCoords( int numPoint, double *x, double *y, double *z, TransformDirection direction = ForwardTransform ) const;
255 
259  bool isShortCircuited() const;
260 
265  static QList< QList< int > > datumTransformations( const QgsCoordinateReferenceSystem &srcCRS, const QgsCoordinateReferenceSystem &destinationCrs ) SIP_SKIP;
266 
267  static QString datumTransformString( int datumTransform );
268 
272  static bool datumTransformCrsInfo( int datumTransform, int &epsgNr, QString &srcProjection, QString &dstProjection, QString &remarks, QString &scope, bool &preferred, bool &deprecated );
273 
274  int sourceDatumTransform() const;
275  void setSourceDatumTransform( int dt );
276  int destinationDatumTransform() const;
277  void setDestinationDatumTransform( int dt );
278 
280  void initialize();
281 
288  bool readXml( const QDomNode &node );
289 
297  bool writeXml( QDomNode &node, QDomDocument &document ) const;
298 
299  private:
300 
301  static void searchDatumTransform( const QString &sql, QList< int > &transforms );
302 
303  mutable QExplicitlySharedDataPointer<QgsCoordinateTransformPrivate> d;
304 };
305 
307 #ifndef SIP_RUN
308 inline std::ostream &operator << ( std::ostream &os, const QgsCoordinateTransform &r )
309 {
310  QString mySummary( QStringLiteral( "\n%%%%%%%%%%%%%%%%%%%%%%%%\nCoordinate Transform def begins:" ) );
311  mySummary += QLatin1String( "\n\tInitialized? : " );
312  //prevent warnings
313  if ( r.isValid() )
314  {
315  //do nothing this is a dummy
316  }
317 
318 #if 0
319  if ( r.isValid() )
320  {
321  mySummary += "Yes";
322  }
323  else
324  {
325  mySummary += "No";
326  }
327  mySummary += "\n\tShort Circuit? : ";
328  if ( r.isShortCircuited() )
329  {
330  mySummary += "Yes";
331  }
332  else
333  {
334  mySummary += "No";
335  }
336 
337  mySummary += "\n\tSource Spatial Ref Sys : ";
338  if ( r.sourceCrs() )
339  {
340  mySummary << r.sourceCrs();
341  }
342  else
343  {
344  mySummary += "Undefined";
345  }
346 
347  mySummary += "\n\tDest Spatial Ref Sys : ";
348  if ( r.destCRS() )
349  {
350  mySummary << r.destCRS();
351  }
352  else
353  {
354  mySummary += "Undefined";
355  }
356 #endif
357 
358  mySummary += QLatin1String( "\nCoordinate Transform def ends \n%%%%%%%%%%%%%%%%%%%%%%%%\n" );
359  return os << mySummary.toLocal8Bit().data() << std::endl;
360 }
361 #endif
362 
363 
364 #endif // QGSCOORDINATETRANSFORM_H
A rectangle specified with double values.
Definition: qgsrectangle.h:39
A class to represent a 2D point.
Definition: qgspointxy.h:43
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:119
bool isShortCircuited() const
Returns true if the transform short circuits because the source and destination are equivalent...
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.