QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 
36 class CORE_EXPORT QgsMapToPixel
37 {
38  public:
39 
50  QgsMapToPixel( double mapUnitsPerPixel, double centerX, double centerY, int widthPixels, int heightPixels, double rotation );
51 
56  QgsMapToPixel( double mapUnitsPerPixel );
57 
66  static QgsMapToPixel fromScale( double scale, QgsUnitTypes::DistanceUnit mapUnits, double dpi = 96 );
67 
73  QgsMapToPixel();
74 
80  QgsPointXY transform( const QgsPointXY &p ) const;
81 
82  void transform( QgsPointXY *p ) const;
83 
91  QgsPointXY transform( qreal x, qreal y ) const;
92 
98  void transformInPlace( double &x, double &y ) const;
99 
101  void transformInPlace( float &x, float &y ) const SIP_SKIP;
102 
103 #ifndef SIP_RUN
104 
111  template <class T> SIP_SKIP
112  void transformInPlace( QVector<T> &x, QVector<T> &y ) const
113  {
114  assert( x.size() == y.size() );
115  for ( int i = 0; i < x.size(); ++i )
116  transformInPlace( x[i], y[i] );
117  }
118 #endif
119 
121  QgsPointXY toMapCoordinates( int x, int y ) const;
122 
124  QgsPointXY toMapCoordinates( double x, double y ) const SIP_PYNAME( toMapCoordinatesF );
125 
131  QgsPointXY toMapCoordinates( QPoint p ) const;
132 
137  Q_DECL_DEPRECATED QgsPointXY toMapPoint( double x, double y ) const SIP_DEPRECATED;
138 
143  void setMapUnitsPerPixel( double mapUnitsPerPixel );
144 
146  double mapUnitsPerPixel() const;
147 
153  int mapWidth() const;
154 
159  int mapHeight() const;
160 
168  void setMapRotation( double degrees, double cx, double cy );
169 
174  double mapRotation() const;
175 
186  void setParameters( double mapUnitsPerPixel, double centerX, double centerY, int widthPixels, int heightPixels, double rotation );
187 
189  QString showParameters() const;
190 
191  QTransform transform() const;
192 
198  double xCenter() const { return mXCenter; }
199 
205  double yCenter() const { return mYCenter; }
206 
207  private:
208  double mMapUnitsPerPixel = 1;
209  int mWidth = 1;
210  int mHeight = 1;
211  double mRotation = 0.0;
212  double mXCenter = 0.5;
213  double mYCenter = 0.5;
214  double xMin = 0;
215  double yMin = 0;
216  QTransform mMatrix;
217 
218  bool updateMatrix();
219 };
220 
221 
222 #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.
double yCenter() const
Returns the center y-coordinate for the transform.
A class to represent a 2D point.
Definition: qgspointxy.h:43
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:36
#define SIP_SKIP
Definition: qgis_sip.h:119
#define SIP_DEPRECATED
Definition: qgis_sip.h:99
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:53
#define SIP_PYNAME(name)
Definition: qgis_sip.h:74