QGIS API Documentation  3.37.0-Master (a5b4d9743e8)
Public Member Functions | Static Public Member Functions | List of all members
QgsMapToPixel Class Reference

Perform transforms between map coordinates and device coordinates. More...

#include <qgsmaptopixel.h>

Public Member Functions

 QgsMapToPixel ()
 Constructor for an invalid QgsMapToPixel. More...
 
 QgsMapToPixel (double mapUnitsPerPixel)
 Constructor. More...
 
 QgsMapToPixel (double mapUnitsPerPixel, double centerX, double centerY, int widthPixels, int heightPixels, double rotation)
 Constructor. More...
 
bool isValid () const
 Returns true if the object is valid (i.e. More...
 
int mapHeight () const
 Returns current map height in pixels. More...
 
double mapRotation () const
 Returns the current map rotation in degrees (clockwise). More...
 
double mapUnitsPerPixel () const
 Returns the current map units per pixel. More...
 
int mapWidth () const
 Returns the current map width in pixels. More...
 
bool operator!= (const QgsMapToPixel &other) const
 
bool operator== (const QgsMapToPixel &other) const
 
void setMapRotation (double degrees, double cx, double cy)
 Sets map rotation in degrees (clockwise). More...
 
void setMapUnitsPerPixel (double mapUnitsPerPixel)
 Sets the map units per pixel. More...
 
void setParameters (double mapUnitsPerPixel, double centerX, double centerY, int widthPixels, int heightPixels, double rotation)
 Sets parameters for use in transforming coordinates. More...
 
void setParameters (double mapUnitsPerPixel, double centerX, double centerY, int widthPixels, int heightPixels, double rotation, bool *ok)
 Sets parameters for use in transforming coordinates. More...
 
QString showParameters () const
 Returns a string representation of the parameters used in the transform. More...
 
QgsPointXY toMapCoordinates (double x, double y) const
 Transforms device coordinates to map (world) coordinates. More...
 
QgsPointXY toMapCoordinates (int x, int y) const
 Transforms device coordinates to map (world) coordinates. More...
 
QgsPointXY toMapCoordinates (QPoint p) const
 Transforms device coordinates to map (world) coordinates. More...
 
Q_DECL_DEPRECATED QgsPointXY toMapPoint (double x, double y) const
 Transforms device coordinates to map (world) coordinates. More...
 
QTransform transform () const
 Returns a QTransform encapsulating the map to pixel conversion. More...
 
QgsPointXY transform (const QgsPointXY &p) const
 Transforms a point p from map (world) coordinates to device coordinates. More...
 
void transform (QgsPointXY *p) const
 Transforms a point p from map (world) coordinates to device coordinates in place. More...
 
QgsPointXY transform (qreal x, qreal y) const
 Transforms the point specified by x,y from map (world) coordinates to device coordinates. More...
 
void transformInPlace (double &x, double &y) const
 Transforms device coordinates to map coordinates. More...
 
void transformInPlace (float &x, float &y) const
 Transforms device coordinates to map coordinates. More...
 
template<class T >
void transformInPlace (QVector< T > &x, QVector< T > &y) const
 Transforms device coordinates to map coordinates. More...
 
double xCenter () const
 Returns the center x-coordinate for the transform. More...
 
double yCenter () const
 Returns the center y-coordinate for the transform. More...
 

Static Public Member Functions

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

Detailed Description

Perform transforms between map coordinates and device coordinates.

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

Definition at line 38 of file qgsmaptopixel.h.

Constructor & Destructor Documentation

◆ QgsMapToPixel() [1/3]

QgsMapToPixel::QgsMapToPixel ( )

Constructor for an invalid QgsMapToPixel.

A manual call to setParameters() is required to initialize the object.

Definition at line 63 of file qgsmaptopixel.cpp.

◆ QgsMapToPixel() [2/3]

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

Constructor.

Parameters
mapUnitsPerPixelMap units per pixel
centerXX coordinate of map center, in geographical units
centerYY coordinate of map center, in geographical units
widthPixelsOutput width, in pixels
heightPixelsOutput height, in pixels
rotationclockwise rotation in degrees

Definition at line 25 of file qgsmaptopixel.cpp.

◆ QgsMapToPixel() [3/3]

QgsMapToPixel::QgsMapToPixel ( double  mapUnitsPerPixel)

Constructor.

Parameters
mapUnitsPerPixelMap units per pixel

Definition at line 45 of file qgsmaptopixel.cpp.

Member Function Documentation

◆ fromScale()

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

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

Parameters
scalemap scale denominator, e.g. 1000.0 for a 1:1000 map.
dpiscreen DPI
mapUnitsmap units
Returns
matching QgsMapToPixel

Definition at line 56 of file qgsmaptopixel.cpp.

◆ isValid()

bool QgsMapToPixel::isValid ( ) const
inline

Returns true if the object is valid (i.e.

it has parameters set), or false if the object is default constructed with no parameters set.

Since
QGIS 3.22

Definition at line 81 of file qgsmaptopixel.h.

◆ mapHeight()

int QgsMapToPixel::mapHeight ( ) const
inline

Returns current map height in pixels.

See also
mapWidth()

Definition at line 246 of file qgsmaptopixel.h.

◆ mapRotation()

double QgsMapToPixel::mapRotation ( ) const
inline

Returns the current map rotation in degrees (clockwise).

See also
setMapRotation()

Definition at line 266 of file qgsmaptopixel.h.

◆ mapUnitsPerPixel()

double QgsMapToPixel::mapUnitsPerPixel ( ) const
inline

Returns the current map units per pixel.

See also
setMapUnitsPerPixel()

Definition at line 230 of file qgsmaptopixel.h.

◆ mapWidth()

int QgsMapToPixel::mapWidth ( ) const
inline

Returns the current map width in pixels.

The information is only known if setRotation was used.

See also
mapHeight()

Definition at line 239 of file qgsmaptopixel.h.

◆ operator!=()

bool QgsMapToPixel::operator!= ( const QgsMapToPixel other) const
inline

Definition at line 336 of file qgsmaptopixel.h.

◆ operator==()

bool QgsMapToPixel::operator== ( const QgsMapToPixel other) const
inline

Definition at line 323 of file qgsmaptopixel.h.

◆ setMapRotation()

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

Sets map rotation in degrees (clockwise).

Calling this method will automatically set the object as valid.

Parameters
degreesclockwise rotation in degrees
cxX ordinate of map center in geographical units
cyY ordinate of map center in geographical units
See also
mapRotation()

Definition at line 92 of file qgsmaptopixel.cpp.

◆ setMapUnitsPerPixel()

void QgsMapToPixel::setMapUnitsPerPixel ( double  mapUnitsPerPixel)

Sets the map units per pixel.

Calling this method will automatically set the object as valid.

Parameters
mapUnitsPerPixelMap units per pixel
See also
mapUnitsPerPixel()

Definition at line 80 of file qgsmaptopixel.cpp.

◆ setParameters() [1/2]

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

Sets parameters for use in transforming coordinates.

Calling this method will automatically set the object as valid.

Parameters
mapUnitsPerPixelMap units per pixel
centerXX coordinate of map center, in geographical units
centerYY coordinate of map center, in geographical units
widthPixelsOutput width, in pixels
heightPixelsOutput height, in pixels
rotationclockwise rotation in degrees
Note
if the specified parameters result in an invalid transform then no changes will be applied to the object

Definition at line 165 of file qgsmaptopixel.cpp.

◆ setParameters() [2/2]

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

Sets parameters for use in transforming coordinates.

Calling this method will automatically set the object as valid.

Parameters
mapUnitsPerPixelMap units per pixel
centerXX coordinate of map center, in geographical units
centerYY coordinate of map center, in geographical units
widthPixelsOutput width, in pixels
heightPixelsOutput height, in pixels
rotationclockwise rotation in degrees
okwill be set to true if the specified parameters result in a valid transform, otherwise the changes are ignored and ok will be set to false.
Since
QGIS 3.20

Definition at line 119 of file qgsmaptopixel.cpp.

◆ showParameters()

QString QgsMapToPixel::showParameters ( ) const

Returns a string representation of the parameters used in the transform.

Definition at line 177 of file qgsmaptopixel.cpp.

◆ toMapCoordinates() [1/3]

QgsPointXY QgsMapToPixel::toMapCoordinates ( double  x,
double  y 
) const
inline

Transforms device coordinates to map (world) coordinates.

Definition at line 182 of file qgsmaptopixel.h.

◆ toMapCoordinates() [2/3]

QgsPointXY QgsMapToPixel::toMapCoordinates ( int  x,
int  y 
) const
inline

Transforms device coordinates to map (world) coordinates.

Definition at line 174 of file qgsmaptopixel.h.

◆ toMapCoordinates() [3/3]

QgsPointXY QgsMapToPixel::toMapCoordinates ( QPoint  p) const
inline

Transforms device coordinates to map (world) coordinates.

Parameters
pPoint to be converted to map cooordinates
Returns
QgsPointXY in map coorndiates

Definition at line 198 of file qgsmaptopixel.h.

◆ toMapPoint()

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

Transforms device coordinates to map (world) coordinates.

Deprecated:
since QGIS 3.4 use toMapCoordinates instead

Definition at line 209 of file qgsmaptopixel.h.

◆ transform() [1/4]

QTransform QgsMapToPixel::transform ( ) const

Returns a QTransform encapsulating the map to pixel conversion.

Definition at line 187 of file qgsmaptopixel.cpp.

◆ transform() [2/4]

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

Transforms a point p from map (world) coordinates to device coordinates.

Parameters
pPoint to transform
Returns
QgsPointXY in device coordinates

Definition at line 88 of file qgsmaptopixel.h.

◆ transform() [3/4]

void QgsMapToPixel::transform ( QgsPointXY p) const
inline

Transforms a point p from map (world) coordinates to device coordinates in place.

Definition at line 99 of file qgsmaptopixel.h.

◆ transform() [4/4]

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

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

Parameters
xx coordinate of point to transform
yy coordinate of point to transform
Returns
QgsPointXY in device coordinates

Definition at line 114 of file qgsmaptopixel.h.

◆ transformInPlace() [1/3]

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

Transforms device coordinates to map coordinates.

This method modifies the given coordinates in place. It is intended as a fast way to do the transform.

Definition at line 126 of file qgsmaptopixel.h.

◆ transformInPlace() [2/3]

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

Transforms device coordinates to map coordinates.

This method modifies the given coordinates in place. It is intended as a fast way to do the transform.

Note
Not available in Python bindings

Definition at line 142 of file qgsmaptopixel.h.

◆ transformInPlace() [3/3]

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

Transforms device coordinates to map coordinates.

This method modifies the given coordinates in place. It is intended as a fast way to do the transform.

Note
not available in Python bindings

Definition at line 160 of file qgsmaptopixel.h.

◆ xCenter()

double QgsMapToPixel::xCenter ( ) const
inline

Returns the center x-coordinate for the transform.

See also
yCenter()

Definition at line 315 of file qgsmaptopixel.h.

◆ yCenter()

double QgsMapToPixel::yCenter ( ) const
inline

Returns the center y-coordinate for the transform.

See also
xCenter()

Definition at line 321 of file qgsmaptopixel.h.


The documentation for this class was generated from the following files: