Skip to content
Permalink
Browse files

[FEATURE] add Nautical miles to measure units (fix #4017). Initial patch

by Jorge Tornero with improvements
  • Loading branch information
alexbruy committed Oct 18, 2013
1 parent 03a60d3 commit 344a5b6e55b363f4f4ee7d4978c7cf44b6f9c8be
@@ -417,6 +417,10 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
{
radFeet->setChecked( true );
}
else if ( myDisplayUnits == QGis::NauticalMiles )
{
radNautical->setChecked( true );
}
else
{
radMeters->setChecked( true );
@@ -1055,6 +1059,10 @@ void QgsOptions::saveOptions()
{
settings.setValue( "/qgis/measure/displayunits", QGis::toLiteral( QGis::Feet ) );
}
else if ( radNautical->isChecked() )
{
settings.setValue( "/qgis/measure/displayunits", QGis::toLiteral( QGis::NauticalMiles ) );
}
else
{
settings.setValue( "/qgis/measure/displayunits", QGis::toLiteral( QGis::Meters ) );
@@ -79,6 +79,7 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa

connect( radMeters, SIGNAL( toggled( bool ) ), btnGrpDegreeDisplay, SLOT( setDisabled( bool ) ) );
connect( radFeet, SIGNAL( toggled( bool ) ), btnGrpDegreeDisplay, SLOT( setDisabled( bool ) ) );
connect( radNMiles, SIGNAL( toggled( bool ) ), btnGrpDegreeDisplay, SLOT( setDisabled( bool ) ) );
connect( radDegrees, SIGNAL( toggled( bool ) ), btnGrpDegreeDisplay, SLOT( setEnabled( bool ) ) );

connect( radAutomatic, SIGNAL( toggled( bool ) ), mPrecisionFrame, SLOT( setDisabled( bool ) ) );
@@ -495,6 +496,7 @@ void QgsProjectProperties::setMapUnits( QGis::UnitType unit )

radMeters->setChecked( unit == QGis::Meters );
radFeet->setChecked( unit == QGis::Feet );
radNMiles->setChecked( unit == QGis::NauticalMiles );
radDegrees->setChecked( unit == QGis::Degrees );

mMapCanvas->mapRenderer()->setMapUnits( unit );
@@ -857,6 +859,7 @@ void QgsProjectProperties::on_cbxProjectionEnabled_toggled( bool onFlyEnabled )

radMeters->setChecked( units == QGis::Meters );
radFeet->setChecked( units == QGis::Feet );
radNMiles->setChecked( units == QGis::NauticalMiles );
radDegrees->setChecked( units == QGis::Degrees );

// unset ellipsoid
@@ -952,6 +955,7 @@ void QgsProjectProperties::setMapUnitsToCurrentProjection()

radMeters->setChecked( units == QGis::Meters );
radFeet->setChecked( units == QGis::Feet );
radNMiles->setChecked( units == QGis::NauticalMiles );
radDegrees->setChecked( units == QGis::Degrees );

// attempt to reset the projection ellipsoid according to the srs
@@ -83,7 +83,8 @@ const char* QGis::qgisUnitTypes[] =
QT_TRANSLATE_NOOP( "QGis::UnitType", "<unknown>" ),
QT_TRANSLATE_NOOP( "QGis::UnitType", "degrees" ),
QT_TRANSLATE_NOOP( "QGis::UnitType", "degrees" ),
QT_TRANSLATE_NOOP( "QGis::UnitType", "degrees" )
QT_TRANSLATE_NOOP( "QGis::UnitType", "degrees" ),
QT_TRANSLATE_NOOP( "QGis::UnitType", "nautical miles" )
};

QGis::UnitType QGis::fromLiteral( QString literal, QGis::UnitType defaultType )
@@ -236,6 +236,7 @@ class CORE_EXPORT QGis
DecimalDegrees = 2, // was 2
DegreesMinutesSeconds = 2, // was 4
DegreesDecimalMinutes = 2, // was 5
NauticalMiles = 7
};

//! Provides the canonical name of the type value
@@ -954,6 +954,16 @@ QString QgsDistanceArea::textUnit( double value, int decimals, QGis::UnitType u,
}
}
break;
case QGis::NauticalMiles:
if ( isArea )
{
unitLabel = QObject::tr( " sq. NM" );
}
else
{
unitLabel = QObject::tr( " NM" );
}
break;
case QGis::Degrees:
if ( isArea )
{
@@ -982,7 +992,7 @@ void QgsDistanceArea::convertMeasurement( double &measure, QGis::UnitType &measu
// Helper for converting between meters and feet
// The parameters measure and measureUnits are in/out

if (( measureUnits == QGis::Degrees || measureUnits == QGis::Feet ) &&
if (( measureUnits == QGis::Degrees || measureUnits == QGis::Feet || measureUnits == QGis::NauticalMiles ) &&
mEllipsoid != GEO_NONE &&
mEllipsoidalMode )
{
@@ -1014,4 +1024,50 @@ void QgsDistanceArea::convertMeasurement( double &measure, QGis::UnitType &measu
QgsDebugMsg( QString( "to %1 meters" ).arg( QString::number( measure ) ) );
measureUnits = QGis::Meters;
}

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;
}
}
@@ -1049,6 +1049,10 @@ bool QgsMapRenderer::readXML( QDomNode & theNode )
{
units = QGis::Feet;
}
else if ( "nautical miles" == element.text() )
{
units = QGis::NauticalMiles;
}
else if ( "degrees" == element.text() )
{
units = QGis::Degrees;
@@ -1121,6 +1125,9 @@ bool QgsMapRenderer::writeXML( QDomNode & theNode, QDomDocument & theDoc )
case QGis::Feet:
unitsString = "feet";
break;
case QGis::NauticalMiles:
unitsString = "nautical miles";
break;
case QGis::Degrees:
unitsString = "degrees";
break;
@@ -66,6 +66,11 @@ double QgsScaleCalculator::calculate( const QgsRectangle &mapExtent, int canvasW
conversionFactor = 12.0;
delta = mapExtent.xMaximum() - mapExtent.xMinimum();
break;
case QGis::NauticalMiles:
// convert nautical miles to inches
conversionFactor = 72913.4;
delta = mapExtent.xMaximum() - mapExtent.xMinimum();
break;

default:
case QGis::Degrees:
@@ -2499,6 +2499,13 @@
<string>Feet</string>
</property>
</widget>
</item>
<item row="5" column="3">
<widget class="QRadioButton" name="radNautical">
<property name="text">
<string>Nautical Miles</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="mAngleUnitsLabel">
@@ -482,7 +482,7 @@
</property>
</spacer>
</item>
<item row="0" column="2">
<item row="0" column="3">
<widget class="QRadioButton" name="radDegrees">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
@@ -495,6 +495,19 @@
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QRadioButton" name="radNMiles">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Nautical miles</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QRadioButton" name="radFeet">
<property name="sizePolicy">
@@ -524,7 +537,7 @@
</property>
</widget>
</item>
<item row="0" column="3" rowspan="2">
<item row="0" column="4" rowspan="2">
<widget class="QGroupBox" name="btnGrpDegreeDisplay">
<property name="enabled">
<bool>false</bool>

0 comments on commit 344a5b6

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