32 , mMapUnitsPerPixel( mapUnitsPerPixel )
35 , mRotation( rotation )
38 , mXMin( xc - ( mWidth * mMapUnitsPerPixel / 2.0 ) )
39 , mYMin( yc - ( mHeight * mMapUnitsPerPixel / 2.0 ) )
47 , mMapUnitsPerPixel( mapUnitsPerPixel )
58 const double metersPerPixel = 25.4 / dpi / 1000.0;
68bool QgsMapToPixel::updateMatrix()
73 if ( !newMatrix.isInvertible() )
84 const double oldUnits = mMapUnitsPerPixel;
86 if ( !updateMatrix() )
88 mMapUnitsPerPixel = oldUnits;
96 const double oldRotation = mRotation;
97 const double oldXCenter = mXCenter;
98 const double oldYCenter = mYCenter;
99 const double oldWidth = mWidth;
107 mWidth = ( ( mXCenter - mXMin ) * 2 ) / mMapUnitsPerPixel;
110 if ( !updateMatrix() )
112 mRotation = oldRotation;
113 mXCenter = oldXCenter;
114 mYCenter = oldYCenter;
129 const double oldMUPP = mMapUnitsPerPixel;
130 const double oldXCenter = mXCenter;
131 const double oldYCenter = mYCenter;
132 const double oldWidth = mWidth;
133 const double oldHeight = mHeight;
134 const double oldRotation = mRotation;
135 const double oldXMin = mXMin;
136 const double oldYMin = mYMin;
143 mRotation = rotation;
144 mXMin = xc - ( mWidth * mMapUnitsPerPixel / 2.0 );
145 mYMin = yc - ( mHeight * mMapUnitsPerPixel / 2.0 );
147 if ( !updateMatrix() )
149 mMapUnitsPerPixel = oldMUPP;
150 mXCenter = oldXCenter;
151 mYCenter = oldYCenter;
154 mRotation = oldRotation;
180 QTextStream( &rep ) <<
"Map units/pixel: " << mMapUnitsPerPixel
181 <<
" center: " << mXCenter <<
',' << mYCenter
182 <<
" rotation: " << mRotation
183 <<
" size: " << mWidth <<
'x' << mHeight;
198 return QTransform::fromScale( 1.0 / mMapUnitsPerPixel, -1.0 / mMapUnitsPerPixel )
199 .translate( -mXMin, - ( mYMin + mHeight * mMapUnitsPerPixel ) );
205 return QTransform::fromTranslate( cx, cy )
207 .scale( 1 / mMapUnitsPerPixel, -1 / mMapUnitsPerPixel )
208 .translate( -mXCenter, -mYCenter );
DistanceUnit
Units of distance.
Perform transforms between map coordinates and device coordinates.
int mapHeight() const
Returns current map height in pixels.
void setMapUnitsPerPixel(double mapUnitsPerPixel)
Sets the map units per pixel.
void setMapRotation(double degrees, double cx, double cy)
Sets map rotation in degrees (clockwise).
QgsMapToPixel()
Constructor for an invalid QgsMapToPixel.
double mapUnitsPerPixel() const
Returns the current map units per pixel.
static QgsMapToPixel fromScale(double scale, Qgis::DistanceUnit mapUnits, double dpi=96)
Returns a new QgsMapToPixel created using a specified scale and distance unit.
QTransform transform() const
Returns a QTransform encapsulating the map to pixel conversion.
int mapWidth() const
Returns the current map width in pixels.
double mapRotation() const
Returns the current map rotation in degrees (clockwise).
void setParameters(double mapUnitsPerPixel, double centerX, double centerY, int widthPixels, int heightPixels, double rotation)
Sets parameters for use in transforming coordinates.
QString showParameters() const
Returns a string representation of the parameters used in the transform.
static Q_INVOKABLE double fromUnitToUnitFactor(Qgis::DistanceUnit fromUnit, Qgis::DistanceUnit toUnit)
Returns the conversion factor between the specified distance units.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)