~ubuntu-branches/ubuntu/trusty/qgis/trusty

« back to all changes in this revision

Viewing changes to src/core/qgsmaptopixel.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Johan Van de Wauw
  • Date: 2010-07-11 20:23:24 UTC
  • mfrom: (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100711202324-5ktghxa7hracohmr
Tags: 1.4.0+12730-3ubuntu1
* Merge from Debian unstable (LP: #540941).
* Fix compilation issues with QT 4.7
* Add build-depends on libqt4-webkit-dev 

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
 *   (at your option) any later version.                                   *
15
15
 *                                                                         *
16
16
 ***************************************************************************/
17
 
 /* $Id: qgsmaptopixel.cpp 4502 2006-01-08 01:18:20Z timlinux $ */
18
 
#include <qstring.h>
19
 
#include <qtextstream.h>
20
 
#include <qpoint.h>
 
17
/* $Id$ */
21
18
#include "qgsmaptopixel.h"
22
 
 
23
 
QgsPoint QgsMapToPixel::toMapPoint(int x, int y)
 
19
#include <QPoint>
 
20
#include <QTextStream>
 
21
#include "qgslogger.h"
 
22
 
 
23
QgsMapToPixel::QgsMapToPixel( double mapUnitsPerPixel,
 
24
                              double ymax,
 
25
                              double ymin,
 
26
                              double xmin )
 
27
    : mMapUnitsPerPixel( mapUnitsPerPixel ),
 
28
    yMax( ymax ),
 
29
    yMin( ymin ),
 
30
    xMin( xmin ),
 
31
    xMax( 0 )                 // XXX wasn't originally specified?  Why?
 
32
{
 
33
}
 
34
 
 
35
QgsMapToPixel::~QgsMapToPixel()
 
36
{
 
37
}
 
38
 
 
39
QgsPoint QgsMapToPixel::toMapPoint( int x, int y ) const
24
40
{
25
41
  double mx = x * mMapUnitsPerPixel + xMin;
26
 
  double my = -1 * ((y - yMax) * mMapUnitsPerPixel - yMin);
27
 
  return QgsPoint(mx, my);
28
 
}
29
 
 
30
 
QgsPoint QgsMapToPixel::toMapCoordinates(QPoint p)
31
 
{
32
 
  QgsPoint mapPt = toMapPoint(p.x(), p.y());
33
 
  return QgsPoint(mapPt);
34
 
}
35
 
 
36
 
QgsPoint QgsMapToPixel::toMapCoordinates(int x, int y)
37
 
{
38
 
  return toMapPoint(x, y);
39
 
}
40
 
 
41
 
void QgsMapToPixel::setMapUnitsPerPixel(double mupp)
42
 
{
43
 
  mMapUnitsPerPixel = mupp;
44
 
}
45
 
 
46
 
double QgsMapToPixel::mapUnitsPerPixel()
 
42
  double my = -1 * (( y - yMax ) * mMapUnitsPerPixel - yMin );
 
43
  return QgsPoint( mx, my );
 
44
}
 
45
 
 
46
QgsPoint QgsMapToPixel::toMapCoordinates( QPoint p ) const
 
47
{
 
48
  QgsPoint mapPt = toMapPoint( p.x(), p.y() );
 
49
  return QgsPoint( mapPt );
 
50
}
 
51
 
 
52
QgsPoint QgsMapToPixel::toMapCoordinates( int x, int y ) const
 
53
{
 
54
  return toMapPoint( x, y );
 
55
}
 
56
 
 
57
void QgsMapToPixel::setMapUnitsPerPixel( double mapUnitsPerPixel )
 
58
{
 
59
  mMapUnitsPerPixel = mapUnitsPerPixel;
 
60
}
 
61
 
 
62
double QgsMapToPixel::mapUnitsPerPixel() const
47
63
{
48
64
  return mMapUnitsPerPixel;
49
65
}
50
66
 
51
 
void QgsMapToPixel::setYmax(double ymax)
 
67
void QgsMapToPixel::setYMaximum( double ymax )
52
68
{
53
69
  yMax = ymax;
54
70
}
55
71
 
56
 
void QgsMapToPixel::setYmin(double ymin)
 
72
void QgsMapToPixel::setYMinimum( double ymin )
57
73
{
58
74
  yMin = ymin;
59
75
}
60
76
 
61
 
void QgsMapToPixel::setXmin(double xmin)
 
77
void QgsMapToPixel::setXMinimum( double xmin )
62
78
{
63
79
  xMin = xmin;
64
80
}
65
81
 
66
 
void QgsMapToPixel::setParameters(double mupp, double xmin, double ymin, double ymax)
 
82
void QgsMapToPixel::setParameters( double mapUnitsPerPixel, double xmin, double ymin, double ymax )
67
83
{
68
 
  mMapUnitsPerPixel = mupp;
 
84
  mMapUnitsPerPixel = mapUnitsPerPixel;
69
85
  xMin = xmin;
70
86
  yMin = ymin;
71
87
  yMax = ymax;
75
91
QString QgsMapToPixel::showParameters()
76
92
{
77
93
  QString rep;
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;
80
96
  return rep;
81
97
 
82
98
}
 
99
 
 
100
 
 
101
QgsPoint QgsMapToPixel::transform( double x, double y ) const
 
102
{
 
103
  transformInPlace( x, y );
 
104
  return QgsPoint( x, y );
 
105
}
 
106
 
 
107
QgsPoint QgsMapToPixel::transform( const QgsPoint& p ) const
 
108
{
 
109
  double dx = p.x();
 
110
  double dy = p.y();
 
111
  transformInPlace( dx, dy );
 
112
 
 
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 );
 
115
}
 
116
 
 
117
void QgsMapToPixel::transform( QgsPoint* p ) const
 
118
{
 
119
  double x = p->x();
 
120
  double y = p->y();
 
121
  transformInPlace( x, y );
 
122
 
 
123
#ifdef QGISDEBUG
 
124
// QgsDebugMsg(QString("Point to pixel...X : %1-->%2, Y: %3 -->%4").arg(p->x()).arg(x).arg(p->y()).arg(y));
 
125
#endif
 
126
  p->set( x, y );
 
127
}
 
128
 
 
129
void QgsMapToPixel::transformInPlace( double& x, double& y ) const
 
130
{
 
131
  x = ( x - xMin ) / mMapUnitsPerPixel;
 
132
  y = yMax - ( y - yMin ) / mMapUnitsPerPixel;
 
133
}
 
134
 
 
135
void QgsMapToPixel::transformInPlace( std::vector<double>& x,
 
136
                                      std::vector<double>& y ) const
 
137
{
 
138
  assert( x.size() == y.size() );
 
139
  for ( unsigned int i = 0; i < x.size(); ++i )
 
140
    transformInPlace( x[i], y[i] );
 
141
}