Class: QgsScaleCalculator

Calculates scale for a given combination of canvas size, map extent, and monitor dpi.

Methods

calculate

Calculate the scale denominator.

calculateGeographicDistance

Calculate the distance between two points in geographic coordinates.

calculateImageSize

Calculate the image size in pixel (physical) units.

dpi

Returns the DPI (dots per inch) used in scale calculations.

mapUnits

Returns current map units.

setDpi

Sets the dpi (dots per inch) for the output resolution, to be used in scale calculations.

setMapUnits

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) – QgsRectangle containing the current map extent. Units are specified by mapUnits().

  • 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) – QgsRectangle containing 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) – QgsRectangle containing the current map extent. Units are specified by mapUnits()

  • 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

setDpi()

Return type:

float

mapUnits(self) Qgis.DistanceUnit[source]

Returns current map units.

See also

setMapUnits()

Return type:

Qgis.DistanceUnit

setDpi(self, dpi: float)[source]

Sets the dpi (dots per inch) for the output resolution, to be used in scale calculations.

See also

dpi()

Parameters:

dpi (float)

setMapUnits(self, mapUnits: Qgis.DistanceUnit)[source]

Set the map units.

See also

mapUnits()

Parameters:

mapUnits (Qgis.DistanceUnit)