QGIS API Documentation 3.43.0-Master (c67cf405802)
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, Qgis::DistanceUnit mapUnits=Qgis::DistanceUnit::Meters)
 Constructor.
 
double calculate (const QgsRectangle &mapExtent, double canvasWidth) const
 Calculate the scale denominator.
 
double calculateGeographicDistance (const QgsRectangle &mapExtent) const
 Calculate the distance in meters, horizontally across the specified map extent (in geographic coordinates).
 
double calculateGeographicDistanceAtLatitude (double latitude, double longitude1, double longitude2) const
 Calculate the distance in meters, horizontally between two longitudes at a specified latitude.
 
QSizeF calculateImageSize (const QgsRectangle &mapExtent, double scale) const
 Calculate the image size in pixel (physical) units.
 
double dpi () const
 Returns the DPI (dots per inch) used in scale calculations.
 
Qgis::DistanceUnit mapUnits () const
 Returns current map units.
 
Qgis::ScaleCalculationMethod method () const
 Returns the method to use for map scale calculations.
 
void setDpi (double dpi)
 Sets the dpi (dots per inch) for the output resolution, to be used in scale calculations.
 
void setMapUnits (Qgis::DistanceUnit mapUnits)
 Set the map units.
 
void setMethod (Qgis::ScaleCalculationMethod method)
 Sets the method to use for map scale calculations.
 

Detailed Description

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

The calculation defaults to using the scale calculated horizontally across the center of the map, however this may be changed by calling setMethod().

Definition at line 37 of file qgsscalecalculator.h.

Constructor & Destructor Documentation

◆ QgsScaleCalculator()

QgsScaleCalculator::QgsScaleCalculator ( double  dpi = 0,
Qgis::DistanceUnit  mapUnits = Qgis::DistanceUnit::Meters 
)

Constructor.

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

Definition at line 26 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. Units are specified by mapUnits().
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 57 of file qgsscalecalculator.cpp.

◆ calculateGeographicDistance()

double QgsScaleCalculator::calculateGeographicDistance ( const QgsRectangle mapExtent) const

Calculate the distance in meters, horizontally across the specified map extent (in geographic coordinates).

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

This method respects the scale method().

Parameters
mapExtentthe map extent, in geographic (degrees) coordinates
Returns
distance in meters across the map extent

Definition at line 168 of file qgsscalecalculator.cpp.

◆ calculateGeographicDistanceAtLatitude()

double QgsScaleCalculator::calculateGeographicDistanceAtLatitude ( double  latitude,
double  longitude1,
double  longitude2 
) const

Calculate the distance in meters, horizontally between two longitudes at a specified latitude.

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

Parameters
latitudelatitude (in degrees) to calculate distance at
longitude1first longitude (left side of map, or x-minimum) to calculate distance between
longitude2second longitude (right side of map, or x-maximum) to calculate distance between
Returns
distance in meters between the two longitudes
Since
QGIS 3.44

Definition at line 203 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. Units are specified by mapUnits()
scaleScale denominator, e.g. 1000.0 for a 1:1000 map
Returns
image size
Since
QGIS 3.24

Definition at line 74 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 40 of file qgsscalecalculator.cpp.

◆ mapUnits()

Qgis::DistanceUnit QgsScaleCalculator::mapUnits ( ) const

Returns current map units.

See also
setMapUnits()

Definition at line 51 of file qgsscalecalculator.cpp.

◆ method()

Qgis::ScaleCalculationMethod QgsScaleCalculator::method ( ) const
inline

Returns the method to use for map scale calculations.

See also
setMethod()
Since
QGIS 3.44

Definition at line 56 of file qgsscalecalculator.h.

◆ 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 36 of file qgsscalecalculator.cpp.

◆ setMapUnits()

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

Set the map units.

See also
mapUnits()

Definition at line 45 of file qgsscalecalculator.cpp.

◆ setMethod()

void QgsScaleCalculator::setMethod ( Qgis::ScaleCalculationMethod  method)

Sets the method to use for map scale calculations.

See also
method()
Since
QGIS 3.44

Definition at line 31 of file qgsscalecalculator.cpp.


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