26 , mMapUnits( mapUnits )
46 QgsDebugMsgLevel( QStringLiteral(
"Map units returned as %1" ).arg( QString::number( mMapUnits ) ), 4 );
54 QgsDebugMsg( QStringLiteral(
"Can't calculate scale from the input values" ) );
58 double conversionFactor = 0;
60 calculateMetrics( mapExtent, delta, conversionFactor );
62 const double scale = ( delta * conversionFactor ) / (
static_cast< double >( canvasWidth ) / mDpi );
63 QgsDebugMsgLevel( QStringLiteral(
"scale = %1 conversionFactor = %2" ).arg( scale ).arg( conversionFactor ), 4 );
71 QgsDebugMsg( QStringLiteral(
"Can't calculate image size from the input values" ) );
74 double conversionFactor = 0;
77 calculateMetrics( mapExtent, delta, conversionFactor );
78 const double imageWidth = ( delta * conversionFactor ) / (
static_cast< double >( scale ) ) * mDpi;
80 const double imageHeight = ( deltaHeight * conversionFactor ) / (
static_cast< double >( scale ) ) * mDpi;
82 QgsDebugMsgLevel( QStringLiteral(
"imageWidth = %1 imageHeight = %2 conversionFactor = %3" )
83 .arg( imageWidth ).arg( imageHeight ).arg( conversionFactor ), 4 );
85 return QSizeF( imageWidth, imageHeight );
88 void QgsScaleCalculator::calculateMetrics(
const QgsRectangle &mapExtent,
double &delta,
double &conversionFactor )
const
95 conversionFactor = 39.3700787;
98 conversionFactor = 12.0;
102 conversionFactor = 72913.4;
107 conversionFactor = 39.3700787;
140 static const double RADS = ( 4.0 * std::atan( 1.0 ) ) / 180.0;
141 const double a = std::pow( std::cos( lat * RADS ), 2 );
142 const double c = 2.0 * std::atan2( std::sqrt( a ), std::sqrt( 1.0 - a ) );
143 static const double RA = 6378000;
146 static const double E = 0.0810820288;
147 const double radius = RA * ( 1.0 - E * E ) /
148 std::pow( 1.0 - E * E * std::sin( lat * RADS ) * std::sin( lat * RADS ), 1.5 );
149 const double meters = ( mapExtent.
xMaximum() - mapExtent.
xMinimum() ) / 180.0 * radius *
c;
151 QgsDebugMsgLevel(
"Distance across map extent (m): " + QString::number( meters ), 4 );