QGIS API Documentation  3.6.0-Noosa (5873452)
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 
181  void setContext( const QgsCoordinateTransformContext &context );
182 
189  QgsCoordinateTransformContext context() const;
190 
197  QgsCoordinateReferenceSystem sourceCrs() const;
198 
205  QgsCoordinateReferenceSystem destinationCrs() const;
206 
215  QgsPointXY transform( const QgsPointXY &point, TransformDirection direction = ForwardTransform ) const SIP_THROW( QgsCsException );
216 
226  QgsPointXY transform( double x, double y, TransformDirection direction = ForwardTransform ) const;
227 
241  QgsRectangle transformBoundingBox( const QgsRectangle &rectangle, TransformDirection direction = ForwardTransform, bool handle180Crossover = false ) const SIP_THROW( QgsCsException );
242 
254  void transformInPlace( double &x, double &y, double &z, TransformDirection direction = ForwardTransform ) const SIP_THROW( QgsCsException );
255 
268  void transformInPlace( float &x, float &y, double &z, TransformDirection direction = ForwardTransform ) const SIP_SKIP;
269 
282  void transformInPlace( float &x, float &y, float &z, TransformDirection direction = ForwardTransform ) const SIP_SKIP;
283 
296  void transformInPlace( QVector<float> &x, QVector<float> &y, QVector<float> &z,
297  TransformDirection direction = ForwardTransform ) const SIP_SKIP;
298 
311  void transformInPlace( QVector<double> &x, QVector<double> &y, QVector<double> &z,
312  TransformDirection direction = ForwardTransform ) const SIP_SKIP;
313 
319  void transformPolygon( QPolygonF &polygon, TransformDirection direction = ForwardTransform ) const SIP_THROW( QgsCsException );
320 
329  QgsRectangle transform( const QgsRectangle &rectangle, TransformDirection direction = ForwardTransform ) const SIP_THROW( QgsCsException );
330 
341  void transformCoords( int numPoint, double *x, double *y, double *z, TransformDirection direction = ForwardTransform ) const SIP_THROW( QgsCsException );
342 
346  bool isShortCircuited() const;
347 
359  int sourceDatumTransformId() const;
360 
372  void setSourceDatumTransformId( int datumId );
373 
385  int destinationDatumTransformId() const;
386 
398  void setDestinationDatumTransformId( int datumId );
399 
406  static void invalidateCache();
407 
417  double scaleFactor( const QgsRectangle &referenceExtent ) const;
418 
419  private:
420 
421  mutable QExplicitlySharedDataPointer<QgsCoordinateTransformPrivate> d;
422 
425 
426 #ifdef QGISDEBUG
427  bool mHasContext = false;
428 #endif
429 
430  bool setFromCache( const QgsCoordinateReferenceSystem &src,
431  const QgsCoordinateReferenceSystem &dest,
432  int srcDatumTransform,
433  int destDatumTransform );
434  void addToCache();
435 
436  // cache
437  static QReadWriteLock sCacheLock;
438  static QMultiHash< QPair< QString, QString >, QgsCoordinateTransform > sTransforms; //same auth_id pairs might have different datum transformations
439 
440 };
441 
443 #ifndef SIP_RUN
444 inline std::ostream &operator << ( std::ostream &os, const QgsCoordinateTransform &r )
445 {
446  QString mySummary( QStringLiteral( "\n%%%%%%%%%%%%%%%%%%%%%%%%\nCoordinate Transform def begins:" ) );
447  mySummary += QLatin1String( "\n\tInitialized? : " );
448  //prevent warnings
449  if ( r.isValid() )
450  {
451  //do nothing this is a dummy
452  }
453 
454 #if 0
455  if ( r.isValid() )
456  {
457  mySummary += "Yes";
458  }
459  else
460  {
461  mySummary += "No";
462  }
463  mySummary += "\n\tShort Circuit? : ";
464  if ( r.isShortCircuited() )
465  {
466  mySummary += "Yes";
467  }
468  else
469  {
470  mySummary += "No";
471  }
472 
473  mySummary += "\n\tSource Spatial Ref Sys : ";
474  if ( r.sourceCrs() )
475  {
476  mySummary << r.sourceCrs();
477  }
478  else
479  {
480  mySummary += "Undefined";
481  }
482 
483  mySummary += "\n\tDest Spatial Ref Sys : ";
484  if ( r.destCRS() )
485  {
486  mySummary << r.destCRS();
487  }
488  else
489  {
490  mySummary += "Undefined";
491  }
492 #endif
493 
494  mySummary += QLatin1String( "\nCoordinate Transform def ends \n%%%%%%%%%%%%%%%%%%%%%%%%\n" );
495  return os << mySummary.toLocal8Bit().data() << std::endl;
496 }
497 #endif
498 
499 
500 #endif // QGSCOORDINATETRANSFORM_H
A rectangle specified with double values.
Definition: qgsrectangle.h:41
A class to represent a 2D point.
Definition: qgspointxy.h:43
TransformDirection
Enum used to indicate the direction (forward or inverse) of the transform.
const QgsCoordinateReferenceSystem & crs
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:89
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.
#define SIP_THROW(name)
Definition: qgis_sip.h:177
Transform from source to destination CRS.
Custom exception class for Coordinate Reference System related exceptions.
Definition: qgsexception.h:65
std::ostream & operator<<(std::ostream &os, const QgsCoordinateTransform &r)
Output stream operator.