QGIS API Documentation  2.99.0-Master (08ee180)
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>
22 
23 class QgsCoordinateTransformPrivate;
24 class QgsPoint;
25 class QgsRectangle;
26 class QPolygonF;
27 
42 class CORE_EXPORT QgsCoordinateTransform
43 {
44 
45  public:
46 
49  {
51  ReverseTransform
52  };
53 
56 
62  const QgsCoordinateReferenceSystem& destination );
63 
68 
72  QgsCoordinateTransform& operator=( const QgsCoordinateTransform& o );
73 
75 
81  bool isValid() const;
82 
89  void setSourceCrs( const QgsCoordinateReferenceSystem& crs );
90 
97  void setDestinationCrs( const QgsCoordinateReferenceSystem& crs );
98 
104  QgsCoordinateReferenceSystem sourceCrs() const;
105 
111  QgsCoordinateReferenceSystem destinationCrs() const;
112 
120  QgsPoint transform( const QgsPoint& point, TransformDirection direction = ForwardTransform ) const;
121 
130  QgsPoint transform( const double x, const double y, TransformDirection direction = ForwardTransform ) const;
131 
144  QgsRectangle transformBoundingBox( const QgsRectangle& rectangle, TransformDirection direction = ForwardTransform, const bool handle180Crossover = false ) const;
145 
156  void transformInPlace( double& x, double& y, double &z, TransformDirection direction = ForwardTransform ) const;
157 
169  void transformInPlace( float& x, float& y, double &z, TransformDirection direction = ForwardTransform ) const;
170 
182  void transformInPlace( float& x, float& y, float& z, TransformDirection direction = ForwardTransform ) const;
183 
195  void transformInPlace( QVector<float>& x, QVector<float>& y, QVector<float>& z,
196  TransformDirection direction = ForwardTransform ) const;
197 
209  void transformInPlace( QVector<double>& x, QVector<double>& y, QVector<double>& z,
210  TransformDirection direction = ForwardTransform ) const;
211 
216  void transformPolygon( QPolygonF& polygon, TransformDirection direction = ForwardTransform ) const;
217 
225  QgsRectangle transform( const QgsRectangle &rectangle, TransformDirection direction = ForwardTransform ) const;
226 
236  void transformCoords( int numPoint, double *x, double *y, double *z, TransformDirection direction = ForwardTransform ) const;
237 
240  bool isShortCircuited() const;
241 
245  static QList< QList< int > > datumTransformations( const QgsCoordinateReferenceSystem& srcCRS, const QgsCoordinateReferenceSystem& destinationCrs );
246  static QString datumTransformString( int datumTransform );
247 
250  static bool datumTransformCrsInfo( int datumTransform, int& epsgNr, QString& srcProjection, QString& dstProjection, QString &remarks, QString &scope, bool &preferred, bool &deprecated );
251 
252  int sourceDatumTransform() const;
253  void setSourceDatumTransform( int dt );
254  int destinationDatumTransform() const;
255  void setDestinationDatumTransform( int dt );
256 
258  void initialise();
259 
265  bool readXml( const QDomNode& node );
266 
273  bool writeXml( QDomNode & node, QDomDocument & document ) const;
274 
275  private:
276 
277  static void searchDatumTransform( const QString& sql, QList< int >& transforms );
278 
279  QExplicitlySharedDataPointer<QgsCoordinateTransformPrivate> d;
280 };
281 
283 inline std::ostream& operator << ( std::ostream& os, const QgsCoordinateTransform &r )
284 {
285  QString mySummary( QStringLiteral( "\n%%%%%%%%%%%%%%%%%%%%%%%%\nCoordinate Transform def begins:" ) );
286  mySummary += QLatin1String( "\n\tInitialised? : " );
287  //prevent warnings
288  if ( r.isValid() )
289  {
290  //do nothing this is a dummy
291  }
292 
293 #if 0
294  if ( r.isValid() )
295  {
296  mySummary += "Yes";
297  }
298  else
299  {
300  mySummary += "No";
301  }
302  mySummary += "\n\tShort Circuit? : ";
303  if ( r.isShortCircuited() )
304  {
305  mySummary += "Yes";
306  }
307  else
308  {
309  mySummary += "No";
310  }
311 
312  mySummary += "\n\tSource Spatial Ref Sys : ";
313  if ( r.sourceCrs() )
314  {
315  mySummary << r.sourceCrs();
316  }
317  else
318  {
319  mySummary += "Undefined";
320  }
321 
322  mySummary += "\n\tDest Spatial Ref Sys : ";
323  if ( r.destCRS() )
324  {
325  mySummary << r.destCRS();
326  }
327  else
328  {
329  mySummary += "Undefined";
330  }
331 #endif
332 
333  mySummary += QLatin1String( "\nCoordinate Transform def ends \n%%%%%%%%%%%%%%%%%%%%%%%%\n" );
334  return os << mySummary.toLocal8Bit().data() << std::endl;
335 }
336 
337 
338 #endif // QGSCOORDINATETRANSFORM_H
A rectangle specified with double values.
Definition: qgsrectangle.h:35
TransformDirection
Enum used to indicate the direction (forward or inverse) of the transform.
QgsCoordinateReferenceSystem sourceCrs() const
Returns the source coordinate reference system, which the transform will transform coordinates from...
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:111
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.