QGIS API Documentation  3.2.0-Bonn (bc43194)
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 SIP_THROW( QgsCsException );
207 
217  QgsPointXY transform( double x, double y, TransformDirection direction = ForwardTransform ) const;
218 
232  QgsRectangle transformBoundingBox( const QgsRectangle &rectangle, TransformDirection direction = ForwardTransform, bool handle180Crossover = false ) const SIP_THROW( QgsCsException );
233 
245  void transformInPlace( double &x, double &y, double &z, TransformDirection direction = ForwardTransform ) const SIP_THROW( QgsCsException );
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 SIP_THROW( QgsCsException );
311 
320  QgsRectangle transform( const QgsRectangle &rectangle, TransformDirection direction = ForwardTransform ) const SIP_THROW( QgsCsException );
321 
332  void transformCoords( int numPoint, double *x, double *y, double *z, TransformDirection direction = ForwardTransform ) const SIP_THROW( QgsCsException );
333 
337  bool isShortCircuited() const;
338 
350  int sourceDatumTransformId() const;
351 
363  void setSourceDatumTransformId( int datumId );
364 
376  int destinationDatumTransformId() const;
377 
389  void setDestinationDatumTransformId( int datumId );
390 
397  static void invalidateCache();
398 
399  private:
400 
401  mutable QExplicitlySharedDataPointer<QgsCoordinateTransformPrivate> d;
402 
405 
406 #ifdef QGISDEBUG
407  bool mHasContext = false;
408 #endif
409 
410  bool setFromCache( const QgsCoordinateReferenceSystem &src,
411  const QgsCoordinateReferenceSystem &dest,
412  int srcDatumTransform,
413  int destDatumTransform );
414  void addToCache();
415 
416  // cache
417  static QReadWriteLock sCacheLock;
418  static QMultiHash< QPair< QString, QString >, QgsCoordinateTransform > sTransforms; //same auth_id pairs might have different datum transformations
419 
420 };
421 
423 #ifndef SIP_RUN
424 inline std::ostream &operator << ( std::ostream &os, const QgsCoordinateTransform &r )
425 {
426  QString mySummary( QStringLiteral( "\n%%%%%%%%%%%%%%%%%%%%%%%%\nCoordinate Transform def begins:" ) );
427  mySummary += QLatin1String( "\n\tInitialized? : " );
428  //prevent warnings
429  if ( r.isValid() )
430  {
431  //do nothing this is a dummy
432  }
433 
434 #if 0
435  if ( r.isValid() )
436  {
437  mySummary += "Yes";
438  }
439  else
440  {
441  mySummary += "No";
442  }
443  mySummary += "\n\tShort Circuit? : ";
444  if ( r.isShortCircuited() )
445  {
446  mySummary += "Yes";
447  }
448  else
449  {
450  mySummary += "No";
451  }
452 
453  mySummary += "\n\tSource Spatial Ref Sys : ";
454  if ( r.sourceCrs() )
455  {
456  mySummary << r.sourceCrs();
457  }
458  else
459  {
460  mySummary += "Undefined";
461  }
462 
463  mySummary += "\n\tDest Spatial Ref Sys : ";
464  if ( r.destCRS() )
465  {
466  mySummary << r.destCRS();
467  }
468  else
469  {
470  mySummary += "Undefined";
471  }
472 #endif
473 
474  mySummary += QLatin1String( "\nCoordinate Transform def ends \n%%%%%%%%%%%%%%%%%%%%%%%%\n" );
475  return os << mySummary.toLocal8Bit().data() << std::endl;
476 }
477 #endif
478 
479 
480 #endif // QGSCOORDINATETRANSFORM_H
A rectangle specified with double values.
Definition: qgsrectangle.h:40
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:85
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.