Skip to content
Permalink
Browse files

#9060: use QGis::fromUnitToUnitFactor in QgsDistanceArea

 in
  • Loading branch information
ahuarte47 committed Jan 14, 2014
1 parent 5d59d83 commit c20f38b6ba147109532d620b8c69b4d4a73d1dca
Showing with 8 additions and 69 deletions.
  1. +8 −69 src/core/qgsdistancearea.cpp
@@ -989,7 +989,7 @@ QString QgsDistanceArea::textUnit( double value, int decimals, QGis::UnitType u,

void QgsDistanceArea::convertMeasurement( double &measure, QGis::UnitType &measureUnits, QGis::UnitType displayUnits, bool isArea )
{
// Helper for converting between meters and feet
// Helper for converting between meters and feet and degrees and NauticalMiles...
// The parameters measure and measureUnits are in/out

if (( measureUnits == QGis::Degrees || measureUnits == QGis::Feet || measureUnits == QGis::NauticalMiles ) &&
@@ -1001,73 +1001,12 @@ void QgsDistanceArea::convertMeasurement( double &measure, QGis::UnitType &measu
QgsDebugMsg( "We're measuring on an ellipsoid or using projections, the system is returning meters" );
}

// Only convert between meters and feet
if ( measureUnits == QGis::Meters && displayUnits == QGis::Feet )
{
QgsDebugMsg( QString( "Converting %1 meters" ).arg( QString::number( measure ) ) );
measure /= 0.3048;
if ( isArea )
{
measure /= 0.3048;
}
QgsDebugMsg( QString( "to %1 feet" ).arg( QString::number( measure ) ) );
measureUnits = QGis::Feet;
}
if ( measureUnits == QGis::Feet && displayUnits == QGis::Meters )
{
QgsDebugMsg( QString( "Converting %1 feet" ).arg( QString::number( measure ) ) );
measure *= 0.3048;
if ( isArea )
{
measure *= 0.3048;
}
QgsDebugMsg( QString( "to %1 meters" ).arg( QString::number( measure ) ) );
measureUnits = QGis::Meters;
}
// Gets the conversion factor between the specified units
double factorUnits = QGis::fromUnitToUnitFactor( measureUnits, displayUnits );
if ( isArea ) factorUnits *= factorUnits;

if ( measureUnits == QGis::Meters && displayUnits == QGis::NauticalMiles )
{
QgsDebugMsg( QString( "Converting %1 meters" ).arg( QString::number( measure ) ) );
measure /= 1852.0;
if ( isArea )
{
measure /= 1852.0;
}
QgsDebugMsg( QString( "to %1 nautical miles" ).arg( QString::number( measure ) ) );
measureUnits = QGis::NauticalMiles;
}
if ( measureUnits == QGis::NauticalMiles && displayUnits == QGis::Meters )
{
QgsDebugMsg( QString( "Converting %1 nautical miles" ).arg( QString::number( measure ) ) );
measure *= 1852.0;
if ( isArea )
{
measure *= 1852.0;
}
QgsDebugMsg( QString( "to %1 meters" ).arg( QString::number( measure ) ) );
measureUnits = QGis::Meters;
}

if ( measureUnits == QGis::Feet && displayUnits == QGis::NauticalMiles )
{
QgsDebugMsg( QString( "Converting %1 meters" ).arg( QString::number( measure ) ) );
measure /= 6076.12;
if ( isArea )
{
measure /= 6076.12;
}
QgsDebugMsg( QString( "to %1 nautical miles" ).arg( QString::number( measure ) ) );
measureUnits = QGis::Feet;
}
if ( measureUnits == QGis::NauticalMiles && displayUnits == QGis::Feet )
{
QgsDebugMsg( QString( "Converting %1 nautical miles" ).arg( QString::number( measure ) ) );
measure *= 6076.12;
if ( isArea )
{
measure *= 6076.12;
}
QgsDebugMsg( QString( "to %1 meters" ).arg( QString::number( measure ) ) );
measureUnits = QGis::Feet;
}
QgsDebugMsg( QString( "Converting %1 %2" ).arg( QString::number( measure ), QGis::toLiteral( measureUnits ) ) );
measure *= factorUnits;
QgsDebugMsg( QString( "to %1 %2" ).arg( QString::number( measure ), QGis::toLiteral( displayUnits ) ) );
measureUnits = displayUnits;
}

0 comments on commit c20f38b

Please sign in to comment.
You can’t perform that action at this time.