2007-01-09 02:39:15 +00:00
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/** \ingroup core
|
|
|
|
* Perform transforms between map coordinates and device coordinates.
|
|
|
|
*
|
|
|
|
* This class can convert device coordinates to map coordinates and vice versa.
|
|
|
|
*/
|
2007-01-09 02:39:15 +00:00
|
|
|
class QgsMapToPixel
|
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
|
|
|
#include <qgsmaptopixel.h>
|
|
|
|
%End
|
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
public:
|
2016-09-15 18:26:43 +10:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
* @param mapUnitsPerPixel Map units per pixel
|
|
|
|
* @param centerX X coordinate of map center, in geographical units
|
|
|
|
* @param centerY Y coordinate of map center, in geographical units
|
|
|
|
* @param widthPixels Output width, in pixels
|
|
|
|
* @param heightPixels Output height, in pixels
|
|
|
|
* @param rotation clockwise rotation in degrees
|
|
|
|
* @note added in 2.8
|
|
|
|
*/
|
|
|
|
QgsMapToPixel( double mapUnitsPerPixel, double centerX, double centerY, int widthPixels, int heightPixels, double rotation );
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
* @param mapUnitsPerPixel Map units per pixel
|
|
|
|
*/
|
2016-09-15 18:26:43 +10:00
|
|
|
QgsMapToPixel( double mapUnitsPerPixel );
|
|
|
|
|
2016-10-02 22:10:01 +11:00
|
|
|
/** Returns a new QgsMapToPixel created using a specified scale and distance unit.
|
|
|
|
* @param scale map scale
|
|
|
|
* @param dpi screen DPI
|
|
|
|
* @param mapUnits map units
|
|
|
|
* @returns matching QgsMapToPixel
|
|
|
|
* @note added in QGIS 3.0
|
|
|
|
*/
|
|
|
|
static QgsMapToPixel fromScale( double scale, QgsUnitTypes::DistanceUnit mapUnits, double dpi = 96 );
|
|
|
|
|
2016-09-15 18:26:43 +10:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* Use setParameters to fill
|
|
|
|
*/
|
|
|
|
QgsMapToPixel();
|
2016-02-14 03:50:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Transform the point from map (world) coordinates to device coordinates
|
|
|
|
* @param p Point to transform
|
|
|
|
* @return QgsPoint in device coordinates
|
|
|
|
*/
|
2017-05-01 16:42:33 +02:00
|
|
|
QgsPoint transform( const QgsPoint &p ) const;
|
2016-02-14 03:50:23 +01:00
|
|
|
|
2017-05-01 16:42:33 +02:00
|
|
|
void transform( QgsPoint *p ) const;
|
2016-02-14 03:50:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Transform the point specified by x,y from map (world)
|
2007-01-09 02:39:15 +00:00
|
|
|
* coordinates to device coordinates
|
|
|
|
* @param x x cordinate o point to transform
|
|
|
|
* @param y y coordinate of point to transform
|
|
|
|
* @return QgsPoint in device coordinates
|
2016-02-14 03:50:23 +01:00
|
|
|
*/
|
2012-09-24 02:28:15 +02:00
|
|
|
QgsPoint transform( double x, double y ) const;
|
2016-02-14 03:50:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Transform device coordinates to map coordinates. Modifies the
|
|
|
|
* given coordinates in place. Intended as a fast way to do the
|
|
|
|
* transform.
|
|
|
|
*/
|
2017-05-01 16:42:33 +02:00
|
|
|
void transformInPlace( double &x, double &y ) const;
|
2016-02-14 03:50:23 +01:00
|
|
|
|
|
|
|
// @note not available in python bindings
|
2017-05-01 16:42:33 +02:00
|
|
|
// void transformInPlace( qreal &x, qreal &y ) const;
|
2016-02-14 03:50:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Transform device coordinates to map coordinates. Modifies the
|
|
|
|
* given coordinates in place. Intended as a fast way to do the
|
|
|
|
* transform.
|
|
|
|
* @note not available in python bindings
|
2012-09-24 22:40:15 +02:00
|
|
|
*/
|
2015-02-08 22:03:33 +01:00
|
|
|
// template <class T>
|
2017-05-01 16:42:33 +02:00
|
|
|
// void transformInPlace( QVector<double> &x, QVector<double> &y ) const;
|
2007-01-09 02:39:15 +00:00
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
QgsPoint toMapCoordinates( int x, int y ) const;
|
2010-10-23 09:50:23 +00:00
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
//! Transform device coordinates to map (world) coordinates
|
2010-10-23 09:50:23 +00:00
|
|
|
QgsPoint toMapCoordinatesF( double x, double y ) const;
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/**
|
|
|
|
* Transform device coordinates to map (world) coordinates
|
2012-09-24 02:28:15 +02:00
|
|
|
* @param p Point to be converted to map cooordinates
|
|
|
|
* @return QgsPoint in map coorndiates
|
|
|
|
*/
|
|
|
|
QgsPoint toMapCoordinates( QPoint p ) const;
|
|
|
|
|
|
|
|
QgsPoint toMapPoint( double x, double y ) const;
|
2014-10-03 15:52:18 +02:00
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/**
|
|
|
|
* Set map units per pixel
|
|
|
|
* @param mapUnitsPerPixel Map units per pixel
|
|
|
|
*/
|
2012-09-24 02:28:15 +02:00
|
|
|
void setMapUnitsPerPixel( double mapUnitsPerPixel );
|
|
|
|
|
2007-01-09 02:39:15 +00:00
|
|
|
//! Return current map units per pixel
|
2012-09-24 02:28:15 +02:00
|
|
|
double mapUnitsPerPixel() const;
|
2007-01-09 02:39:15 +00:00
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/**
|
|
|
|
* Return current map width in pixels
|
|
|
|
* The information is only known if setRotation was used
|
|
|
|
* @note added in 2.8
|
|
|
|
*/
|
2015-02-03 02:21:52 +01:00
|
|
|
int mapWidth() const;
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/**
|
|
|
|
* Return current map height in pixels
|
|
|
|
* @note added in 2.8
|
|
|
|
*/
|
2015-02-03 02:21:52 +01:00
|
|
|
int mapHeight() const;
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/**
|
|
|
|
* Set map rotation in degrees (clockwise)
|
|
|
|
* @param degrees clockwise rotation in degrees
|
|
|
|
* @param cx X ordinate of map center in geographical units
|
|
|
|
* @param cy Y ordinate of map center in geographical units
|
|
|
|
* @note added in 2.8
|
|
|
|
*/
|
2015-02-03 02:21:52 +01:00
|
|
|
void setMapRotation( double degrees, double cx, double cy );
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/**
|
|
|
|
* Return current map rotation in degrees
|
|
|
|
* @note added in 2.8
|
|
|
|
*/
|
2015-02-03 02:21:52 +01:00
|
|
|
double mapRotation() const;
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/**
|
|
|
|
* Set parameters for use in transforming coordinates
|
|
|
|
* @param mapUnitsPerPixel Map units per pixel
|
2016-09-15 18:26:43 +10:00
|
|
|
* @param centerX X coordinate of map center, in geographical units
|
|
|
|
* @param centerY Y coordinate of map center, in geographical units
|
|
|
|
* @param widthPixels Output width, in pixels
|
|
|
|
* @param heightPixels Output height, in pixels
|
2016-02-14 03:50:23 +01:00
|
|
|
* @param rotation clockwise rotation in degrees
|
|
|
|
* @note added in 2.8
|
|
|
|
*/
|
2016-09-15 18:26:43 +10:00
|
|
|
void setParameters( double mapUnitsPerPixel, double centerX, double centerY, int widthPixels, int heightPixels, double rotation );
|
2015-02-03 02:21:52 +01:00
|
|
|
|
2007-01-09 02:39:15 +00:00
|
|
|
//! String representation of the parameters used in the transform
|
2015-02-08 22:03:33 +01:00
|
|
|
QString showParameters() const;
|
2007-01-09 02:39:15 +00:00
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
QTransform transform() const;
|
2016-09-15 18:26:43 +10:00
|
|
|
|
|
|
|
/** Returns the center x-coordinate for the transform.
|
|
|
|
* @see yCenter()
|
|
|
|
* @note added in QGIS 3.0
|
|
|
|
*/
|
|
|
|
double xCenter() const;
|
|
|
|
|
|
|
|
/** Returns the center y-coordinate for the transform.
|
|
|
|
* @see xCenter()
|
|
|
|
* @note added in QGIS 3.0
|
|
|
|
*/
|
|
|
|
double yCenter() const;
|
2007-01-09 02:39:15 +00:00
|
|
|
};
|