QGIS API Documentation  3.27.0-Master (e113457133)
Public Member Functions | List of all members
QgsScaleCalculator Class Reference

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

#include <qgsscalecalculator.h>

Public Member Functions

 QgsScaleCalculator (double dpi=0, QgsUnitTypes::DistanceUnit mapUnits=QgsUnitTypes::DistanceMeters)
 Constructor. More...
 
double calculate (const QgsRectangle &mapExtent, double canvasWidth) const
 Calculate the scale denominator. More...
 
double calculateGeographicDistance (const QgsRectangle &mapExtent) const
 Calculate the distance between two points in geographic coordinates. More...
 
QSizeF calculateImageSize (const QgsRectangle &mapExtent, double scale) const
 Calculate the image size in pixel (physical) units. More...
 
double dpi () const
 Returns the DPI (dots per inch) used in scale calculations. More...
 
QgsUnitTypes::DistanceUnit mapUnits () const
 Returns current map units. More...
 
void setDpi (double dpi)
 Sets the dpi (dots per inch) for the output resolution, to be used in scale calculations. More...
 
void setMapUnits (QgsUnitTypes::DistanceUnit mapUnits)
 Set the map units. More...
 

Detailed Description

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

Definition at line 34 of file qgsscalecalculator.h.

Constructor & Destructor Documentation

◆ QgsScaleCalculator()

QgsScaleCalculator::QgsScaleCalculator ( double  dpi = 0,
QgsUnitTypes::DistanceUnit  mapUnits = QgsUnitTypes::DistanceMeters 
)

Constructor.

Parameters
dpiMonitor resolution in dots per inch
mapUnitsUnits of the data on the map

Definition at line 24 of file qgsscalecalculator.cpp.

Member Function Documentation

◆ calculate()

double QgsScaleCalculator::calculate ( const QgsRectangle mapExtent,
double  canvasWidth 
) const

Calculate the scale denominator.

Parameters
mapExtentQgsRectangle containing the current map extent
canvasWidthWidth of the map canvas in pixel (physical) units
Returns
scale denominator of current map view, e.g. 1000.0 for a 1:1000 map.

Definition at line 50 of file qgsscalecalculator.cpp.

◆ calculateGeographicDistance()

double QgsScaleCalculator::calculateGeographicDistance ( const QgsRectangle mapExtent) const

Calculate the distance between two points in geographic coordinates.

Used to calculate scale for map views with geographic (decimal degree) data.

Parameters
mapExtentQgsRectangle containing the current map extent

Definition at line 113 of file qgsscalecalculator.cpp.

◆ calculateImageSize()

QSizeF QgsScaleCalculator::calculateImageSize ( const QgsRectangle mapExtent,
double  scale 
) const

Calculate the image size in pixel (physical) units.

Parameters
mapExtentQgsRectangle containing the current map extent
scaleScale denominator, e.g. 1000.0 for a 1:1000 map
Returns
image size
Since
QGIS 3.24

Definition at line 67 of file qgsscalecalculator.cpp.

◆ dpi()

double QgsScaleCalculator::dpi ( ) const

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

See also
setDpi()

Definition at line 33 of file qgsscalecalculator.cpp.

◆ mapUnits()

QgsUnitTypes::DistanceUnit QgsScaleCalculator::mapUnits ( ) const

Returns current map units.

Definition at line 44 of file qgsscalecalculator.cpp.

◆ setDpi()

void QgsScaleCalculator::setDpi ( double  dpi)

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

See also
dpi()

Definition at line 29 of file qgsscalecalculator.cpp.

◆ setMapUnits()

void QgsScaleCalculator::setMapUnits ( QgsUnitTypes::DistanceUnit  mapUnits)

Set the map units.

Parameters
mapUnitsUnits of the data on the map. Must match a value from the

Definition at line 38 of file qgsscalecalculator.cpp.


The documentation for this class was generated from the following files: