25 : mDpi( dpi ), mMapUnits( mapUnits )
42 QgsDebugMsg( QString(
"Map units set to %1" ).arg( QString::number( mapUnits ) ) );
54 double conversionFactor = 0;
62 conversionFactor = 39.3700787;
66 conversionFactor = 12.0;
71 conversionFactor = 72913.4;
78 conversionFactor = 39.3700787;
82 if ( canvasWidth == 0 ||
mDpi == 0 )
84 QgsDebugMsg(
"Can't calculate scale from the input values" );
87 double scale = ( delta * conversionFactor ) / ((
double )canvasWidth /
mDpi );
88 QgsDebugMsg( QString(
"scale = %1 conversionFactor = %2" ).arg( scale ).arg( conversionFactor ) );
120 const static double rads = ( 4.0 * atan( 1.0 ) ) / 180.0;
121 double a = pow( cos( lat * rads ), 2 );
122 double c = 2.0 * atan2( sqrt( a ), sqrt( 1.0 - a ) );
123 const static double ra = 6378000;
126 const static double e = 0.0810820288;
127 double radius = ra * ( 1.0 - e * e ) /
128 pow( 1.0 - e * e * sin( lat * rads ) * sin( lat * rads ), 1.5 );
129 double meters = ( mapExtent.
xMaximum() - mapExtent.
xMinimum() ) / 180.0 * radius * c;
131 QgsDebugMsg(
"Distance across map extent (m): " + QString::number( meters ) );
void setMapUnits(QGis::UnitType mapUnits)
Set the map units.
double calculateGeographicDistance(const QgsRectangle &mapExtent)
Calculate the distance between two points in geographic coordinates.
A rectangle specified with double values.
double yMaximum() const
Get the y maximum value (top side of rectangle)
void setDpi(double dpi)
Set the dpi to be used in scale calculations.
QGis::UnitType mapUnits() const
Returns current map units.
double calculate(const QgsRectangle &mapExtent, int canvasWidth)
Calculate the scale denominator.
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
double xMaximum() const
Get the x maximum value (right side of rectangle)
#define QgsDebugMsgLevel(str, level)
double dpi()
Accessor for dpi used in scale calculations.
QgsScaleCalculator(double dpi=0, QGis::UnitType mapUnits=QGis::Meters)
Constructor.
~QgsScaleCalculator()
Destructor.
UnitType
Map units that qgis supports.
QGis::UnitType mMapUnits
map unit member
double xMinimum() const
Get the x minimum value (left side of rectangle)