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: Qgis.DistanceUnit = Qgis.DistanceUnit.Meters) 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.

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.

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

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

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

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

New in version 3.24.

dpi(self) float

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

See also

setDpi()

Return type:

float

mapUnits(self) Qgis.DistanceUnit

Returns current map units.

See also

setMapUnits()

Return type:

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

Set the map units.

See also

mapUnits()

Parameters:

mapUnits (Qgis.DistanceUnit) –