Skip to content

Commit

Permalink
Moved convertMeasure to QgsDistanceArea
Browse files Browse the repository at this point in the history
  • Loading branch information
homann committed Aug 23, 2012
1 parent e455264 commit a1db95f
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 55 deletions.
3 changes: 3 additions & 0 deletions python/core/qgsdistancearea.sip
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,7 @@ class QgsDistanceArea

static QString textUnit( double value, int decimals, QGis::UnitType u, bool isArea, bool keepBaseUnit = false );

//! Helper for conversion between physical units
void convertMeasurement( double &measure, QGis::UnitType &measureUnits, QGis::displayUnits, bool isArea );

};
34 changes: 7 additions & 27 deletions src/app/qgsmaptoolidentify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,43 +387,23 @@ void QgsMapToolIdentify::convertMeasurement( QgsDistanceArea &calc, double &meas
// Helper for converting between meters and feet
// The parameter &u is out only...

// Get the canvas units
QGis::UnitType myUnits = mCanvas->mapUnits();
if (( myUnits == QGis::Degrees || myUnits == QGis::Feet ) &&
calc.ellipsoid() != "NONE" &&
calc.hasCrsTransformEnabled() )
{
// Measuring on an ellipsoid returns meters, and so does using projections???
myUnits = QGis::Meters;
QgsDebugMsg( "We're measuring on an ellipsoid or using projections, the system is returning meters" );
}

// Get the units for display
QSettings settings;
QString myDisplayUnitsTxt = settings.value( "/qgis/measure/displayunits", "meters" ).toString();

// Only convert between meters and feet
if ( myUnits == QGis::Meters && myDisplayUnitsTxt == "feet" )
QGis::UnitType displayUnits;
if ( myDisplayUnitsTxt == "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 ) ) );
myUnits = QGis::Feet;
displayUnits = QGis::Feet;
}
if ( myUnits == QGis::Feet && myDisplayUnitsTxt == "meters" )
else
{
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 ) ) );
myUnits = QGis::Meters;
displayUnits = QGis::Meters;
}

calc.convertMeasurement( measure, myUnits, displayUnits, isArea );
u = myUnits;
}
36 changes: 8 additions & 28 deletions src/app/qgsmeasuredialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,45 +257,25 @@ void QgsMeasureDialog::convertMeasurement( double &measure, QGis::UnitType &u, b
// Helper for converting between meters and feet
// The parameter &u is out only...

// Get the canvas units
QGis::UnitType myUnits = mTool->canvas()->mapUnits();
QgsDebugMsg( QString( "Canvas units are %1" ).arg( QgsDistanceArea::textUnit( 1.0, 1, myUnits, false, true ) ) );
if (( myUnits == QGis::Degrees || myUnits == QGis::Feet ) &&
mcbProjectionEnabled->isChecked() )
{
// Measuring on an ellipsoid returns meters, and so does using projections???
myUnits = QGis::Meters;
QgsDebugMsg( "We were measuring on an ellipsoid, the calculation returned meters" );
QgsDebugMsg( QString( "Set new units to %1" ).arg( QgsDistanceArea::textUnit( 1.0, 1, myUnits, false, true ) ) );
}

// Get the units for display
QSettings settings;
QString myDisplayUnitsTxt = settings.value( "/qgis/measure/displayunits", "meters" ).toString();
QgsDebugMsg( QString( "Preferred display units are %1" ).arg( myDisplayUnitsTxt ) );
// Only convert between meters and feet
if ( myUnits == QGis::Meters && myDisplayUnitsTxt == "feet" )

QGis::UnitType displayUnits;
if ( myDisplayUnitsTxt == "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 ) ) );
myUnits = QGis::Feet;
displayUnits = QGis::Feet;
}
if ( myUnits == QGis::Feet && myDisplayUnitsTxt == "meters" )
else
{
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 ) ) );
myUnits = QGis::Meters;
displayUnits = QGis::Meters;
}

mDa.convertMeasurement( measure, myUnits, displayUnits, isArea );
u = myUnits;
}

Expand Down
39 changes: 39 additions & 0 deletions src/core/qgsdistancearea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -878,3 +878,42 @@ QString QgsDistanceArea::textUnit( double value, int decimals, QGis::UnitType u,

return QLocale::system().toString( value, 'f', decimals ) + unitLabel;
}

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

if (( measureUnits == QGis::Degrees || measureUnits == QGis::Feet ) &&
mEllipsoid != "NONE" &&
mEllipsoidalEnabled )
{
// Measuring on an ellipsoid returned meters. Force!
measureUnits = QGis::Meters;
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;
}
}
3 changes: 3 additions & 0 deletions src/core/qgsdistancearea.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ class CORE_EXPORT QgsDistanceArea

static QString textUnit( double value, int decimals, QGis::UnitType u, bool isArea, bool keepBaseUnit = false );

//! Helper for conversion between physical units
void convertMeasurement( double &measure, QGis::UnitType &measureUnits, QGis::UnitType displayUnits, bool isArea );

protected:
//! measures line distance, line points are extracted from WKB
unsigned char* measureLine( unsigned char* feature, double* area, bool hasZptr = false );
Expand Down

0 comments on commit a1db95f

Please sign in to comment.