QgsMapToPixel class

Perform transforms between map coordinates and device coordinates.

This class can convert device coordinates to map coordinates and vice versa.

Public static functions

static auto fromScale(double scale, QgsUnitTypes::DistanceUnit mapUnits, double dpi = 96) -> QgsMapToPixel
Returns a new QgsMapToPixel created using a specified scale and distance unit.

Constructors, destructors, conversion operators

QgsMapToPixel(double mapUnitsPerPixel, double centerX, double centerY, int widthPixels, int heightPixels, double rotation)
Constructor.
QgsMapToPixel(double mapUnitsPerPixel)
Constructor.
QgsMapToPixel()
Constructor.

Public functions

auto mapHeight() const -> int
Returns current map height in pixels.
auto mapRotation() const -> double
Returns current map rotation in degrees.
auto mapUnitsPerPixel() const -> double
Returns current map units per pixel.
auto mapWidth() const -> int
Returns current map width in pixels The information is only known if setRotation was used.
void setMapRotation(double degrees, double cx, double cy)
Set map rotation in degrees (clockwise)
void setMapUnitsPerPixel(double mapUnitsPerPixel)
Set map units per pixel.
void setParameters(double mapUnitsPerPixel, double centerX, double centerY, int widthPixels, int heightPixels, double rotation)
Set parameters for use in transforming coordinates.
auto showParameters() const -> QString
String representation of the parameters used in the transform.
auto toMapCoordinates(int x, int y) const -> QgsPointXY
Transform device coordinates to map (world) coordinates.
auto toMapCoordinates(double x, double y) const -> QgsPointXY
Transform device coordinates to map (world) coordinates.
auto toMapCoordinates(QPoint p) const -> QgsPointXY
Transform device coordinates to map (world) coordinates.
auto toMapPoint(double x, double y) const -> Q_DECL_DEPRECATED QgsPointXY deprecated
Transform device coordinates to map (world) coordinates.
auto transform(const QgsPointXY& p) const -> QgsPointXY
Transform the point from map (world) coordinates to device coordinates.
auto transform(qreal x, qreal y) const -> QgsPointXY
Transform the point specified by x,y from map (world) coordinates to device coordinates.
void transformInPlace(double& x, double& y) const
Transform device coordinates to map coordinates.
void transformInPlace(float& x, float& y) const
template<class T>
void transformInPlace(QVector<T>& x, QVector<T>& y) const
Transform device coordinates to map coordinates.
auto xCenter() const -> double
Returns the center x-coordinate for the transform.
auto yCenter() const -> double
Returns the center y-coordinate for the transform.

Function documentation

static QgsMapToPixel QgsMapToPixel::fromScale(double scale, QgsUnitTypes::DistanceUnit mapUnits, double dpi = 96)

Returns a new QgsMapToPixel created using a specified scale and distance unit.

Parameters
scale map scale denominator, e.g. 1000.0 for a 1:1000 map.
mapUnits map units
dpi screen DPI
Returns matching QgsMapToPixel

QgsMapToPixel::QgsMapToPixel(double mapUnitsPerPixel, double centerX, double centerY, int widthPixels, int heightPixels, double rotation)

Constructor.

Parameters
mapUnitsPerPixel Map units per pixel
centerX X coordinate of map center, in geographical units
centerY Y coordinate of map center, in geographical units
widthPixels Output width, in pixels
heightPixels Output height, in pixels
rotation clockwise rotation in degrees

QgsMapToPixel::QgsMapToPixel(double mapUnitsPerPixel)

Constructor.

Parameters
mapUnitsPerPixel Map units per pixel

QgsMapToPixel::QgsMapToPixel()

Constructor.

Use setParameters to fill

int QgsMapToPixel::mapHeight() const

Returns current map height in pixels.

double QgsMapToPixel::mapRotation() const

Returns current map rotation in degrees.

int QgsMapToPixel::mapWidth() const

Returns current map width in pixels The information is only known if setRotation was used.

void QgsMapToPixel::setMapRotation(double degrees, double cx, double cy)

Set map rotation in degrees (clockwise)

Parameters
degrees clockwise rotation in degrees
cx X ordinate of map center in geographical units
cy Y ordinate of map center in geographical units

void QgsMapToPixel::setMapUnitsPerPixel(double mapUnitsPerPixel)

Set map units per pixel.

Parameters
mapUnitsPerPixel Map units per pixel

void QgsMapToPixel::setParameters(double mapUnitsPerPixel, double centerX, double centerY, int widthPixels, int heightPixels, double rotation)

Set parameters for use in transforming coordinates.

Parameters
mapUnitsPerPixel Map units per pixel
centerX X coordinate of map center, in geographical units
centerY Y coordinate of map center, in geographical units
widthPixels Output width, in pixels
heightPixels Output height, in pixels
rotation clockwise rotation in degrees

QgsPointXY QgsMapToPixel::toMapCoordinates(QPoint p) const

Transform device coordinates to map (world) coordinates.

Parameters
p Point to be converted to map cooordinates
Returns QgsPointXY in map coorndiates

Q_DECL_DEPRECATED QgsPointXY QgsMapToPixel::toMapPoint(double x, double y) const

Transform device coordinates to map (world) coordinates.

QgsPointXY QgsMapToPixel::transform(const QgsPointXY& p) const

Transform the point from map (world) coordinates to device coordinates.

Parameters
p Point to transform
Returns QgsPointXY in device coordinates

QgsPointXY QgsMapToPixel::transform(qreal x, qreal y) const

Transform the point specified by x,y from map (world) coordinates to device coordinates.

Parameters
x x cordinate o point to transform
y y coordinate of point to transform
Returns QgsPointXY in device coordinates

void QgsMapToPixel::transformInPlace(double& x, double& y) const

Transform device coordinates to map coordinates.

Modifies the given coordinates in place. Intended as a fast way to do the transform.

void QgsMapToPixel::transformInPlace(float& x, float& y) const

template<class T>
void QgsMapToPixel::transformInPlace(QVector<T>& x, QVector<T>& y) const

Transform device coordinates to map coordinates.

Modifies the given coordinates in place. Intended as a fast way to do the transform.

double QgsMapToPixel::xCenter() const

Returns the center x-coordinate for the transform.

double QgsMapToPixel::yCenter() const

Returns the center y-coordinate for the transform.