Class: QgsScaleCalculator

class qgis.core.QgsScaleCalculator

Bases: sip.wrapper

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

QgsScaleCalculator(dpi: float = 0, mapUnits: QgsUnitTypes.DistanceUnit = QgsUnitTypes.DistanceMeters) Constructor

Parameters:
  • dpi – Monitor resolution in dots per inch

  • mapUnits – Units of the data on the map

QgsScaleCalculator(QgsScaleCalculator)

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