Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FEATURE] Added option to display position as Degrees,Minutes,Seconds…
… in the status bar

git-svn-id: http://svn.osgeo.org/qgis/trunk@11825 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux committed Oct 21, 2009
1 parent dc92ab0 commit 49b970a
Show file tree
Hide file tree
Showing 8 changed files with 237 additions and 171 deletions.
8 changes: 8 additions & 0 deletions python/core/qgspoint.sip
Expand Up @@ -52,6 +52,14 @@ public:

//! As above but with precision for string representaiton of a point
QString toString(int thePrecision) const;

/** Return a string representation as degrees minutes seconds.
* Its up to the calling function to ensure that this point can
* be meaningfully represented in this form.
* @note added in QGIS 1.4
*/
QString toDegreesMinutesSeconds( int thePrecision ) const;


/*! Return the well known text representation for the point.
* The wkt is created without an SRID.
Expand Down
9 changes: 8 additions & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -4593,7 +4593,14 @@ void QgisApp::showMouseCoordinate( const QgsPoint & p )
}
else
{
mCoordsEdit->setText( p.toString( mMousePrecisionDecimalPlaces ) );
if ( mMapCanvas->mapUnits() == QGis::DegreesMinutesSeconds )
{
mCoordsEdit->setText( p.toDegreesMinutesSeconds( mMousePrecisionDecimalPlaces ) );
}
else
{
mCoordsEdit->setText( p.toString( mMousePrecisionDecimalPlaces ) );
}
if ( mCoordsEdit->width() > mCoordsEdit->minimumWidth() )
{
mCoordsEdit->setMinimumWidth( mCoordsEdit->width() );
Expand Down
8 changes: 8 additions & 0 deletions src/app/qgsprojectproperties.cpp
Expand Up @@ -289,6 +289,10 @@ void QgsProjectProperties::setMapUnits( QGis::UnitType unit )
{
radFeet->setChecked( true );
}
else if ( unit == QGis::DegreesMinutesSeconds )
{
radDMS->setChecked( true );
}
else
{
radDecimalDegrees->setChecked( true );
Expand Down Expand Up @@ -326,6 +330,10 @@ void QgsProjectProperties::apply()
{
mapUnit = QGis::Feet;
}
else if ( radDMS->isChecked() )
{
mapUnit = QGis::DegreesMinutesSeconds;
}
else
{
mapUnit = QGis::Degrees;
Expand Down
15 changes: 10 additions & 5 deletions src/core/qgis.h
Expand Up @@ -74,13 +74,18 @@ class CORE_EXPORT QGis
//! description strings for feature types
static const char *qgisFeatureTypes[];

//! map units that qgis supports
/** Map units that qgis supports
* @note that QGIS < 1.4 api had only Meters, Feet, Degrees and UnknownUnit
*/
enum UnitType
{
Meters,
Feet,
Degrees,
UnknownUnit
Meters = 0,
Feet = 1,
Degrees = 2, //for 1.0 api backwards compatibility
DecimalDegrees = 2,
DegreesMinutesSeconds = 4,
DegreesDecimalMinutes = 5,
UnknownUnit = 3
} ;

//! User defined event types
Expand Down
26 changes: 26 additions & 0 deletions src/core/qgspoint.cpp
Expand Up @@ -20,6 +20,7 @@
#include "qgspoint.h"
#include <cmath>
#include <QTextStream>
#include <QObject> // for tr()


QgsPoint::QgsPoint( const QgsPoint& p )
Expand All @@ -44,6 +45,31 @@ QString QgsPoint::toString( int thePrecision ) const
return rep;
}

QString QgsPoint::toDegreesMinutesSeconds( int thePrecision ) const
{
int myDegreesX = int( std::abs( m_x ) );
float myFloatMinutesX = float( ( std::abs( m_x ) - myDegreesX ) * 60 );
int myIntMinutesX = int( myFloatMinutesX );
float mySecondsX = float ( myFloatMinutesX - myIntMinutesX ) * 60;

int myDegreesY = int( std::abs( m_y ) );
float myFloatMinutesY = float( ( std::abs( m_y ) - myDegreesY ) * 60 );
int myIntMinutesY = int( myFloatMinutesY );
float mySecondsY = float ( myFloatMinutesY - myIntMinutesY ) * 60;

QString myXHemisphere = m_x < 0 ? QObject::tr("W") : QObject::tr("E");
QString myYHemisphere = m_y < 0 ? QObject::tr("S") : QObject::tr("N");
QString rep = QString::number( myDegreesX ) + QChar(176) +
QString::number( myIntMinutesX ) + QString("'") +
QString::number( mySecondsX, 'f', thePrecision ) + QString( "\"" ) +
myXHemisphere + QString( "," ) +
QString::number( myDegreesY ) + QChar(176) +
QString::number( myIntMinutesY ) + QString("'") +
QString::number( mySecondsY, 'f', thePrecision ) + QString( "\"" ) +
myYHemisphere;
return rep;
}


QString QgsPoint::wellKnownText() const
{
Expand Down
8 changes: 8 additions & 0 deletions src/core/qgspoint.h
Expand Up @@ -93,6 +93,14 @@ class CORE_EXPORT QgsPoint
//! As above but with precision for string representaiton of a point
QString toString( int thePrecision ) const;

/** Return a string representation as degrees minutes seconds.
* Its up to the calling function to ensure that this point can
* be meaningfully represented in this form.
* @note added in QGIS 1.4
*/
QString toDegreesMinutesSeconds( int thePrecision ) const;


/*! Return the well known text representation for the point.
* The wkt is created without an SRID.
* @return Well known text in the form POINT(x y)
Expand Down
12 changes: 11 additions & 1 deletion src/core/qgsscalecalculator.cpp
Expand Up @@ -68,7 +68,17 @@ double QgsScaleCalculator::calculate( const QgsRectangle &mapExtent, int canvasW
conversionFactor = 12.0;
delta = mapExtent.xMaximum() - mapExtent.xMinimum();
break;
case QGis::Degrees:
case QGis::DecimalDegrees:
// degrees require conversion to meters first
conversionFactor = 39.3700787;
delta = calculateGeographicDistance( mapExtent );
break;
case QGis::DegreesMinutesSeconds:
// degrees require conversion to meters first
conversionFactor = 39.3700787;
delta = calculateGeographicDistance( mapExtent );
break;
case QGis::DegreesDecimalMinutes:
// degrees require conversion to meters first
conversionFactor = 39.3700787;
delta = calculateGeographicDistance( mapExtent );
Expand Down

0 comments on commit 49b970a

Please sign in to comment.