Skip to content

Commit d38be18

Browse files
author
timlinux
committedOct 21, 2009
[FEATURE] Added option to display position as Degrees,Minutes,Seconds in the status bar
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@11825 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

8 files changed

+237
-171
lines changed

8 files changed

+237
-171
lines changed
 

‎python/core/qgspoint.sip

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ public:
5252

5353
//! As above but with precision for string representaiton of a point
5454
QString toString(int thePrecision) const;
55+
56+
/** Return a string representation as degrees minutes seconds.
57+
* Its up to the calling function to ensure that this point can
58+
* be meaningfully represented in this form.
59+
* @note added in QGIS 1.4
60+
*/
61+
QString toDegreesMinutesSeconds( int thePrecision ) const;
62+
5563

5664
/*! Return the well known text representation for the point.
5765
* The wkt is created without an SRID.

‎src/app/qgisapp.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4593,7 +4593,14 @@ void QgisApp::showMouseCoordinate( const QgsPoint & p )
45934593
}
45944594
else
45954595
{
4596-
mCoordsEdit->setText( p.toString( mMousePrecisionDecimalPlaces ) );
4596+
if ( mMapCanvas->mapUnits() == QGis::DegreesMinutesSeconds )
4597+
{
4598+
mCoordsEdit->setText( p.toDegreesMinutesSeconds( mMousePrecisionDecimalPlaces ) );
4599+
}
4600+
else
4601+
{
4602+
mCoordsEdit->setText( p.toString( mMousePrecisionDecimalPlaces ) );
4603+
}
45974604
if ( mCoordsEdit->width() > mCoordsEdit->minimumWidth() )
45984605
{
45994606
mCoordsEdit->setMinimumWidth( mCoordsEdit->width() );

‎src/app/qgsprojectproperties.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,10 @@ void QgsProjectProperties::setMapUnits( QGis::UnitType unit )
289289
{
290290
radFeet->setChecked( true );
291291
}
292+
else if ( unit == QGis::DegreesMinutesSeconds )
293+
{
294+
radDMS->setChecked( true );
295+
}
292296
else
293297
{
294298
radDecimalDegrees->setChecked( true );
@@ -326,6 +330,10 @@ void QgsProjectProperties::apply()
326330
{
327331
mapUnit = QGis::Feet;
328332
}
333+
else if ( radDMS->isChecked() )
334+
{
335+
mapUnit = QGis::DegreesMinutesSeconds;
336+
}
329337
else
330338
{
331339
mapUnit = QGis::Degrees;

‎src/core/qgis.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,18 @@ class CORE_EXPORT QGis
7474
//! description strings for feature types
7575
static const char *qgisFeatureTypes[];
7676

77-
//! map units that qgis supports
77+
/** Map units that qgis supports
78+
* @note that QGIS < 1.4 api had only Meters, Feet, Degrees and UnknownUnit
79+
*/
7880
enum UnitType
7981
{
80-
Meters,
81-
Feet,
82-
Degrees,
83-
UnknownUnit
82+
Meters = 0,
83+
Feet = 1,
84+
Degrees = 2, //for 1.0 api backwards compatibility
85+
DecimalDegrees = 2,
86+
DegreesMinutesSeconds = 4,
87+
DegreesDecimalMinutes = 5,
88+
UnknownUnit = 3
8489
} ;
8590

8691
//! User defined event types

‎src/core/qgspoint.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "qgspoint.h"
2121
#include <cmath>
2222
#include <QTextStream>
23+
#include <QObject> // for tr()
2324

2425

2526
QgsPoint::QgsPoint( const QgsPoint& p )
@@ -44,6 +45,31 @@ QString QgsPoint::toString( int thePrecision ) const
4445
return rep;
4546
}
4647

48+
QString QgsPoint::toDegreesMinutesSeconds( int thePrecision ) const
49+
{
50+
int myDegreesX = int( std::abs( m_x ) );
51+
float myFloatMinutesX = float( ( std::abs( m_x ) - myDegreesX ) * 60 );
52+
int myIntMinutesX = int( myFloatMinutesX );
53+
float mySecondsX = float ( myFloatMinutesX - myIntMinutesX ) * 60;
54+
55+
int myDegreesY = int( std::abs( m_y ) );
56+
float myFloatMinutesY = float( ( std::abs( m_y ) - myDegreesY ) * 60 );
57+
int myIntMinutesY = int( myFloatMinutesY );
58+
float mySecondsY = float ( myFloatMinutesY - myIntMinutesY ) * 60;
59+
60+
QString myXHemisphere = m_x < 0 ? QObject::tr("W") : QObject::tr("E");
61+
QString myYHemisphere = m_y < 0 ? QObject::tr("S") : QObject::tr("N");
62+
QString rep = QString::number( myDegreesX ) + QChar(176) +
63+
QString::number( myIntMinutesX ) + QString("'") +
64+
QString::number( mySecondsX, 'f', thePrecision ) + QString( "\"" ) +
65+
myXHemisphere + QString( "," ) +
66+
QString::number( myDegreesY ) + QChar(176) +
67+
QString::number( myIntMinutesY ) + QString("'") +
68+
QString::number( mySecondsY, 'f', thePrecision ) + QString( "\"" ) +
69+
myYHemisphere;
70+
return rep;
71+
}
72+
4773

4874
QString QgsPoint::wellKnownText() const
4975
{

‎src/core/qgspoint.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ class CORE_EXPORT QgsPoint
9393
//! As above but with precision for string representaiton of a point
9494
QString toString( int thePrecision ) const;
9595

96+
/** Return a string representation as degrees minutes seconds.
97+
* Its up to the calling function to ensure that this point can
98+
* be meaningfully represented in this form.
99+
* @note added in QGIS 1.4
100+
*/
101+
QString toDegreesMinutesSeconds( int thePrecision ) const;
102+
103+
96104
/*! Return the well known text representation for the point.
97105
* The wkt is created without an SRID.
98106
* @return Well known text in the form POINT(x y)

‎src/core/qgsscalecalculator.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,17 @@ double QgsScaleCalculator::calculate( const QgsRectangle &mapExtent, int canvasW
6868
conversionFactor = 12.0;
6969
delta = mapExtent.xMaximum() - mapExtent.xMinimum();
7070
break;
71-
case QGis::Degrees:
71+
case QGis::DecimalDegrees:
72+
// degrees require conversion to meters first
73+
conversionFactor = 39.3700787;
74+
delta = calculateGeographicDistance( mapExtent );
75+
break;
76+
case QGis::DegreesMinutesSeconds:
77+
// degrees require conversion to meters first
78+
conversionFactor = 39.3700787;
79+
delta = calculateGeographicDistance( mapExtent );
80+
break;
81+
case QGis::DegreesDecimalMinutes:
7282
// degrees require conversion to meters first
7383
conversionFactor = 39.3700787;
7484
delta = calculateGeographicDistance( mapExtent );

‎src/ui/qgsprojectpropertiesbase.ui

Lines changed: 158 additions & 164 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.