27 , mMapUnits( mapUnits )
55 QgsDebugMsg( QStringLiteral(
"Can't calculate scale from the input values" ) );
59 double conversionFactor = 0;
61 calculateMetrics( mapExtent, delta, conversionFactor );
63 const double scale = ( delta * conversionFactor ) / (
static_cast< double >( canvasWidth ) / mDpi );
64 QgsDebugMsgLevel( QStringLiteral(
"scale = %1 conversionFactor = %2" ).arg( scale ).arg( conversionFactor ), 4 );
72 QgsDebugMsg( QStringLiteral(
"Can't calculate image size from the input values" ) );
75 double conversionFactor = 0;
78 calculateMetrics( mapExtent, delta, conversionFactor );
79 const double imageWidth = ( delta * conversionFactor ) / (
static_cast< double >( scale ) ) * mDpi;
81 const double imageHeight = ( deltaHeight * conversionFactor ) / (
static_cast< double >( scale ) ) * mDpi;
83 QgsDebugMsgLevel( QStringLiteral(
"imageWidth = %1 imageHeight = %2 conversionFactor = %3" )
84 .arg( imageWidth ).arg( imageHeight ).arg( conversionFactor ), 4 );
86 return QSizeF( imageWidth, imageHeight );
89void QgsScaleCalculator::calculateMetrics(
const QgsRectangle &mapExtent,
double &delta,
double &conversionFactor )
const
94 case Qgis::DistanceUnit::Meters:
96 conversionFactor = 39.3700787;
98 case Qgis::DistanceUnit::Feet:
99 conversionFactor = 12.0;
101 case Qgis::DistanceUnit::NauticalMiles:
103 conversionFactor = 72913.4;
106 case Qgis::DistanceUnit::Degrees:
108 conversionFactor = 39.3700787;
141 static const double RADS = ( 4.0 * std::atan( 1.0 ) ) / 180.0;
142 const double a = std::pow( std::cos( lat * RADS ), 2 );
143 const double c = 2.0 * std::atan2( std::sqrt( a ), std::sqrt( 1.0 - a ) );
144 static const double RA = 6378000;
147 static const double E = 0.0810820288;
148 const double radius = RA * ( 1.0 - E * E ) /
149 std::pow( 1.0 - E * E * std::sin( lat * RADS ) * std::sin( lat * RADS ), 1.5 );
150 const double meters = ( mapExtent.
xMaximum() - mapExtent.
xMinimum() ) / 180.0 * radius *
c;
152 QgsDebugMsgLevel(
"Distance across map extent (m): " + QString::number( meters ), 4 );
DistanceUnit
Units of distance.
A rectangle specified with double values.
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
double calculate(const QgsRectangle &mapExtent, double canvasWidth) const
Calculate the scale denominator.
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.
double calculateGeographicDistance(const QgsRectangle &mapExtent) const
Calculate the distance between two points in geographic coordinates.
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.
QgsScaleCalculator(double dpi=0, Qgis::DistanceUnit mapUnits=Qgis::DistanceUnit::Meters)
Constructor.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
#define QgsDebugMsgLevel(str, level)