Class: QgsMapToPixel¶
- class qgis.core.QgsMapToPixel¶
Bases:
sip.wrapper
Perform transforms between map coordinates and device coordinates.
This class can convert device coordinates to map coordinates and vice versa.
QgsMapToPixel() Constructor for an invalid QgsMapToPixel.
A manual call to
setParameters()
is required to initialize the object.QgsMapToPixel(mapUnitsPerPixel: float, centerX: float, centerY: float, widthPixels: int, heightPixels: int, rotation: float) 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
New in version 2.8.
QgsMapToPixel(mapUnitsPerPixel: float) Constructor
- Parameters:
mapUnitsPerPixel – Map units per pixel
QgsMapToPixel(
QgsMapToPixel
)Methods
Returns a new
QgsMapToPixel
created using a specifiedscale
and distance unit.Returns
True
if the object is valid (i.e. it has parameters set), orFalse
if the object is default constructed with no parameters set.Returns current map height in pixels
Returns the current map rotation in degrees (clockwise).
Returns the current map units per pixel.
Returns the current map width in pixels.
Sets map rotation in
degrees
(clockwise).Sets the map units per pixel.
Sets parameters for use in transforming coordinates.
Returns a string representation of the parameters used in the transform.
Transforms device coordinates to map (world) coordinates.
Transforms device coordinates to map (world) coordinates.
Transforms device coordinates to map (world) coordinates.
Transforms a point
p
from map (world) coordinates to device coordinates.Transforms device coordinates to map coordinates.
Returns the center x-coordinate for the transform.
Returns the center y-coordinate for the transform.
- fromScale(scale: float, mapUnits: QgsUnitTypes.DistanceUnit, dpi: float = 96) QgsMapToPixel ¶
Returns a new
QgsMapToPixel
created using a specifiedscale
and distance unit.- Parameters:
scale (float) – map scale denominator, e.g. 1000.0 for a 1:1000 map.
dpi (float = 96) – screen DPI
mapUnits (QgsUnitTypes.DistanceUnit) – map units
- Return type:
- Returns:
matching QgsMapToPixel
New in version 3.0.
- isValid(self) bool ¶
Returns
True
if the object is valid (i.e. it has parameters set), orFalse
if the object is default constructed with no parameters set.New in version 3.22.
- Return type:
bool
- mapHeight(self) int ¶
Returns current map height in pixels
See also
New in version 2.8.
- Return type:
int
- mapRotation(self) float ¶
Returns the current map rotation in degrees (clockwise).
See also
New in version 2.8.
- Return type:
float
- mapUnitsPerPixel(self) float ¶
Returns the current map units per pixel.
See also
- Return type:
float
- mapWidth(self) int ¶
Returns the current map width in pixels.
The information is only known if setRotation was used.
See also
New in version 2.8.
- Return type:
int
- setMapRotation(self, degrees: float, cx: float, cy: float)¶
Sets map rotation in
degrees
(clockwise).Calling this method will automatically set the object as valid.
- Parameters:
degrees (float) – clockwise rotation in degrees
cx (float) – X ordinate of map center in geographical units
cy (float) – Y ordinate of map center in geographical units
See also
New in version 2.8.
- setMapUnitsPerPixel(self, mapUnitsPerPixel: float)¶
Sets the map units per pixel.
Calling this method will automatically set the object as valid.
- Parameters:
mapUnitsPerPixel (float) – Map units per pixel
See also
- setParameters(self, mapUnitsPerPixel: float, centerX: float, centerY: float, widthPixels: int, heightPixels: int, rotation: float)¶
Sets parameters for use in transforming coordinates.
Calling this method will automatically set the object as valid.
- Parameters:
mapUnitsPerPixel (float) – Map units per pixel
centerX (float) – X coordinate of map center, in geographical units
centerY (float) – Y coordinate of map center, in geographical units
widthPixels (int) – Output width, in pixels
heightPixels (int) – Output height, in pixels
rotation (float) – clockwise rotation in degrees
Note
if the specified parameters result in an invalid transform then no changes will be applied to the object
New in version 2.8.
- showParameters(self) str ¶
Returns a string representation of the parameters used in the transform.
- Return type:
str
- toMapCoordinates(self, x: int, y: int) QgsPointXY ¶
Transforms device coordinates to map (world) coordinates.
toMapCoordinates(self, p: QPoint) -> QgsPointXY Transforms device coordinates to map (world) coordinates.
- Parameters:
p – Point to be converted to map cooordinates
x (int) –
y (int) –
- Return type:
- Returns:
QgsPointXY
in map coorndiates
- toMapCoordinatesF(self, x: float, y: float) QgsPointXY ¶
Transforms device coordinates to map (world) coordinates.
- Parameters:
x (float) –
y (float) –
- Return type:
- toMapPoint(self, x: float, y: float) QgsPointXY ¶
Transforms device coordinates to map (world) coordinates.
Deprecated since version QGIS: 3.4 use toMapCoordinates instead
- Parameters:
x (float) –
y (float) –
- Return type:
- transform(self, p: QgsPointXY) QgsPointXY ¶
Transforms a point
p
from map (world) coordinates to device coordinates.- Parameters:
p (QgsPointXY) – Point to transform
- Returns:
QgsPointXY
in device coordinates
transform(self, p:
QgsPointXY
) Transforms a pointp
from map (world) coordinates to device coordinates in place.transform(self, x: float, y: float) -> QgsPointXY Transforms the point specified by x,y from map (world) coordinates to device coordinates.
- Parameters:
x – x coordinate of point to transform
y – y coordinate of point to transform
- Return type:
- Returns:
QgsPointXY
in device coordinates
transform(self) -> QTransform Returns a QTransform encapsulating the map to pixel conversion.
- transformInPlace(self) Tuple[float, float] ¶
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.
- Return type:
Tuple[float, float]
- xCenter(self) float ¶
Returns the center x-coordinate for the transform.
See also
New in version 3.0.
- Return type:
float