Skip to content
Permalink
Browse files

[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
timlinux committed Oct 21, 2009
1 parent dc92ab0 commit 49b970adfd46018132e1b996ef2a0ad953abcc15
@@ -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.
@@ -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() );
@@ -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 );
@@ -326,6 +330,10 @@ void QgsProjectProperties::apply()
{
mapUnit = QGis::Feet;
}
else if ( radDMS->isChecked() )
{
mapUnit = QGis::DegreesMinutesSeconds;
}
else
{
mapUnit = QGis::Degrees;
@@ -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
@@ -20,6 +20,7 @@
#include "qgspoint.h"
#include <cmath>
#include <QTextStream>
#include <QObject> // for tr()


QgsPoint::QgsPoint( const QgsPoint& p )
@@ -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
{
@@ -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)
@@ -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 );

0 comments on commit 49b970a

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