Class: QgsScaleCalculator¶
Calculates scale for a given combination of canvas size, map extent, and monitor dpi.
Methods
Calculate the scale denominator.  | 
|
Calculate the distance between two points in geographic coordinates.  | 
|
Calculate the image size in pixel (physical) units.  | 
|
Returns the DPI (dots per inch) used in scale calculations.  | 
|
Returns current map units.  | 
|
Sets the dpi (dots per inch) for the output resolution, to be used in scale calculations.  | 
|
Set the map units.  | 
- class qgis.core.QgsScaleCalculator[source]¶
 Bases:
object- __init__(dpi: float = 0, mapUnits: Qgis.DistanceUnit = Qgis.DistanceUnit.Meters)
 Constructor
- Parameters:
 dpi (float = 0) – Monitor resolution in dots per inch
mapUnits (Qgis.DistanceUnit = Qgis.DistanceUnit.Meters) – Units of the data on the map
- __init__(a0: QgsScaleCalculator)
 - Parameters:
 a0 (QgsScaleCalculator)
- calculate(self, mapExtent: QgsRectangle, canvasWidth: float) float[source]¶
 Calculate the scale denominator.
- Parameters:
 mapExtent (QgsRectangle) –
QgsRectanglecontaining the current map extent. Units are specified bymapUnits().canvasWidth (float) – Width of the map canvas in pixel (physical) units
- Return type:
 float
- Returns:
 scale denominator of current map view, e.g. 1000.0 for a 1:1000 map.
- calculateGeographicDistance(self, mapExtent: QgsRectangle) float[source]¶
 Calculate the distance between two points in geographic coordinates. Used to calculate scale for map views with geographic (decimal degree) data.
- Parameters:
 mapExtent (QgsRectangle) –
QgsRectanglecontaining the current map extent- Return type:
 float
- calculateImageSize(self, mapExtent: QgsRectangle, scale: float) QSizeF[source]¶
 Calculate the image size in pixel (physical) units.
- Parameters:
 mapExtent (QgsRectangle) –
QgsRectanglecontaining the current map extent. Units are specified bymapUnits()scale (float) – Scale denominator, e.g. 1000.0 for a 1:1000 map
- Return type:
 QSizeF
- Returns:
 image size
Added in version 3.24.
- dpi(self) float[source]¶
 Returns the DPI (dots per inch) used in scale calculations.
See also
- Return type:
 float
- mapUnits(self) Qgis.DistanceUnit[source]¶
 Returns current map units.
See also
- Return type:
 
- setDpi(self, dpi: float)[source]¶
 Sets the
dpi(dots per inch) for the output resolution, to be used in scale calculations.See also
- Parameters:
 dpi (float)
- setMapUnits(self, mapUnits: Qgis.DistanceUnit)[source]¶
 Set the map units.
See also
- Parameters:
 mapUnits (Qgis.DistanceUnit)