QGIS API Documentation  2.99.0-Master (cb63e82)
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 "qgis_core.h"
21 #include <QTransform>
22 #include <vector>
23 #include "qgsunittypes.h"
24 #include <cassert>
25 
26 class QgsPoint;
27 class QPoint;
28 
34 class CORE_EXPORT QgsMapToPixel
35 {
36  public:
37 
48  QgsMapToPixel( double mapUnitsPerPixel, double centerX, double centerY, int widthPixels, int heightPixels, double rotation );
49 
54  QgsMapToPixel( double mapUnitsPerPixel );
55 
63  static QgsMapToPixel fromScale( double scale, QgsUnitTypes::DistanceUnit mapUnits, double dpi = 96 );
64 
70  QgsMapToPixel();
71 
77  QgsPoint transform( const QgsPoint &p ) const;
78 
79  void transform( QgsPoint *p ) const;
80 
88  QgsPoint transform( qreal x, qreal y ) const;
89 
95  void transformInPlace( double &x, double &y ) const;
96 
97  // \note not available in Python bindings
98  void transformInPlace( float &x, float &y ) const;
99 
106  template <class T>
107  void transformInPlace( QVector<T> &x, QVector<T> &y ) const
108  {
109  assert( x.size() == y.size() );
110  for ( int i = 0; i < x.size(); ++i )
111  transformInPlace( x[i], y[i] );
112  }
113 
114  QgsPoint toMapCoordinates( int x, int y ) const;
115 
117  QgsPoint toMapCoordinatesF( double x, double y ) const;
118 
124  QgsPoint toMapCoordinates( QPoint p ) const;
125 
126  QgsPoint toMapPoint( double x, double y ) const;
127 
132  void setMapUnitsPerPixel( double mapUnitsPerPixel );
133 
135  double mapUnitsPerPixel() const;
136 
142  int mapWidth() const;
143 
148  int mapHeight() const;
149 
157  void setMapRotation( double degrees, double cx, double cy );
158 
163  double mapRotation() const;
164 
175  void setParameters( double mapUnitsPerPixel, double centerX, double centerY, int widthPixels, int heightPixels, double rotation );
176 
178  QString showParameters() const;
179 
180  QTransform transform() const;
181 
186  double xCenter() const { return mXCenter; }
187 
192  double yCenter() const { return mYCenter; }
193 
194  private:
195  double mMapUnitsPerPixel;
196  int mWidth;
197  int mHeight;
198  double mRotation;
199  double mXCenter;
200  double mYCenter;
201  double xMin;
202  double yMin;
203  QTransform mMatrix;
204 
205  bool updateMatrix();
206 };
207 
208 
209 #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:34
A class to represent a point.
Definition: qgspoint.h:37
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:42
double yCenter() const
Returns the center y-coordinate for the transform.