QGIS API Documentation  2.99.0-Master (c42dad3)
qgsmaptopixel.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmaptopixel.h - description
3  -------------------
4  begin : Sat Jun 22 2002
5  copyright : (C) 2002 by Gary E.Sherman
6  email : sherman at mrcc.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 QGSMAPTOPIXEL
18 #define QGSMAPTOPIXEL
19 
20 #include <QTransform>
21 #include <vector>
22 #include "qgsunittypes.h"
23 #include <cassert>
24 
25 class QgsPoint;
26 class QPoint;
27 
33 class CORE_EXPORT QgsMapToPixel
34 {
35  public:
36 
47  QgsMapToPixel( double mapUnitsPerPixel, double centerX, double centerY, int widthPixels, int heightPixels, double rotation );
48 
53  QgsMapToPixel( double mapUnitsPerPixel );
54 
62  static QgsMapToPixel fromScale( double scale, QgsUnitTypes::DistanceUnit mapUnits, double dpi = 96 );
63 
69  QgsMapToPixel();
70 
76  QgsPoint transform( const QgsPoint& p ) const;
77 
78  void transform( QgsPoint* p ) const;
79 
87  QgsPoint transform( qreal x, qreal y ) const;
88 
94  void transformInPlace( double& x, double& y ) const;
95 
96  // @note not available in python bindings
97  void transformInPlace( float& x, float& y ) const;
98 
105  template <class T>
106  void transformInPlace( QVector<T>& x, QVector<T>& y ) const
107  {
108  assert( x.size() == y.size() );
109  for ( int i = 0; i < x.size(); ++i )
110  transformInPlace( x[i], y[i] );
111  }
112 
113  QgsPoint toMapCoordinates( int x, int y ) const;
114 
116  QgsPoint toMapCoordinatesF( double x, double y ) const;
117 
123  QgsPoint toMapCoordinates( QPoint p ) const;
124 
125  QgsPoint toMapPoint( double x, double y ) const;
126 
131  void setMapUnitsPerPixel( double mapUnitsPerPixel );
132 
134  double mapUnitsPerPixel() const;
135 
141  int mapWidth() const;
142 
147  int mapHeight() const;
148 
156  void setMapRotation( double degrees, double cx, double cy );
157 
162  double mapRotation() const;
163 
174  void setParameters( double mapUnitsPerPixel, double centerX, double centerY, int widthPixels, int heightPixels, double rotation );
175 
177  QString showParameters() const;
178 
179  QTransform transform() const;
180 
185  double xCenter() const { return mXCenter; }
186 
191  double yCenter() const { return mYCenter; }
192 
193  private:
194  double mMapUnitsPerPixel;
195  int mWidth;
196  int mHeight;
197  double mRotation;
198  double mXCenter;
199  double mYCenter;
200  double xMin;
201  double yMin;
202  QTransform mMatrix;
203 
204  bool updateMatrix();
205 };
206 
207 
208 #endif // QGSMAPTOPIXEL
double xCenter() const
Returns the center x-coordinate for the transform.
void transformInPlace(QVector< T > &x, QVector< T > &y) const
Transform device coordinates to map coordinates.
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:33
A class to represent a point.
Definition: qgspoint.h:111
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:42
double yCenter() const
Returns the center y-coordinate for the transform.