14
14
* (at your option) any later version. *
16
16
***************************************************************************/
17
/* $Id: qgsmaptopixel.cpp 4502 2006-01-08 01:18:20Z timlinux $ */
19
#include <qtextstream.h>
21
18
#include "qgsmaptopixel.h"
23
QgsPoint QgsMapToPixel::toMapPoint(int x, int y)
20
#include <QTextStream>
21
#include "qgslogger.h"
23
QgsMapToPixel::QgsMapToPixel( double mapUnitsPerPixel,
27
: mMapUnitsPerPixel( mapUnitsPerPixel ),
31
xMax( 0 ) // XXX wasn't originally specified? Why?
35
QgsMapToPixel::~QgsMapToPixel()
39
QgsPoint QgsMapToPixel::toMapPoint( int x, int y ) const
25
41
double mx = x * mMapUnitsPerPixel + xMin;
26
double my = -1 * ((y - yMax) * mMapUnitsPerPixel - yMin);
27
return QgsPoint(mx, my);
30
QgsPoint QgsMapToPixel::toMapCoordinates(QPoint p)
32
QgsPoint mapPt = toMapPoint(p.x(), p.y());
33
return QgsPoint(mapPt);
36
QgsPoint QgsMapToPixel::toMapCoordinates(int x, int y)
38
return toMapPoint(x, y);
41
void QgsMapToPixel::setMapUnitsPerPixel(double mupp)
43
mMapUnitsPerPixel = mupp;
46
double QgsMapToPixel::mapUnitsPerPixel()
42
double my = -1 * (( y - yMax ) * mMapUnitsPerPixel - yMin );
43
return QgsPoint( mx, my );
46
QgsPoint QgsMapToPixel::toMapCoordinates( QPoint p ) const
48
QgsPoint mapPt = toMapPoint( p.x(), p.y() );
49
return QgsPoint( mapPt );
52
QgsPoint QgsMapToPixel::toMapCoordinates( int x, int y ) const
54
return toMapPoint( x, y );
57
void QgsMapToPixel::setMapUnitsPerPixel( double mapUnitsPerPixel )
59
mMapUnitsPerPixel = mapUnitsPerPixel;
62
double QgsMapToPixel::mapUnitsPerPixel() const
48
64
return mMapUnitsPerPixel;
51
void QgsMapToPixel::setYmax(double ymax)
67
void QgsMapToPixel::setYMaximum( double ymax )
56
void QgsMapToPixel::setYmin(double ymin)
72
void QgsMapToPixel::setYMinimum( double ymin )
61
void QgsMapToPixel::setXmin(double xmin)
77
void QgsMapToPixel::setXMinimum( double xmin )
66
void QgsMapToPixel::setParameters(double mupp, double xmin, double ymin, double ymax)
82
void QgsMapToPixel::setParameters( double mapUnitsPerPixel, double xmin, double ymin, double ymax )
68
mMapUnitsPerPixel = mupp;
84
mMapUnitsPerPixel = mapUnitsPerPixel;
75
91
QString QgsMapToPixel::showParameters()
78
QTextOStream(&rep) << "Map units/pixel: " << mMapUnitsPerPixel
79
<< " X minimum: " << xMin << " Y minimum: " << yMin << " Y maximum: " << yMax;
94
QTextStream( &rep ) << "Map units/pixel: " << mMapUnitsPerPixel
95
<< " X minimum: " << xMin << " Y minimum: " << yMin << " Y maximum: " << yMax;
101
QgsPoint QgsMapToPixel::transform( double x, double y ) const
103
transformInPlace( x, y );
104
return QgsPoint( x, y );
107
QgsPoint QgsMapToPixel::transform( const QgsPoint& p ) const
111
transformInPlace( dx, dy );
113
// QgsDebugMsg(QString("Point to pixel...X : %1-->%2, Y: %3 -->%4").arg(p.x()).arg(dx).arg(p.y()).arg(dy));
114
return QgsPoint( dx, dy );
117
void QgsMapToPixel::transform( QgsPoint* p ) const
121
transformInPlace( x, y );
124
// QgsDebugMsg(QString("Point to pixel...X : %1-->%2, Y: %3 -->%4").arg(p->x()).arg(x).arg(p->y()).arg(y));
129
void QgsMapToPixel::transformInPlace( double& x, double& y ) const
131
x = ( x - xMin ) / mMapUnitsPerPixel;
132
y = yMax - ( y - yMin ) / mMapUnitsPerPixel;
135
void QgsMapToPixel::transformInPlace( std::vector<double>& x,
136
std::vector<double>& y ) const
138
assert( x.size() == y.size() );
139
for ( unsigned int i = 0; i < x.size(); ++i )
140
transformInPlace( x[i], y[i] );