QGIS API Documentation  3.0.2-Girona (307d082)
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 "qgsconfig.h"
23 #include "qgis_core.h"
24 #include "qgis_sip.h"
27 
28 class QgsCoordinateTransformPrivate;
29 class QgsPointXY;
30 class QgsRectangle;
31 class QPolygonF;
32 class QgsProject;
33 
52 class CORE_EXPORT QgsCoordinateTransform
53 {
54 
55  public:
56 
59  {
61  ReverseTransform
62  };
63 
66 
78  Q_DECL_DEPRECATED explicit QgsCoordinateTransform( const QgsCoordinateReferenceSystem &source, const QgsCoordinateReferenceSystem &destination ) SIP_SKIP;
79 
101  const QgsCoordinateReferenceSystem &destination,
102  const QgsCoordinateTransformContext &context );
103 
125  const QgsCoordinateReferenceSystem &destination,
126  const QgsProject *project );
127 
136  const QgsCoordinateReferenceSystem &destination,
137  int sourceDatumTransformId,
138  int destinationDatumTransformId );
139 
144 
148  QgsCoordinateTransform &operator=( const QgsCoordinateTransform &o );
149 
151 
157  bool isValid() const;
158 
165  void setSourceCrs( const QgsCoordinateReferenceSystem &crs );
166 
173  void setDestinationCrs( const QgsCoordinateReferenceSystem &crs );
174 
180  void setContext( const QgsCoordinateTransformContext &context );
181 
188  QgsCoordinateReferenceSystem sourceCrs() const;
189 
196  QgsCoordinateReferenceSystem destinationCrs() const;
197 
206  QgsPointXY transform( const QgsPointXY &point, TransformDirection direction = ForwardTransform ) const;
207 
217  QgsPointXY transform( const double x, const double y, TransformDirection direction = ForwardTransform ) const;
218 
232  QgsRectangle transformBoundingBox( const QgsRectangle &rectangle, TransformDirection direction = ForwardTransform, const bool handle180Crossover = false ) const;
233 
245  void transformInPlace( double &x, double &y, double &z, TransformDirection direction = ForwardTransform ) const;
246 
259  void transformInPlace( float &x, float &y, double &z, TransformDirection direction = ForwardTransform ) const SIP_SKIP;
260 
273  void transformInPlace( float &x, float &y, float &z, TransformDirection direction = ForwardTransform ) const SIP_SKIP;
274 
287  void transformInPlace( QVector<float> &x, QVector<float> &y, QVector<float> &z,
288  TransformDirection direction = ForwardTransform ) const SIP_SKIP;
289 
302  void transformInPlace( QVector<double> &x, QVector<double> &y, QVector<double> &z,
303  TransformDirection direction = ForwardTransform ) const SIP_SKIP;
304 
310  void transformPolygon( QPolygonF &polygon, TransformDirection direction = ForwardTransform ) const;
311 
320  QgsRectangle transform( const QgsRectangle &rectangle, TransformDirection direction = ForwardTransform ) const;
321 
332  void transformCoords( int numPoint, double *x, double *y, double *z, TransformDirection direction = ForwardTransform ) const;
333 
337  bool isShortCircuited() const;
338 
351  int sourceDatumTransformId() const;
352 
365  void setSourceDatumTransformId( int datumId );
366 
379  int destinationDatumTransformId() const;
380 
393  void setDestinationDatumTransformId( int datumId );
394 
401  static void invalidateCache();
402 
403  private:
404 
405  mutable QExplicitlySharedDataPointer<QgsCoordinateTransformPrivate> d;
406 
409 
410 #ifdef QGISDEBUG
411  bool mHasContext = false;
412 #endif
413 
414  bool setFromCache( const QgsCoordinateReferenceSystem &src,
415  const QgsCoordinateReferenceSystem &dest,
416  int srcDatumTransform,
417  int destDatumTransform );
418  void addToCache();
419 
420  // cache
421  static QReadWriteLock sCacheLock;
422  static QMultiHash< QPair< QString, QString >, QgsCoordinateTransform > sTransforms; //same auth_id pairs might have different datum transformations
423 
424 };
425 
427 #ifndef SIP_RUN
428 inline std::ostream &operator << ( std::ostream &os, const QgsCoordinateTransform &r )
429 {
430  QString mySummary( QStringLiteral( "\n%%%%%%%%%%%%%%%%%%%%%%%%\nCoordinate Transform def begins:" ) );
431  mySummary += QLatin1String( "\n\tInitialized? : " );
432  //prevent warnings
433  if ( r.isValid() )
434  {
435  //do nothing this is a dummy
436  }
437 
438 #if 0
439  if ( r.isValid() )
440  {
441  mySummary += "Yes";
442  }
443  else
444  {
445  mySummary += "No";
446  }
447  mySummary += "\n\tShort Circuit? : ";
448  if ( r.isShortCircuited() )
449  {
450  mySummary += "Yes";
451  }
452  else
453  {
454  mySummary += "No";
455  }
456 
457  mySummary += "\n\tSource Spatial Ref Sys : ";
458  if ( r.sourceCrs() )
459  {
460  mySummary << r.sourceCrs();
461  }
462  else
463  {
464  mySummary += "Undefined";
465  }
466 
467  mySummary += "\n\tDest Spatial Ref Sys : ";
468  if ( r.destCRS() )
469  {
470  mySummary << r.destCRS();
471  }
472  else
473  {
474  mySummary += "Undefined";
475  }
476 #endif
477 
478  mySummary += QLatin1String( "\nCoordinate Transform def ends \n%%%%%%%%%%%%%%%%%%%%%%%%\n" );
479  return os << mySummary.toLocal8Bit().data() << std::endl;
480 }
481 #endif
482 
483 
484 #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...
Reads and writes project states.
Definition: qgsproject.h:82
Contains information about the context in which a coordinate transform is executed.
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.