mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
Moved convertMeasure to QgsDistanceArea
This commit is contained in:
parent
e455264ac6
commit
a1db95fc98
@ -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 );
|
||||
|
||||
};
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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 );
|
||||
|
Loading…
x
Reference in New Issue
Block a user