Skip to content

Commit

Permalink
[FEATURE] add Nautical miles to measure units (fix #4017). Initial patch
Browse files Browse the repository at this point in the history
by Jorge Tornero with improvements
  • Loading branch information
alexbruy committed Oct 18, 2013
1 parent 03a60d3 commit 344a5b6
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/app/qgsoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 ) );
Expand Down
4 changes: 4 additions & 0 deletions src/app/qgsprojectproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ) );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
1 change: 1 addition & 0 deletions src/core/qgis.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
58 changes: 57 additions & 1 deletion src/core/qgsdistancearea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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;
}
}
7 changes: 7 additions & 0 deletions src/core/qgsmaprenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/core/qgsscalecalculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions src/ui/qgsoptionsbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
17 changes: 15 additions & 2 deletions src/ui/qgsprojectpropertiesbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand All @@ -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">
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit 344a5b6

Please sign in to comment.