QGIS API Documentation  2.99.0-Master (dcec6bb)
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 "qgis_sip.h"
22 #include <QTransform>
23 #include <vector>
24 #include "qgsunittypes.h"
25 #include <cassert>
26 
27 class QgsPointXY;
28 class QPoint;
29 
35 class CORE_EXPORT QgsMapToPixel
36 {
37  public:
38 
49  QgsMapToPixel( double mapUnitsPerPixel, double centerX, double centerY, int widthPixels, int heightPixels, double rotation );
50 
55  QgsMapToPixel( double mapUnitsPerPixel );
56 
64  static QgsMapToPixel fromScale( double scale, QgsUnitTypes::DistanceUnit mapUnits, double dpi = 96 );
65 
71  QgsMapToPixel();
72 
78  QgsPointXY transform( const QgsPointXY &p ) const;
79 
80  void transform( QgsPointXY *p ) const;
81 
89  QgsPointXY transform( qreal x, qreal y ) const;
90 
96  void transformInPlace( double &x, double &y ) const;
97 
99  void transformInPlace( float &x, float &y ) const SIP_SKIP;
100 
101 #ifndef SIP_RUN
102 
109  template <class T> SIP_SKIP
110  void transformInPlace( QVector<T> &x, QVector<T> &y ) const
111  {
112  assert( x.size() == y.size() );
113  for ( int i = 0; i < x.size(); ++i )
114  transformInPlace( x[i], y[i] );
115  }
116 #endif
117 
118  QgsPointXY toMapCoordinates( int x, int y ) const;
119 
121  QgsPointXY toMapCoordinatesF( double x, double y ) const;
122 
128  QgsPointXY toMapCoordinates( QPoint p ) const;
129 
130  QgsPointXY toMapPoint( double x, double y ) const;
131 
136  void setMapUnitsPerPixel( double mapUnitsPerPixel );
137 
139  double mapUnitsPerPixel() const;
140 
146  int mapWidth() const;
147 
152  int mapHeight() const;
153 
161  void setMapRotation( double degrees, double cx, double cy );
162 
167  double mapRotation() const;
168 
179  void setParameters( double mapUnitsPerPixel, double centerX, double centerY, int widthPixels, int heightPixels, double rotation );
180 
182  QString showParameters() const;
183 
184  QTransform transform() const;
185 
190  double xCenter() const { return mXCenter; }
191 
196  double yCenter() const { return mYCenter; }
197 
198  private:
199  double mMapUnitsPerPixel;
200  int mWidth;
201  int mHeight;
202  double mRotation;
203  double mXCenter;
204  double mYCenter;
205  double xMin;
206  double yMin;
207  QTransform mMatrix;
208 
209  bool updateMatrix();
210 };
211 
212 
213 #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.
A class to represent a 2D point.
Definition: qgspointxy.h:42
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:35
#define SIP_SKIP
Definition: qgis_sip.h:119
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:42
double yCenter() const
Returns the center y-coordinate for the transform.