QGIS API Documentation  2.7.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 "qgspoint.h"
21 #include <QTransform>
22 #include <vector>
23 
24 #include <cassert>
25 
26 class QgsPoint;
27 class QPoint;
28 
34 class CORE_EXPORT QgsMapToPixel
35 {
36  public:
37  /* Constructor
38  * @param mapUnitsPerPixel Map units per pixel
39  * @param height Map canvas height, in pixels
40  * @param ymin Minimum y value of the map canvas
41  * @param xmin Minimum x value of the map canvas
42  * @deprecated in 2.8, use version with all parameters
43  */
44  QgsMapToPixel( double mapUnitsPerPixel, double height = 0, double ymin = 0, double xmin = 0 );
45 
46  /* Constructor
47  * @param mapUnitsPerPixel Map units per pixel
48  * @param xc X ordinate of map center, in geographical units
49  * @param yc Y ordinate of map center, in geographical units
50  * @param width Output width, in pixels
51  * @param height Output height, in pixels
52  * @param degrees clockwise rotation in degrees
53  * @note added in 2.8
54  */
55  QgsMapToPixel( double mapUnitsPerPixel, double xc, double yc, int width, int height, double rotation );
56 
61  QgsMapToPixel();
62 
64  ~QgsMapToPixel();
69  QgsPoint transform( const QgsPoint& p ) const;
70  void transform( QgsPoint* p ) const;
77  QgsPoint transform( double x, double y ) const;
84  /* Transform device coordinates to map coordinates. Modifies the
85  given coordinates in place. Intended as a fast way to do the
86  transform. */
87  void transformInPlace( qreal& x, qreal& y ) const;
88 
89  /* Transform device coordinates to map coordinates. Modifies the
90  given coordinates in place. Intended as a fast way to do the
91  transform.
92  @note not available in python bindings
93  */
94  template <class T>
95  void transformInPlace( QVector<T>& x, QVector<T>& y ) const
96  {
97  assert( x.size() == y.size() );
98  for ( int i = 0; i < x.size(); ++i )
99  transformInPlace( x[i], y[i] );
100  }
101 
102  QgsPoint toMapCoordinates( int x, int y ) const;
103 
105  QgsPoint toMapCoordinatesF( double x, double y ) const;
106 
111  QgsPoint toMapCoordinates( QPoint p ) const;
112 
113  QgsPoint toMapPoint( double x, double y ) const;
114 
118  void setMapUnitsPerPixel( double mapUnitsPerPixel );
119 
121  double mapUnitsPerPixel() const;
122 
126  int mapWidth() const;
127 
130  int mapHeight() const;
131 
137  void setMapRotation( double degrees, double cx, double cy );
138 
141  double mapRotation() const;
142 
144  // @deprecated in 2.8, use setParameters
145  // @note this really sets the viewport height, not ymax
146  void setYMaximum( double yMax ) { mHeight = yMax; }
147 
149  // @deprecated in 2.8, use setParameters
150  void setYMinimum( double ymin );
151 
153  // @deprecated in 2.8, use setParameters
154  void setXMinimum( double xmin );
155 
163  void setParameters( double mapUnitsPerPixel, double xmin, double ymin, double height );
164 
174  void setParameters( double mapUnitsPerPixel, double xc, double yc, int width, int height, double rotation );
175 
177  QString showParameters() const;
178 
179  private:
180  double mMapUnitsPerPixel;
181  int mWidth;
182  int mHeight;
183  double mRotation;
184  double xCenter;
185  double yCenter;
186  double xMin; // @deprecated in 2.8
187  double yMin; // @deprecated in 2.8
188  QTransform mMatrix;
189 
190  void updateMatrix();
191 };
192 
193 
194 #endif // QGSMAPTOPIXEL
void transformInPlace(QVector< T > &x, QVector< T > &y) const
Definition: qgsmaptopixel.h:95
void setYMaximum(double yMax)
Set maximum y value.
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:34
A class to represent a point.
Definition: qgspoint.h:63