36 , mRotation( rotation )
39 , mXMin( xc - ( mWidth * mMapUnitsPerPixel / 2.0 ) )
40 , mYMin( yc - ( mHeight * mMapUnitsPerPixel / 2.0 ) )
59 const double metersPerPixel = 25.4 / dpi / 1000.0;
69bool QgsMapToPixel::updateMatrix()
74 if ( !newMatrix.isInvertible() )
85 const double oldUnits = mMapUnitsPerPixel;
87 if ( !updateMatrix() )
89 mMapUnitsPerPixel = oldUnits;
97 const double oldRotation = mRotation;
98 const double oldXCenter = mXCenter;
99 const double oldYCenter = mYCenter;
100 const double oldWidth = mWidth;
108 mWidth = ( ( mXCenter - mXMin ) * 2 ) / mMapUnitsPerPixel;
111 if ( !updateMatrix() )
113 mRotation = oldRotation;
114 mXCenter = oldXCenter;
115 mYCenter = oldYCenter;
130 const double oldMUPP = mMapUnitsPerPixel;
131 const double oldXCenter = mXCenter;
132 const double oldYCenter = mYCenter;
133 const double oldWidth = mWidth;
134 const double oldHeight = mHeight;
135 const double oldRotation = mRotation;
136 const double oldXMin = mXMin;
137 const double oldYMin = mYMin;
144 mRotation = rotation;
145 mXMin = xc - ( mWidth * mMapUnitsPerPixel / 2.0 );
146 mYMin = yc - ( mHeight * mMapUnitsPerPixel / 2.0 );
148 if ( !updateMatrix() )
150 mMapUnitsPerPixel = oldMUPP;
151 mXCenter = oldXCenter;
152 mYCenter = oldYCenter;
155 mRotation = oldRotation;
181 QTextStream( &rep ) <<
"Map units/pixel: " << mMapUnitsPerPixel
182 <<
" center: " << mXCenter <<
',' << mYCenter
183 <<
" rotation: " << mRotation
184 <<
" size: " << mWidth <<
'x' << mHeight;
199 return QTransform::fromScale( 1.0 / mMapUnitsPerPixel, -1.0 / mMapUnitsPerPixel )
200 .translate( -mXMin, - ( mYMin + mHeight * mMapUnitsPerPixel ) );
206 return QTransform::fromTranslate( cx, cy )
208 .scale( 1 / mMapUnitsPerPixel, -1 / mMapUnitsPerPixel )
209 .translate( -mXCenter, -mYCenter );
DistanceUnit
Units of distance.
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).