Class: QgsScaleCalculator

class qgis.core.QgsScaleCalculator(dpi: float = 0, mapUnits: QgsUnitTypes.DistanceUnit = QgsUnitTypes.DistanceMeters)

Bases: sip.wrapper

Constructor

Parameters
  • dpi (float = 0) – Monitor resolution in dots per inch

  • mapUnits (QgsUnitTypes.DistanceUnit = QgsUnitTypes.DistanceMeters) – Units of the data on the map

QgsScaleCalculator(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.

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

calculate(self, mapExtent: QgsRectangle, canvasWidth: float) → float

Calculate the scale denominator

Parameters
  • mapExtent (QgsRectangle) – QgsRectangle containing the current map extent

  • 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

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

dpi(self) → float

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

See also

setDpi()

Return type

float

mapUnits(self)QgsUnitTypes.DistanceUnit

Returns current map units

Return type

QgsUnitTypes.DistanceUnit

setDpi(self, dpi: float)

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: QgsUnitTypes.DistanceUnit)

Set the map units

Parameters

mapUnits (QgsUnitTypes.DistanceUnit) – Units of the data on the map. Must match a value from the