mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
Remove coordinate formatting methods from QgsPointXY
Use QgsCoordinateFormatter instead
This commit is contained in:
parent
0d7b828bda
commit
95765a191a
@ -1963,6 +1963,7 @@ QgsPoint {#qgis_api_break_3_0_QgsPoint}
|
||||
--------
|
||||
|
||||
- onSegment() has been removed. Use sqrDistToSegment() instead for a more precise test.
|
||||
- toDegreesMinutesSeconds() and toDegreesMinutes() have been removed. Use QgsCoordinateFormatter instead.
|
||||
|
||||
|
||||
QgsPointDisplacementRenderer {#qgis_api_break_3_0_QgsPointDisplacementRenderer}
|
||||
|
@ -74,6 +74,18 @@ class QgsCoordinateFormatter
|
||||
:rtype: str
|
||||
%End
|
||||
|
||||
static QString format( QgsPointXY point, Format format, int precision = 12, FormatFlags flags = FlagDegreesUseStringSuffix );
|
||||
%Docstring
|
||||
Formats a ``point`` according to the specified parameters.
|
||||
|
||||
The ``format`` argument indicates the desired display format for the coordinate.
|
||||
|
||||
The ``precision`` argument gives the number of decimal places to include for coordinates.
|
||||
|
||||
Optional ``flags`` can be specified to control the output format.
|
||||
:rtype: str
|
||||
%End
|
||||
|
||||
static QString asPair( double x, double y, int precision = 12 );
|
||||
%Docstring
|
||||
Formats coordinates as an "``x``,``y``" pair, with optional decimal ``precision`` (number
|
||||
@ -83,6 +95,9 @@ class QgsCoordinateFormatter
|
||||
|
||||
};
|
||||
|
||||
QFlags<QgsCoordinateFormatter::FormatFlag> operator|(QgsCoordinateFormatter::FormatFlag f1, QFlags<QgsCoordinateFormatter::FormatFlag> f2);
|
||||
|
||||
|
||||
/************************************************************************
|
||||
* This file has been generated automatically from *
|
||||
* *
|
||||
|
@ -105,45 +105,12 @@ Sets the x and y value of the point
|
||||
:rtype: QPointF
|
||||
%End
|
||||
|
||||
QString toString() const;
|
||||
QString toString( int precision = 12 ) const;
|
||||
%Docstring
|
||||
String representation of the point (x,y)
|
||||
Returns a string representation of the point (x, y) with a preset ``precision``.
|
||||
:rtype: str
|
||||
%End
|
||||
|
||||
QString toString( int precision ) const;
|
||||
%Docstring
|
||||
As above but with precision for string representation of a point
|
||||
:rtype: str
|
||||
%End
|
||||
|
||||
QString toDegreesMinutesSeconds( int precision, const bool useSuffix = true, const bool padded = false ) const;
|
||||
%Docstring
|
||||
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.
|
||||
\param precision number of decimal points to use for seconds
|
||||
\param useSuffix set to true to include a direction suffix (e.g., 'N'),
|
||||
set to false to use a "-" prefix for west and south coordinates
|
||||
\param padded set to true to force minutes and seconds to use two decimals,
|
||||
e.g., '05' instead of '5'.
|
||||
:rtype: str
|
||||
%End
|
||||
|
||||
QString toDegreesMinutes( int precision, const bool useSuffix = true, const bool padded = false ) const;
|
||||
%Docstring
|
||||
Return a string representation as degrees minutes.
|
||||
Its up to the calling function to ensure that this point can
|
||||
be meaningfully represented in this form.
|
||||
\param precision number of decimal points to use for minutes
|
||||
\param useSuffix set to true to include a direction suffix (e.g., 'N'),
|
||||
set to false to use a "-" prefix for west and south coordinates
|
||||
\param padded set to true to force minutes to use two decimals,
|
||||
e.g., '05' instead of '5'.
|
||||
:rtype: str
|
||||
%End
|
||||
|
||||
|
||||
QString wellKnownText() const;
|
||||
%Docstring
|
||||
Return the well known text representation for the point.
|
||||
|
@ -33,7 +33,7 @@
|
||||
#include "qgsexpressioncontext.h"
|
||||
#include "qgsexception.h"
|
||||
#include "qgssettings.h"
|
||||
|
||||
#include "qgscoordinateformatter.h"
|
||||
#include <QPainter>
|
||||
#include <QPen>
|
||||
|
||||
@ -1484,49 +1484,56 @@ QString QgsComposerMapGrid::gridAnnotationString( double value, QgsComposerMapGr
|
||||
return mGridAnnotationExpression->evaluate( &expressionContext ).toString();
|
||||
}
|
||||
|
||||
QgsPointXY p;
|
||||
p.setX( coord == QgsComposerMapGrid::Longitude ? value : 0 );
|
||||
p.setY( coord == QgsComposerMapGrid::Longitude ? 0 : value );
|
||||
QgsCoordinateFormatter::Format format = QgsCoordinateFormatter::FormatDecimalDegrees;
|
||||
QgsCoordinateFormatter::FormatFlags flags = 0;
|
||||
switch ( mGridAnnotationFormat )
|
||||
{
|
||||
case Decimal:
|
||||
case DecimalWithSuffix:
|
||||
case CustomFormat:
|
||||
break; // already handled above
|
||||
|
||||
QString annotationString;
|
||||
if ( mGridAnnotationFormat == QgsComposerMapGrid::DegreeMinute )
|
||||
{
|
||||
annotationString = p.toDegreesMinutes( mGridAnnotationPrecision );
|
||||
}
|
||||
else if ( mGridAnnotationFormat == QgsComposerMapGrid::DegreeMinuteNoSuffix )
|
||||
{
|
||||
annotationString = p.toDegreesMinutes( mGridAnnotationPrecision, false );
|
||||
}
|
||||
else if ( mGridAnnotationFormat == QgsComposerMapGrid::DegreeMinutePadded )
|
||||
{
|
||||
annotationString = p.toDegreesMinutes( mGridAnnotationPrecision, true, true );
|
||||
}
|
||||
else if ( mGridAnnotationFormat == QgsComposerMapGrid::DegreeMinuteSecond )
|
||||
{
|
||||
annotationString = p.toDegreesMinutesSeconds( mGridAnnotationPrecision );
|
||||
}
|
||||
else if ( mGridAnnotationFormat == QgsComposerMapGrid::DegreeMinuteSecondNoSuffix )
|
||||
{
|
||||
annotationString = p.toDegreesMinutesSeconds( mGridAnnotationPrecision, false );
|
||||
}
|
||||
else if ( mGridAnnotationFormat == QgsComposerMapGrid::DegreeMinuteSecondPadded )
|
||||
{
|
||||
annotationString = p.toDegreesMinutesSeconds( mGridAnnotationPrecision, true, true );
|
||||
case DegreeMinute:
|
||||
format = QgsCoordinateFormatter::FormatDegreesMinutes;
|
||||
flags = QgsCoordinateFormatter::FlagDegreesUseStringSuffix;
|
||||
break;
|
||||
|
||||
case DegreeMinuteSecond:
|
||||
format = QgsCoordinateFormatter::FormatDegreesMinutesSeconds;
|
||||
flags = QgsCoordinateFormatter::FlagDegreesUseStringSuffix;
|
||||
break;
|
||||
|
||||
case DegreeMinuteNoSuffix:
|
||||
format = QgsCoordinateFormatter::FormatDegreesMinutes;
|
||||
flags = 0;
|
||||
break;
|
||||
|
||||
case DegreeMinutePadded:
|
||||
format = QgsCoordinateFormatter::FormatDegreesMinutes;
|
||||
flags = QgsCoordinateFormatter::FlagDegreesUseStringSuffix | QgsCoordinateFormatter::FlagDegreesPadMinutesSeconds;
|
||||
break;
|
||||
|
||||
case DegreeMinuteSecondNoSuffix:
|
||||
format = QgsCoordinateFormatter::FormatDegreesMinutesSeconds;
|
||||
flags = 0;
|
||||
break;
|
||||
|
||||
case DegreeMinuteSecondPadded:
|
||||
format = QgsCoordinateFormatter::FormatDegreesMinutesSeconds;
|
||||
flags = QgsCoordinateFormatter::FlagDegreesUseStringSuffix | QgsCoordinateFormatter::FlagDegreesPadMinutesSeconds;
|
||||
break;
|
||||
}
|
||||
|
||||
QStringList split = annotationString.split( ',' );
|
||||
if ( coord == QgsComposerMapGrid::Longitude )
|
||||
switch ( coord )
|
||||
{
|
||||
return split.at( 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( split.size() < 2 )
|
||||
{
|
||||
return QLatin1String( "" );
|
||||
}
|
||||
return split.at( 1 );
|
||||
case Longitude:
|
||||
return QgsCoordinateFormatter::formatX( value, format, flags );
|
||||
|
||||
case Latitude:
|
||||
return QgsCoordinateFormatter::formatY( value, format, flags );
|
||||
}
|
||||
|
||||
return QString(); // no warnings
|
||||
}
|
||||
|
||||
int QgsComposerMapGrid::xGridLines( QList< QPair< double, QLineF > > &lines ) const
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "qgsexpressioncontext.h"
|
||||
#include "qgsexception.h"
|
||||
#include "qgssettings.h"
|
||||
#include "qgscoordinateformatter.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QPen>
|
||||
@ -1410,49 +1411,56 @@ QString QgsLayoutItemMapGrid::gridAnnotationString( double value, QgsLayoutItemM
|
||||
return mGridAnnotationExpression->evaluate( &expressionContext ).toString();
|
||||
}
|
||||
|
||||
QgsPointXY p;
|
||||
p.setX( coord == QgsLayoutItemMapGrid::Longitude ? value : 0 );
|
||||
p.setY( coord == QgsLayoutItemMapGrid::Longitude ? 0 : value );
|
||||
QgsCoordinateFormatter::Format format = QgsCoordinateFormatter::FormatDecimalDegrees;
|
||||
QgsCoordinateFormatter::FormatFlags flags = 0;
|
||||
switch ( mGridAnnotationFormat )
|
||||
{
|
||||
case Decimal:
|
||||
case DecimalWithSuffix:
|
||||
case CustomFormat:
|
||||
break; // already handled above
|
||||
|
||||
QString annotationString;
|
||||
if ( mGridAnnotationFormat == QgsLayoutItemMapGrid::DegreeMinute )
|
||||
{
|
||||
annotationString = p.toDegreesMinutes( mGridAnnotationPrecision );
|
||||
}
|
||||
else if ( mGridAnnotationFormat == QgsLayoutItemMapGrid::DegreeMinuteNoSuffix )
|
||||
{
|
||||
annotationString = p.toDegreesMinutes( mGridAnnotationPrecision, false );
|
||||
}
|
||||
else if ( mGridAnnotationFormat == QgsLayoutItemMapGrid::DegreeMinutePadded )
|
||||
{
|
||||
annotationString = p.toDegreesMinutes( mGridAnnotationPrecision, true, true );
|
||||
}
|
||||
else if ( mGridAnnotationFormat == QgsLayoutItemMapGrid::DegreeMinuteSecond )
|
||||
{
|
||||
annotationString = p.toDegreesMinutesSeconds( mGridAnnotationPrecision );
|
||||
}
|
||||
else if ( mGridAnnotationFormat == QgsLayoutItemMapGrid::DegreeMinuteSecondNoSuffix )
|
||||
{
|
||||
annotationString = p.toDegreesMinutesSeconds( mGridAnnotationPrecision, false );
|
||||
}
|
||||
else if ( mGridAnnotationFormat == QgsLayoutItemMapGrid::DegreeMinuteSecondPadded )
|
||||
{
|
||||
annotationString = p.toDegreesMinutesSeconds( mGridAnnotationPrecision, true, true );
|
||||
case DegreeMinute:
|
||||
format = QgsCoordinateFormatter::FormatDegreesMinutes;
|
||||
flags = QgsCoordinateFormatter::FlagDegreesUseStringSuffix;
|
||||
break;
|
||||
|
||||
case DegreeMinuteSecond:
|
||||
format = QgsCoordinateFormatter::FormatDegreesMinutesSeconds;
|
||||
flags = QgsCoordinateFormatter::FlagDegreesUseStringSuffix;
|
||||
break;
|
||||
|
||||
case DegreeMinuteNoSuffix:
|
||||
format = QgsCoordinateFormatter::FormatDegreesMinutes;
|
||||
flags = 0;
|
||||
break;
|
||||
|
||||
case DegreeMinutePadded:
|
||||
format = QgsCoordinateFormatter::FormatDegreesMinutes;
|
||||
flags = QgsCoordinateFormatter::FlagDegreesUseStringSuffix | QgsCoordinateFormatter::FlagDegreesPadMinutesSeconds;
|
||||
break;
|
||||
|
||||
case DegreeMinuteSecondNoSuffix:
|
||||
format = QgsCoordinateFormatter::FormatDegreesMinutesSeconds;
|
||||
flags = 0;
|
||||
break;
|
||||
|
||||
case DegreeMinuteSecondPadded:
|
||||
format = QgsCoordinateFormatter::FormatDegreesMinutesSeconds;
|
||||
flags = QgsCoordinateFormatter::FlagDegreesUseStringSuffix | QgsCoordinateFormatter::FlagDegreesPadMinutesSeconds;
|
||||
break;
|
||||
}
|
||||
|
||||
QStringList split = annotationString.split( ',' );
|
||||
if ( coord == QgsLayoutItemMapGrid::Longitude )
|
||||
switch ( coord )
|
||||
{
|
||||
return split.at( 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( split.size() < 2 )
|
||||
{
|
||||
return QLatin1String( "" );
|
||||
}
|
||||
return split.at( 1 );
|
||||
case Longitude:
|
||||
return QgsCoordinateFormatter::formatX( value, format, flags );
|
||||
|
||||
case Latitude:
|
||||
return QgsCoordinateFormatter::formatY( value, format, flags );
|
||||
}
|
||||
|
||||
return QString(); // no warnings
|
||||
}
|
||||
|
||||
int QgsLayoutItemMapGrid::xGridLines( QList< QPair< double, QLineF > > &lines ) const
|
||||
|
@ -58,6 +58,12 @@ QString QgsCoordinateFormatter::formatY( double y, QgsCoordinateFormatter::Forma
|
||||
return QString(); //avoid warnings
|
||||
}
|
||||
|
||||
QString QgsCoordinateFormatter::format( QgsPointXY point, QgsCoordinateFormatter::Format format, int precision, FormatFlags flags )
|
||||
{
|
||||
return QStringLiteral( "%1,%2" ).arg( formatX( point.x(), format, precision, flags ),
|
||||
formatY( point.x(), format, precision, flags ) );
|
||||
}
|
||||
|
||||
QString QgsCoordinateFormatter::asPair( double x, double y, int precision )
|
||||
{
|
||||
QString s = formatAsPair( x, precision );
|
||||
|
@ -19,6 +19,8 @@
|
||||
#define QGSCOORDINATEFORMATTER_H
|
||||
|
||||
#include <QString>
|
||||
#include "qgis.h"
|
||||
#include "qgspointxy.h"
|
||||
|
||||
/**
|
||||
* \ingroup core
|
||||
@ -86,6 +88,17 @@ class CORE_EXPORT QgsCoordinateFormatter
|
||||
*/
|
||||
static QString formatY( double y, Format format, int precision = 12, FormatFlags flags = FlagDegreesUseStringSuffix );
|
||||
|
||||
/**
|
||||
* Formats a \a point according to the specified parameters.
|
||||
*
|
||||
* The \a format argument indicates the desired display format for the coordinate.
|
||||
*
|
||||
* The \a precision argument gives the number of decimal places to include for coordinates.
|
||||
*
|
||||
* Optional \a flags can be specified to control the output format.
|
||||
*/
|
||||
static QString format( QgsPointXY point, Format format, int precision = 12, FormatFlags flags = FlagDegreesUseStringSuffix );
|
||||
|
||||
/**
|
||||
* Formats coordinates as an "\a x,\a y" pair, with optional decimal \a precision (number
|
||||
* of decimal places to include).
|
||||
@ -106,4 +119,6 @@ class CORE_EXPORT QgsCoordinateFormatter
|
||||
static QString formatYAsDegrees( double val, int precision, FormatFlags flags );
|
||||
};
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS( QgsCoordinateFormatter::FormatFlags )
|
||||
|
||||
#endif // QGSCOORDINATEFORMATTER_H
|
||||
|
@ -21,7 +21,7 @@
|
||||
#include "qgsproject.h"
|
||||
#include "qgis.h"
|
||||
#include "qgsexception.h"
|
||||
|
||||
#include "qgscoordinateformatter.h"
|
||||
///@cond NOT_STABLE_API
|
||||
|
||||
int QgsCoordinateUtils::calculateCoordinatePrecision( double mapUnitsPerPixel, const QgsCoordinateReferenceSystem &mapCrs )
|
||||
@ -85,16 +85,16 @@ QString QgsCoordinateUtils::formatCoordinateForProject( const QgsPointXY &point,
|
||||
}
|
||||
|
||||
if ( format == QLatin1String( "DM" ) )
|
||||
return geo.toDegreesMinutes( precision, true, true );
|
||||
return QgsCoordinateFormatter::format( geo, QgsCoordinateFormatter::FormatDegreesMinutes, precision, QgsCoordinateFormatter::FlagDegreesPadMinutesSeconds | QgsCoordinateFormatter::FlagDegreesUseStringSuffix );
|
||||
else if ( format == QLatin1String( "DMS" ) )
|
||||
return geo.toDegreesMinutesSeconds( precision, true, true );
|
||||
return QgsCoordinateFormatter::format( geo, QgsCoordinateFormatter::FormatDegreesMinutesSeconds, precision, QgsCoordinateFormatter::FlagDegreesPadMinutesSeconds | QgsCoordinateFormatter::FlagDegreesUseStringSuffix );
|
||||
else
|
||||
return geo.toString( precision );
|
||||
return QgsCoordinateFormatter::asPair( geo.x(), geo.y(), precision );
|
||||
}
|
||||
else
|
||||
{
|
||||
// coordinates in map units
|
||||
return point.toString( precision );
|
||||
return QgsCoordinateFormatter::asPair( point.x(), point.y(), precision );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,15 +42,6 @@ QPointF QgsPointXY::toQPointF() const
|
||||
return QPointF( mX, mY );
|
||||
}
|
||||
|
||||
QString QgsPointXY::toString() const
|
||||
{
|
||||
QString rep;
|
||||
QTextStream ot( &rep );
|
||||
ot.setRealNumberPrecision( 12 );
|
||||
ot << mX << ", " << mY;
|
||||
return rep;
|
||||
}
|
||||
|
||||
QString QgsPointXY::toString( int precision ) const
|
||||
{
|
||||
QString x = std::isfinite( mX ) ? QString::number( mX, 'f', precision ) : QObject::tr( "infinite" );
|
||||
@ -58,204 +49,6 @@ QString QgsPointXY::toString( int precision ) const
|
||||
return QStringLiteral( "%1,%2" ).arg( x, y );
|
||||
}
|
||||
|
||||
QString QgsPointXY::toDegreesMinutesSeconds( int precision, const bool useSuffix, const bool padded ) const
|
||||
{
|
||||
//first, limit longitude to -360 to 360 degree range
|
||||
double myWrappedX = std::fmod( mX, 360.0 );
|
||||
//next, wrap around longitudes > 180 or < -180 degrees, so that, e.g., "190E" -> "170W"
|
||||
if ( myWrappedX > 180.0 )
|
||||
{
|
||||
myWrappedX = myWrappedX - 360.0;
|
||||
}
|
||||
else if ( myWrappedX < -180.0 )
|
||||
{
|
||||
myWrappedX = myWrappedX + 360.0;
|
||||
}
|
||||
|
||||
//first, limit latitude to -180 to 180 degree range
|
||||
double myWrappedY = std::fmod( mY, 180.0 );
|
||||
//next, wrap around latitudes > 90 or < -90 degrees, so that, e.g., "110S" -> "70N"
|
||||
if ( myWrappedY > 90.0 )
|
||||
{
|
||||
myWrappedY = myWrappedY - 180.0;
|
||||
}
|
||||
else if ( myWrappedY < -90.0 )
|
||||
{
|
||||
myWrappedY = myWrappedY + 180.0;
|
||||
}
|
||||
|
||||
int myDegreesX = int( std::fabs( myWrappedX ) );
|
||||
double myFloatMinutesX = double( ( std::fabs( myWrappedX ) - myDegreesX ) * 60 );
|
||||
int myIntMinutesX = int( myFloatMinutesX );
|
||||
double mySecondsX = double( myFloatMinutesX - myIntMinutesX ) * 60;
|
||||
|
||||
int myDegreesY = int( std::fabs( myWrappedY ) );
|
||||
double myFloatMinutesY = double( ( std::fabs( myWrappedY ) - myDegreesY ) * 60 );
|
||||
int myIntMinutesY = int( myFloatMinutesY );
|
||||
double mySecondsY = double( myFloatMinutesY - myIntMinutesY ) * 60;
|
||||
|
||||
//make sure rounding to specified precision doesn't create seconds >= 60
|
||||
if ( std::round( mySecondsX * std::pow( 10.0, precision ) ) >= 60 * std::pow( 10.0, precision ) )
|
||||
{
|
||||
mySecondsX = std::max( mySecondsX - 60, 0.0 );
|
||||
myIntMinutesX++;
|
||||
if ( myIntMinutesX >= 60 )
|
||||
{
|
||||
myIntMinutesX -= 60;
|
||||
myDegreesX++;
|
||||
}
|
||||
}
|
||||
if ( std::round( mySecondsY * std::pow( 10.0, precision ) ) >= 60 * std::pow( 10.0, precision ) )
|
||||
{
|
||||
mySecondsY = std::max( mySecondsY - 60, 0.0 );
|
||||
myIntMinutesY++;
|
||||
if ( myIntMinutesY >= 60 )
|
||||
{
|
||||
myIntMinutesY -= 60;
|
||||
myDegreesY++;
|
||||
}
|
||||
}
|
||||
|
||||
QString myXHemisphere;
|
||||
QString myYHemisphere;
|
||||
QString myXSign;
|
||||
QString myYSign;
|
||||
if ( useSuffix )
|
||||
{
|
||||
myXHemisphere = myWrappedX < 0 ? QObject::tr( "W" ) : QObject::tr( "E" );
|
||||
myYHemisphere = myWrappedY < 0 ? QObject::tr( "S" ) : QObject::tr( "N" );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( myWrappedX < 0 )
|
||||
{
|
||||
myXSign = QObject::tr( "-" );
|
||||
}
|
||||
if ( myWrappedY < 0 )
|
||||
{
|
||||
myYSign = QObject::tr( "-" );
|
||||
}
|
||||
}
|
||||
//check if coordinate is all zeros for the specified precision, and if so,
|
||||
//remove the sign and hemisphere strings
|
||||
if ( myDegreesX == 0 && myIntMinutesX == 0 && std::round( mySecondsX * std::pow( 10.0, precision ) ) == 0 )
|
||||
{
|
||||
myXSign = QString();
|
||||
myXHemisphere = QString();
|
||||
}
|
||||
if ( myDegreesY == 0 && myIntMinutesY == 0 && std::round( mySecondsY * std::pow( 10.0, precision ) ) == 0 )
|
||||
{
|
||||
myYSign = QString();
|
||||
myYHemisphere = QString();
|
||||
}
|
||||
//also remove directional prefix from 180 degree longitudes
|
||||
if ( myDegreesX == 180 && myIntMinutesX == 0 && std::round( mySecondsX * std::pow( 10.0, precision ) ) == 0 )
|
||||
{
|
||||
myXHemisphere = QString();
|
||||
}
|
||||
//pad minutes with leading digits if required
|
||||
QString myMinutesX = padded ? QStringLiteral( "%1" ).arg( myIntMinutesX, 2, 10, QChar( '0' ) ) : QString::number( myIntMinutesX );
|
||||
QString myMinutesY = padded ? QStringLiteral( "%1" ).arg( myIntMinutesY, 2, 10, QChar( '0' ) ) : QString::number( myIntMinutesY );
|
||||
//pad seconds with leading digits if required
|
||||
int digits = 2 + ( precision == 0 ? 0 : 1 + precision ); //1 for decimal place if required
|
||||
QString myStrSecondsX = padded ? QStringLiteral( "%1" ).arg( mySecondsX, digits, 'f', precision, QChar( '0' ) ) : QString::number( mySecondsX, 'f', precision );
|
||||
QString myStrSecondsY = padded ? QStringLiteral( "%1" ).arg( mySecondsY, digits, 'f', precision, QChar( '0' ) ) : QString::number( mySecondsY, 'f', precision );
|
||||
|
||||
QString rep = myXSign + QString::number( myDegreesX ) + QChar( 176 ) +
|
||||
myMinutesX + QChar( 0x2032 ) +
|
||||
myStrSecondsX + QChar( 0x2033 ) +
|
||||
myXHemisphere + ',' +
|
||||
myYSign + QString::number( myDegreesY ) + QChar( 176 ) +
|
||||
myMinutesY + QChar( 0x2032 ) +
|
||||
myStrSecondsY + QChar( 0x2033 ) +
|
||||
myYHemisphere;
|
||||
return rep;
|
||||
}
|
||||
|
||||
QString QgsPointXY::toDegreesMinutes( int precision, const bool useSuffix, const bool padded ) const
|
||||
{
|
||||
//first, limit longitude to -360 to 360 degree range
|
||||
double myWrappedX = std::fmod( mX, 360.0 );
|
||||
//next, wrap around longitudes > 180 or < -180 degrees, so that, e.g., "190E" -> "170W"
|
||||
if ( myWrappedX > 180.0 )
|
||||
{
|
||||
myWrappedX = myWrappedX - 360.0;
|
||||
}
|
||||
else if ( myWrappedX < -180.0 )
|
||||
{
|
||||
myWrappedX = myWrappedX + 360.0;
|
||||
}
|
||||
|
||||
int myDegreesX = int( std::fabs( myWrappedX ) );
|
||||
double myFloatMinutesX = double( ( std::fabs( myWrappedX ) - myDegreesX ) * 60 );
|
||||
|
||||
int myDegreesY = int( std::fabs( mY ) );
|
||||
double myFloatMinutesY = double( ( std::fabs( mY ) - myDegreesY ) * 60 );
|
||||
|
||||
//make sure rounding to specified precision doesn't create minutes >= 60
|
||||
if ( std::round( myFloatMinutesX * std::pow( 10.0, precision ) ) >= 60 * std::pow( 10.0, precision ) )
|
||||
{
|
||||
myFloatMinutesX = std::max( myFloatMinutesX - 60, 0.0 );
|
||||
myDegreesX++;
|
||||
}
|
||||
if ( std::round( myFloatMinutesY * std::pow( 10.0, precision ) ) >= 60 * std::pow( 10.0, precision ) )
|
||||
{
|
||||
myFloatMinutesY = std::max( myFloatMinutesY - 60, 0.0 );
|
||||
myDegreesY++;
|
||||
}
|
||||
|
||||
QString myXHemisphere;
|
||||
QString myYHemisphere;
|
||||
QString myXSign;
|
||||
QString myYSign;
|
||||
if ( useSuffix )
|
||||
{
|
||||
myXHemisphere = myWrappedX < 0 ? QObject::tr( "W" ) : QObject::tr( "E" );
|
||||
myYHemisphere = mY < 0 ? QObject::tr( "S" ) : QObject::tr( "N" );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( myWrappedX < 0 )
|
||||
{
|
||||
myXSign = QObject::tr( "-" );
|
||||
}
|
||||
if ( mY < 0 )
|
||||
{
|
||||
myYSign = QObject::tr( "-" );
|
||||
}
|
||||
}
|
||||
//check if coordinate is all zeros for the specified precision, and if so,
|
||||
//remove the sign and hemisphere strings
|
||||
if ( myDegreesX == 0 && std::round( myFloatMinutesX * std::pow( 10.0, precision ) ) == 0 )
|
||||
{
|
||||
myXSign = QString();
|
||||
myXHemisphere = QString();
|
||||
}
|
||||
if ( myDegreesY == 0 && std::round( myFloatMinutesY * std::pow( 10.0, precision ) ) == 0 )
|
||||
{
|
||||
myYSign = QString();
|
||||
myYHemisphere = QString();
|
||||
}
|
||||
//also remove directional prefix from 180 degree longitudes
|
||||
if ( myDegreesX == 180 && std::round( myFloatMinutesX * std::pow( 10.0, precision ) ) == 0 )
|
||||
{
|
||||
myXHemisphere = QString();
|
||||
}
|
||||
|
||||
//pad minutes with leading digits if required
|
||||
int digits = 2 + ( precision == 0 ? 0 : 1 + precision ); //1 for decimal place if required
|
||||
QString myStrMinutesX = padded ? QStringLiteral( "%1" ).arg( myFloatMinutesX, digits, 'f', precision, QChar( '0' ) ) : QString::number( myFloatMinutesX, 'f', precision );
|
||||
QString myStrMinutesY = padded ? QStringLiteral( "%1" ).arg( myFloatMinutesY, digits, 'f', precision, QChar( '0' ) ) : QString::number( myFloatMinutesY, 'f', precision );
|
||||
|
||||
QString rep = myXSign + QString::number( myDegreesX ) + QChar( 176 ) +
|
||||
myStrMinutesX + QChar( 0x2032 ) +
|
||||
myXHemisphere + ',' +
|
||||
myYSign + QString::number( myDegreesY ) + QChar( 176 ) +
|
||||
myStrMinutesY + QChar( 0x2032 ) +
|
||||
myYHemisphere;
|
||||
return rep;
|
||||
}
|
||||
|
||||
QString QgsPointXY::wellKnownText() const
|
||||
{
|
||||
return QStringLiteral( "POINT(%1 %2)" ).arg( qgsDoubleToString( mX ), qgsDoubleToString( mY ) );
|
||||
|
@ -147,36 +147,10 @@ class CORE_EXPORT QgsPointXY
|
||||
*/
|
||||
QPointF toQPointF() const;
|
||||
|
||||
//! String representation of the point (x,y)
|
||||
QString toString() const;
|
||||
|
||||
//! As above but with precision for string representation of a point
|
||||
QString toString( int precision ) 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.
|
||||
* \param precision number of decimal points to use for seconds
|
||||
* \param useSuffix set to true to include a direction suffix (e.g., 'N'),
|
||||
* set to false to use a "-" prefix for west and south coordinates
|
||||
* \param padded set to true to force minutes and seconds to use two decimals,
|
||||
* e.g., '05' instead of '5'.
|
||||
* Returns a string representation of the point (x, y) with a preset \a precision.
|
||||
*/
|
||||
QString toDegreesMinutesSeconds( int precision, const bool useSuffix = true, const bool padded = false ) const;
|
||||
|
||||
/**
|
||||
* Return a string representation as degrees minutes.
|
||||
* Its up to the calling function to ensure that this point can
|
||||
* be meaningfully represented in this form.
|
||||
* \param precision number of decimal points to use for minutes
|
||||
* \param useSuffix set to true to include a direction suffix (e.g., 'N'),
|
||||
* set to false to use a "-" prefix for west and south coordinates
|
||||
* \param padded set to true to force minutes to use two decimals,
|
||||
* e.g., '05' instead of '5'.
|
||||
*/
|
||||
QString toDegreesMinutes( int precision, const bool useSuffix = true, const bool padded = false ) const;
|
||||
|
||||
QString toString( int precision = 12 ) const;
|
||||
|
||||
/**
|
||||
* Return the well known text representation for the point.
|
||||
|
@ -41,12 +41,6 @@ class TestQgsPointXY: public QObject
|
||||
void toQPointF();
|
||||
void operators();
|
||||
void toString();
|
||||
void toDegreesMinutesSeconds();
|
||||
void toDegreesMinutesSecondsNoSuffix();
|
||||
void toDegreesMinutesSecondsPadded();
|
||||
void toDegreesMinutes();
|
||||
void toDegreesMinutesNoSuffix();
|
||||
void toDegreesMinutesPadded();
|
||||
void sqrDist();
|
||||
void distance();
|
||||
void compare();
|
||||
@ -194,441 +188,6 @@ void TestQgsPointXY::toString()
|
||||
QCOMPARE( mPoint1.toString( 2 ), QString( "20.00,-20.00" ) );
|
||||
}
|
||||
|
||||
void TestQgsPointXY::toDegreesMinutesSeconds()
|
||||
{
|
||||
mReport += QLatin1String( "<p>Testing toDegreesMinutesSeconds()</p>" );
|
||||
mReport += "<p>" + mPoint1.toDegreesMinutesSeconds( 2 ) + "</p>";
|
||||
mReport += "<p>" + mPoint2.toDegreesMinutesSeconds( 2 ) + "</p>";
|
||||
mReport += "<p>" + mPoint3.toDegreesMinutesSeconds( 2 ) + "</p>";
|
||||
mReport += "<p>" + mPoint4.toDegreesMinutesSeconds( 2 ) + "</p>";
|
||||
|
||||
qDebug() << mPoint4.toDegreesMinutesSeconds( 2 );
|
||||
QString myControlString = QStringLiteral( "80" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) +
|
||||
QChar( 0x2033 ) +
|
||||
QStringLiteral( "E,20" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ) +
|
||||
QStringLiteral( "N" );
|
||||
qDebug() << myControlString;
|
||||
QCOMPARE( mPoint4.toDegreesMinutesSeconds( 2 ), myControlString );
|
||||
|
||||
//check if longitudes > 180 or <-180 wrap around
|
||||
myControlString = QStringLiteral( "10" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ) + QStringLiteral( "E" ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 );
|
||||
QCOMPARE( QgsPointXY( 370, 0 ).toDegreesMinutesSeconds( 2 ), myControlString );
|
||||
myControlString = QStringLiteral( "10" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ) + QStringLiteral( "W" ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 );
|
||||
QCOMPARE( QgsPointXY( -370, 0 ).toDegreesMinutesSeconds( 2 ), myControlString );
|
||||
myControlString = QStringLiteral( "179" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ) + QStringLiteral( "W" ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 );
|
||||
QCOMPARE( QgsPointXY( 181, 0 ).toDegreesMinutesSeconds( 2 ), myControlString );
|
||||
myControlString = QStringLiteral( "179" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ) + QStringLiteral( "E" ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 );
|
||||
QCOMPARE( QgsPointXY( -181, 0 ).toDegreesMinutesSeconds( 2 ), myControlString );
|
||||
myControlString = QStringLiteral( "1" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ) + QStringLiteral( "W" ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 );
|
||||
QCOMPARE( QgsPointXY( 359, 0 ).toDegreesMinutesSeconds( 2 ), myControlString );
|
||||
myControlString = QStringLiteral( "1" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ) + QStringLiteral( "E" ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 );
|
||||
QCOMPARE( QgsPointXY( -359, 0 ).toDegreesMinutesSeconds( 2 ), myControlString );
|
||||
|
||||
//check if latitudes > 90 or <-90 wrap around
|
||||
myControlString = QStringLiteral( "0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ) +
|
||||
QStringLiteral( ",10" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ) + QStringLiteral( "N" );
|
||||
QCOMPARE( QgsPointXY( 0, 190 ).toDegreesMinutesSeconds( 2 ), myControlString );
|
||||
myControlString = QStringLiteral( "0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ) +
|
||||
QStringLiteral( ",10" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ) + QStringLiteral( "S" );
|
||||
QCOMPARE( QgsPointXY( 0, -190 ).toDegreesMinutesSeconds( 2 ), myControlString );
|
||||
myControlString = QStringLiteral( "0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ) +
|
||||
QStringLiteral( ",89" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ) + QStringLiteral( "S" );
|
||||
QCOMPARE( QgsPointXY( 0, 91 ).toDegreesMinutesSeconds( 2 ), myControlString );
|
||||
myControlString = QStringLiteral( "0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ) +
|
||||
QStringLiteral( ",89" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ) + QStringLiteral( "N" );
|
||||
QCOMPARE( QgsPointXY( 0, -91 ).toDegreesMinutesSeconds( 2 ), myControlString );
|
||||
myControlString = QStringLiteral( "0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ) +
|
||||
QStringLiteral( ",1" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ) + QStringLiteral( "S" );
|
||||
QCOMPARE( QgsPointXY( 0, 179 ).toDegreesMinutesSeconds( 2 ), myControlString );
|
||||
myControlString = QStringLiteral( "0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ) +
|
||||
QStringLiteral( ",1" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ) + QStringLiteral( "N" );
|
||||
QCOMPARE( QgsPointXY( 0, -179 ).toDegreesMinutesSeconds( 2 ), myControlString );
|
||||
|
||||
//should be no directional suffixes for 0 degree coordinates
|
||||
myControlString = QStringLiteral( "0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) +
|
||||
QChar( 0x2033 ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 );
|
||||
QCOMPARE( QgsPointXY( 0, 0 ).toDegreesMinutesSeconds( 2 ), myControlString );
|
||||
//should also be no directional suffix for 0 degree coordinates within specified precision
|
||||
QCOMPARE( QgsPointXY( 0, 0.000001 ).toDegreesMinutesSeconds( 2 ), myControlString );
|
||||
QCOMPARE( QgsPointXY( 0, -0.000001 ).toDegreesMinutesSeconds( 2 ), myControlString );
|
||||
QCOMPARE( QgsPointXY( -0.000001, 0 ).toDegreesMinutesSeconds( 2 ), myControlString );
|
||||
QCOMPARE( QgsPointXY( 0.000001, 0 ).toDegreesMinutesSeconds( 2 ), myControlString );
|
||||
myControlString = QStringLiteral( "0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00000" ) +
|
||||
QChar( 0x2033 ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00360" ) + QChar( 0x2033 ) + QStringLiteral( "N" );
|
||||
QCOMPARE( QgsPointXY( 0, 0.000001 ).toDegreesMinutesSeconds( 5 ), myControlString );
|
||||
myControlString = QStringLiteral( "0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00000" ) +
|
||||
QChar( 0x2033 ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00360" ) + QChar( 0x2033 ) + QStringLiteral( "S" );
|
||||
QCOMPARE( QgsPointXY( 0, -0.000001 ).toDegreesMinutesSeconds( 5 ), myControlString );
|
||||
myControlString = QStringLiteral( "0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00360" ) + QChar( 0x2033 ) + QStringLiteral( "E" ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00000" ) + QChar( 0x2033 );
|
||||
QCOMPARE( QgsPointXY( 0.000001, 0 ).toDegreesMinutesSeconds( 5 ), myControlString );
|
||||
myControlString = QStringLiteral( "0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00360" ) + QChar( 0x2033 ) + QStringLiteral( "W" ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00000" ) + QChar( 0x2033 );
|
||||
QCOMPARE( QgsPointXY( -0.000001, 0 ).toDegreesMinutesSeconds( 5 ), myControlString );
|
||||
|
||||
//test rounding does not create seconds >= 60
|
||||
myControlString = QStringLiteral( "100" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ) + QStringLiteral( "E" ) +
|
||||
QStringLiteral( ",90" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 ) + QStringLiteral( "N" );
|
||||
QCOMPARE( QgsPointXY( 99.999999, 89.999999 ).toDegreesMinutesSeconds( 2 ), myControlString );
|
||||
|
||||
//should be no directional suffixes for 180 degree longitudes
|
||||
myControlString = QStringLiteral( "180" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) +
|
||||
QChar( 0x2033 ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 );
|
||||
QCOMPARE( QgsPointXY( 180, 0 ).toDegreesMinutesSeconds( 2 ), myControlString );
|
||||
//should also be no directional suffix for 180 degree longitudes within specified precision
|
||||
QCOMPARE( QgsPointXY( 180.000001, 0 ).toDegreesMinutesSeconds( 2 ), myControlString );
|
||||
QCOMPARE( QgsPointXY( 179.999999, 0 ).toDegreesMinutesSeconds( 2 ), myControlString );
|
||||
myControlString = QStringLiteral( "179" ) + QChar( 176 ) +
|
||||
QStringLiteral( "59" ) + QChar( 0x2032 ) + QStringLiteral( "59.99640" ) + QChar( 0x2033 ) + QStringLiteral( "W" ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00000" ) + QChar( 0x2033 );
|
||||
QCOMPARE( QgsPointXY( 180.000001, 0 ).toDegreesMinutesSeconds( 5 ), myControlString );
|
||||
myControlString = QStringLiteral( "179" ) + QChar( 176 ) +
|
||||
QStringLiteral( "59" ) + QChar( 0x2032 ) + QStringLiteral( "59.99640" ) + QChar( 0x2033 ) + QStringLiteral( "E" ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00000" ) + QChar( 0x2033 );
|
||||
QCOMPARE( QgsPointXY( 179.999999, 0 ).toDegreesMinutesSeconds( 5 ), myControlString );
|
||||
}
|
||||
|
||||
void TestQgsPointXY::toDegreesMinutesSecondsNoSuffix()
|
||||
{
|
||||
QString myControlString = QStringLiteral( "80" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) +
|
||||
QChar( 0x2033 ) +
|
||||
QStringLiteral( ",20" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 );
|
||||
QCOMPARE( mPoint4.toDegreesMinutesSeconds( 2, false ), myControlString );
|
||||
|
||||
//test 0 lat/long
|
||||
myControlString = QStringLiteral( "0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) +
|
||||
QChar( 0x2033 ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00" ) + QChar( 0x2033 );
|
||||
QVERIFY( QgsPointXY( 0, 0 ).toDegreesMinutesSeconds( 2, false ) == myControlString );
|
||||
//test near zero lat/long
|
||||
QCOMPARE( QgsPointXY( 0, 0.000001 ).toDegreesMinutesSeconds( 2, false ), myControlString );
|
||||
QCOMPARE( QgsPointXY( 0.000001, 0 ).toDegreesMinutesSeconds( 2, false ), myControlString );
|
||||
//should be no "-" prefix for near-zero lat/long when rounding to 2 decimal places
|
||||
QCOMPARE( QgsPointXY( 0, -0.000001 ).toDegreesMinutesSeconds( 2, false ), myControlString );
|
||||
QCOMPARE( QgsPointXY( -0.000001, 0 ).toDegreesMinutesSeconds( 2, false ), myControlString );
|
||||
|
||||
myControlString = QStringLiteral( "0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00000" ) +
|
||||
QChar( 0x2033 ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00360" ) + QChar( 0x2033 );
|
||||
QCOMPARE( QgsPointXY( 0, 0.000001 ).toDegreesMinutesSeconds( 5, false ), myControlString );
|
||||
myControlString = QStringLiteral( "0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00000" ) +
|
||||
QChar( 0x2033 ) +
|
||||
QStringLiteral( ",-0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00360" ) + QChar( 0x2033 );
|
||||
QCOMPARE( QgsPointXY( 0, -0.000001 ).toDegreesMinutesSeconds( 5, false ), myControlString );
|
||||
myControlString = QStringLiteral( "0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00360" ) +
|
||||
QChar( 0x2033 ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00000" ) + QChar( 0x2033 );
|
||||
QCOMPARE( QgsPointXY( 0.000001, 0 ).toDegreesMinutesSeconds( 5, false ), myControlString );
|
||||
myControlString = QStringLiteral( "-0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00360" ) +
|
||||
QChar( 0x2033 ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0" ) + QChar( 0x2032 ) + QStringLiteral( "0.00000" ) + QChar( 0x2033 );
|
||||
QCOMPARE( QgsPointXY( -0.000001, 0 ).toDegreesMinutesSeconds( 5, false ), myControlString );
|
||||
}
|
||||
|
||||
void TestQgsPointXY::toDegreesMinutesSecondsPadded()
|
||||
{
|
||||
QString myControlString = QStringLiteral( "80" ) + QChar( 176 ) +
|
||||
QStringLiteral( "00" ) + QChar( 0x2032 ) + QStringLiteral( "00.00" ) +
|
||||
QChar( 0x2033 ) +
|
||||
QStringLiteral( "E,20" ) + QChar( 176 ) +
|
||||
QStringLiteral( "00" ) + QChar( 0x2032 ) + QStringLiteral( "00.00" ) + QChar( 0x2033 ) +
|
||||
QStringLiteral( "N" );
|
||||
qDebug() << myControlString;
|
||||
QCOMPARE( mPoint4.toDegreesMinutesSeconds( 2, true, true ), myControlString );
|
||||
|
||||
//should be no directional suffixes for 0 degree coordinates
|
||||
myControlString = QStringLiteral( "0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "00" ) + QChar( 0x2032 ) + QStringLiteral( "00.00" ) +
|
||||
QChar( 0x2033 ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "00" ) + QChar( 0x2032 ) + QStringLiteral( "00.00" ) + QChar( 0x2033 );
|
||||
QVERIFY( QgsPointXY( 0, 0 ).toDegreesMinutesSeconds( 2, true, true ) == myControlString );
|
||||
//should also be no directional suffix for 0 degree coordinates within specified precision
|
||||
QCOMPARE( QgsPointXY( 0, 0.000001 ).toDegreesMinutesSeconds( 2, true, true ), myControlString );
|
||||
QCOMPARE( QgsPointXY( 0, -0.000001 ).toDegreesMinutesSeconds( 2, true, true ), myControlString );
|
||||
QCOMPARE( QgsPointXY( -0.000001, 0 ).toDegreesMinutesSeconds( 2, true, true ), myControlString );
|
||||
QCOMPARE( QgsPointXY( 0.000001, 0 ).toDegreesMinutesSeconds( 2, true, true ), myControlString );
|
||||
myControlString = QStringLiteral( "0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "00" ) + QChar( 0x2032 ) + QStringLiteral( "00.00000" ) +
|
||||
QChar( 0x2033 ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "00" ) + QChar( 0x2032 ) + QStringLiteral( "00.00360" ) + QChar( 0x2033 ) + QStringLiteral( "N" );
|
||||
QCOMPARE( QgsPointXY( 0, 0.000001 ).toDegreesMinutesSeconds( 5, true, true ), myControlString );
|
||||
myControlString = QStringLiteral( "0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "00" ) + QChar( 0x2032 ) + QStringLiteral( "00.00000" ) +
|
||||
QChar( 0x2033 ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "00" ) + QChar( 0x2032 ) + QStringLiteral( "00.00360" ) + QChar( 0x2033 ) + QStringLiteral( "S" );
|
||||
QCOMPARE( QgsPointXY( 0, -0.000001 ).toDegreesMinutesSeconds( 5, true, true ), myControlString );
|
||||
myControlString = QStringLiteral( "0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "00" ) + QChar( 0x2032 ) + QStringLiteral( "00.00360" ) + QChar( 0x2033 ) + QStringLiteral( "E" ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "00" ) + QChar( 0x2032 ) + QStringLiteral( "00.00000" ) + QChar( 0x2033 );
|
||||
QCOMPARE( QgsPointXY( 0.000001, 0 ).toDegreesMinutesSeconds( 5, true, true ), myControlString );
|
||||
myControlString = QStringLiteral( "0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "00" ) + QChar( 0x2032 ) + QStringLiteral( "00.00360" ) + QChar( 0x2033 ) + QStringLiteral( "W" ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "00" ) + QChar( 0x2032 ) + QStringLiteral( "00.00000" ) + QChar( 0x2033 );
|
||||
QCOMPARE( QgsPointXY( -0.000001, 0 ).toDegreesMinutesSeconds( 5, true, true ), myControlString );
|
||||
}
|
||||
|
||||
void TestQgsPointXY::toDegreesMinutes()
|
||||
{
|
||||
mReport += QLatin1String( "<p>Testing toDegreesMinutes()</p>" );
|
||||
mReport += "<p>" + mPoint1.toDegreesMinutes( 2 ) + "</p>";
|
||||
mReport += "<p>" + mPoint2.toDegreesMinutes( 2 ) + "</p>";
|
||||
mReport += "<p>" + mPoint3.toDegreesMinutes( 2 ) + "</p>";
|
||||
mReport += "<p>" + mPoint4.toDegreesMinutes( 2 ) + "</p>";
|
||||
|
||||
qDebug() << mPoint4.toDegreesMinutes( 2 );
|
||||
QString myControlString = QStringLiteral( "80" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0.00" ) + QChar( 0x2032 ) +
|
||||
QStringLiteral( "E,20" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0.00" ) + QChar( 0x2032 ) + QStringLiteral( "N" );
|
||||
qDebug() << myControlString;
|
||||
QCOMPARE( mPoint4.toDegreesMinutes( 2 ), myControlString );
|
||||
|
||||
//check if longitudes > 180 or <-180 wrap around
|
||||
myControlString = QStringLiteral( "10" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0.00" ) + QChar( 0x2032 ) + QStringLiteral( "E" ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0.00" ) + QChar( 0x2032 );
|
||||
QCOMPARE( QgsPointXY( 370, 0 ).toDegreesMinutes( 2 ), myControlString );
|
||||
myControlString = QStringLiteral( "10" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0.00" ) + QChar( 0x2032 ) + QStringLiteral( "W" ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0.00" ) + QChar( 0x2032 );
|
||||
QCOMPARE( QgsPointXY( -370, 0 ).toDegreesMinutes( 2 ), myControlString );
|
||||
myControlString = QStringLiteral( "179" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0.00" ) + QChar( 0x2032 ) + QStringLiteral( "W" ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0.00" ) + QChar( 0x2032 );
|
||||
QCOMPARE( QgsPointXY( 181, 0 ).toDegreesMinutes( 2 ), myControlString );
|
||||
myControlString = QStringLiteral( "179" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0.00" ) + QChar( 0x2032 ) + QStringLiteral( "E" ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0.00" ) + QChar( 0x2032 );
|
||||
QCOMPARE( QgsPointXY( -181, 0 ).toDegreesMinutes( 2 ), myControlString );
|
||||
myControlString = QStringLiteral( "1" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0.00" ) + QChar( 0x2032 ) + QStringLiteral( "W" ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0.00" ) + QChar( 0x2032 );
|
||||
QCOMPARE( QgsPointXY( 359, 0 ).toDegreesMinutes( 2 ), myControlString );
|
||||
myControlString = QStringLiteral( "1" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0.00" ) + QChar( 0x2032 ) + QStringLiteral( "E" ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0.00" ) + QChar( 0x2032 );
|
||||
QCOMPARE( QgsPointXY( -359, 0 ).toDegreesMinutes( 2 ), myControlString );
|
||||
|
||||
//should be no directional suffixes for 0 degree coordinates
|
||||
myControlString = QStringLiteral( "0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0.00" ) + QChar( 0x2032 ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0.00" ) + QChar( 0x2032 );
|
||||
QVERIFY( QgsPointXY( 0, 0 ).toDegreesMinutes( 2 ) == myControlString );
|
||||
//should also be no directional suffix for 0 degree coordinates within specified precision
|
||||
QCOMPARE( QgsPointXY( 0, 0.000001 ).toDegreesMinutes( 2 ), myControlString );
|
||||
QCOMPARE( QgsPointXY( 0, -0.000001 ).toDegreesMinutes( 2 ), myControlString );
|
||||
QCOMPARE( QgsPointXY( -0.000001, 0 ).toDegreesMinutes( 2 ), myControlString );
|
||||
QCOMPARE( QgsPointXY( 0.000001, 0 ).toDegreesMinutes( 2 ), myControlString );
|
||||
myControlString = QStringLiteral( "0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0.00000" ) + QChar( 0x2032 ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0.00006" ) + QChar( 0x2032 ) + QStringLiteral( "N" );
|
||||
QCOMPARE( QgsPointXY( 0, 0.000001 ).toDegreesMinutes( 5 ), myControlString );
|
||||
myControlString = QStringLiteral( "0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0.00000" ) + QChar( 0x2032 ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0.00006" ) + QChar( 0x2032 ) + QStringLiteral( "S" );
|
||||
QCOMPARE( QgsPointXY( 0, -0.000001 ).toDegreesMinutes( 5 ), myControlString );
|
||||
myControlString = QStringLiteral( "0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0.00006" ) + QChar( 0x2032 ) + QStringLiteral( "E" ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0.00000" ) + QChar( 0x2032 );
|
||||
QCOMPARE( QgsPointXY( 0.000001, 0 ).toDegreesMinutes( 5 ), myControlString );
|
||||
myControlString = QStringLiteral( "0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0.00006" ) + QChar( 0x2032 ) + QStringLiteral( "W" ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0.00000" ) + QChar( 0x2032 );
|
||||
QCOMPARE( QgsPointXY( -0.000001, 0 ).toDegreesMinutes( 5 ), myControlString );
|
||||
|
||||
//test rounding does not create minutes >= 60
|
||||
myControlString = QStringLiteral( "100" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0.00" ) + QChar( 0x2032 ) + QStringLiteral( "E" ) +
|
||||
QStringLiteral( ",100" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0.00" ) + QChar( 0x2032 ) + QStringLiteral( "N" );
|
||||
QCOMPARE( QgsPointXY( 99.999999, 99.999999 ).toDegreesMinutes( 2 ), myControlString );
|
||||
|
||||
//should be no directional suffixes for 180 degree longitudes
|
||||
myControlString = QStringLiteral( "180" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0.00" ) + QChar( 0x2032 ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0.00" ) + QChar( 0x2032 );
|
||||
QCOMPARE( QgsPointXY( 180, 0 ).toDegreesMinutes( 2 ), myControlString );
|
||||
//should also be no directional suffix for 180 degree longitudes within specified precision
|
||||
QCOMPARE( QgsPointXY( 180.000001, 0 ).toDegreesMinutes( 2 ), myControlString );
|
||||
QCOMPARE( QgsPointXY( 179.999999, 0 ).toDegreesMinutes( 2 ), myControlString );
|
||||
myControlString = QStringLiteral( "179" ) + QChar( 176 ) +
|
||||
QStringLiteral( "59.99994" ) + QChar( 0x2032 ) + QStringLiteral( "W" ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0.00000" ) + QChar( 0x2032 );
|
||||
QCOMPARE( QgsPointXY( 180.000001, 0 ).toDegreesMinutes( 5 ), myControlString );
|
||||
myControlString = QStringLiteral( "179" ) + QChar( 176 ) +
|
||||
QStringLiteral( "59.99994" ) + QChar( 0x2032 ) + QStringLiteral( "E" ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0.00000" ) + QChar( 0x2032 );
|
||||
QCOMPARE( QgsPointXY( 179.999999, 0 ).toDegreesMinutes( 5 ), myControlString );
|
||||
}
|
||||
|
||||
void TestQgsPointXY::toDegreesMinutesNoSuffix()
|
||||
{
|
||||
QString myControlString = QStringLiteral( "80" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0.00" ) + QChar( 0x2032 ) +
|
||||
QStringLiteral( ",20" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0.00" ) + QChar( 0x2032 );
|
||||
QCOMPARE( mPoint4.toDegreesMinutes( 2, false ), myControlString );
|
||||
|
||||
//test 0 lat/long
|
||||
myControlString = QStringLiteral( "0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0.00" ) + QChar( 0x2032 ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0.00" ) + QChar( 0x2032 );
|
||||
QVERIFY( QgsPointXY( 0, 0 ).toDegreesMinutes( 2, false ) == myControlString );
|
||||
//test near zero lat/long
|
||||
QCOMPARE( QgsPointXY( 0, 0.000001 ).toDegreesMinutes( 2, false ), myControlString );
|
||||
QCOMPARE( QgsPointXY( 0.000001, 0 ).toDegreesMinutes( 2, false ), myControlString );
|
||||
//should be no "-" prefix for near-zero lat/long when rounding to 2 decimal places
|
||||
QCOMPARE( QgsPointXY( 0, -0.000001 ).toDegreesMinutes( 2, false ), myControlString );
|
||||
QCOMPARE( QgsPointXY( -0.000001, 0 ).toDegreesMinutes( 2, false ), myControlString );
|
||||
|
||||
myControlString = QStringLiteral( "0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0.00000" ) + QChar( 0x2032 ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0.00006" ) + QChar( 0x2032 );
|
||||
QCOMPARE( QgsPointXY( 0, 0.000001 ).toDegreesMinutes( 5, false ), myControlString );
|
||||
myControlString = QStringLiteral( "0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0.00000" ) + QChar( 0x2032 ) +
|
||||
QStringLiteral( ",-0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0.00006" ) + QChar( 0x2032 );
|
||||
QCOMPARE( QgsPointXY( 0, -0.000001 ).toDegreesMinutes( 5, false ), myControlString );
|
||||
myControlString = QStringLiteral( "0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0.00006" ) + QChar( 0x2032 ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0.00000" ) + QChar( 0x2032 );
|
||||
QCOMPARE( QgsPointXY( 0.000001, 0 ).toDegreesMinutes( 5, false ), myControlString );
|
||||
myControlString = QStringLiteral( "-0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0.00006" ) + QChar( 0x2032 ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "0.00000" ) + QChar( 0x2032 );
|
||||
QCOMPARE( QgsPointXY( -0.000001, 0 ).toDegreesMinutes( 5, false ), myControlString );
|
||||
}
|
||||
|
||||
void TestQgsPointXY::toDegreesMinutesPadded()
|
||||
{
|
||||
QString myControlString = QStringLiteral( "80" ) + QChar( 176 ) +
|
||||
QStringLiteral( "00.00" ) + QChar( 0x2032 ) +
|
||||
QStringLiteral( "E,20" ) + QChar( 176 ) +
|
||||
QStringLiteral( "00.00" ) + QChar( 0x2032 ) + QStringLiteral( "N" );
|
||||
qDebug() << myControlString;
|
||||
QCOMPARE( mPoint4.toDegreesMinutes( 2, true, true ), myControlString );
|
||||
|
||||
//should be no directional suffixes for 0 degree coordinates
|
||||
myControlString = QStringLiteral( "0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "00.00" ) + QChar( 0x2032 ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "00.00" ) + QChar( 0x2032 );
|
||||
QVERIFY( QgsPointXY( 0, 0 ).toDegreesMinutes( 2, true, true ) == myControlString );
|
||||
//should also be no directional suffix for 0 degree coordinates within specified precision
|
||||
QCOMPARE( QgsPointXY( 0, 0.000001 ).toDegreesMinutes( 2, true, true ), myControlString );
|
||||
QCOMPARE( QgsPointXY( 0, -0.000001 ).toDegreesMinutes( 2, true, true ), myControlString );
|
||||
QCOMPARE( QgsPointXY( -0.000001, 0 ).toDegreesMinutes( 2, true, true ), myControlString );
|
||||
QCOMPARE( QgsPointXY( 0.000001, 0 ).toDegreesMinutes( 2, true, true ), myControlString );
|
||||
myControlString = QStringLiteral( "0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "00.00000" ) + QChar( 0x2032 ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "00.00006" ) + QChar( 0x2032 ) + QStringLiteral( "N" );
|
||||
QCOMPARE( QgsPointXY( 0, 0.000001 ).toDegreesMinutes( 5, true, true ), myControlString );
|
||||
myControlString = QStringLiteral( "0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "00.00000" ) + QChar( 0x2032 ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "00.00006" ) + QChar( 0x2032 ) + QStringLiteral( "S" );
|
||||
QCOMPARE( QgsPointXY( 0, -0.000001 ).toDegreesMinutes( 5, true, true ), myControlString );
|
||||
myControlString = QStringLiteral( "0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "00.00006" ) + QChar( 0x2032 ) + QStringLiteral( "E" ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "00.00000" ) + QChar( 0x2032 );
|
||||
QCOMPARE( QgsPointXY( 0.000001, 0 ).toDegreesMinutes( 5, true, true ), myControlString );
|
||||
myControlString = QStringLiteral( "0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "00.00006" ) + QChar( 0x2032 ) + QStringLiteral( "W" ) +
|
||||
QStringLiteral( ",0" ) + QChar( 176 ) +
|
||||
QStringLiteral( "00.00000" ) + QChar( 0x2032 );
|
||||
QCOMPARE( QgsPointXY( -0.000001, 0 ).toDegreesMinutes( 5, true, true ), myControlString );
|
||||
}
|
||||
|
||||
void TestQgsPointXY::sqrDist()
|
||||
{
|
||||
QCOMPARE( QgsPointXY( 1, 2 ).sqrDist( QgsPointXY( 2, 2 ) ), 1.0 );
|
||||
|
@ -22,22 +22,22 @@ class TestQgsCoordinateFormatter(TestCase):
|
||||
def testFormatXPair(self):
|
||||
"""Test formatting x as pair"""
|
||||
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(20, QgsCoordinateFormatter.Pair, 0), '20')
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-20, QgsCoordinateFormatter.Pair, 0), '-20')
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(20.11111111111111111, QgsCoordinateFormatter.Pair, 3), '20.111')
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(20.11161111111111111, QgsCoordinateFormatter.Pair, 3), '20.112')
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(20, QgsCoordinateFormatter.Pair, 3), '20.000')
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(float('inf'), QgsCoordinateFormatter.Pair, 3), 'infinite')
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(20, QgsCoordinateFormatter.FormatPair, 0), '20')
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-20, QgsCoordinateFormatter.FormatPair, 0), '-20')
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(20.11111111111111111, QgsCoordinateFormatter.FormatPair, 3), '20.111')
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(20.11161111111111111, QgsCoordinateFormatter.FormatPair, 3), '20.112')
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(20, QgsCoordinateFormatter.FormatPair, 3), '20.000')
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(float('inf'), QgsCoordinateFormatter.FormatPair, 3), 'infinite')
|
||||
|
||||
def testFormatYPair(self):
|
||||
"""Test formatting y as pair"""
|
||||
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(20, QgsCoordinateFormatter.Pair, 0), '20')
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-20, QgsCoordinateFormatter.Pair, 0), '-20')
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(20.11111111111111111, QgsCoordinateFormatter.Pair, 3), '20.111')
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(20.11161111111111111, QgsCoordinateFormatter.Pair, 3), '20.112')
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(20, QgsCoordinateFormatter.Pair, 3), '20.000')
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(float('inf'), QgsCoordinateFormatter.Pair, 3), 'infinite')
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(20, QgsCoordinateFormatter.FormatPair, 0), '20')
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-20, QgsCoordinateFormatter.FormatPair, 0), '-20')
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(20.11111111111111111, QgsCoordinateFormatter.FormatPair, 3), '20.111')
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(20.11161111111111111, QgsCoordinateFormatter.FormatPair, 3), '20.112')
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(20, QgsCoordinateFormatter.FormatPair, 3), '20.000')
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(float('inf'), QgsCoordinateFormatter.FormatPair, 3), 'infinite')
|
||||
|
||||
def testAsPair(self):
|
||||
"""Test formatting x/y as pair"""
|
||||
@ -48,305 +48,305 @@ class TestQgsCoordinateFormatter(TestCase):
|
||||
self.assertEqual(QgsCoordinateFormatter.asPair(20, 10, 2), '20.00,10.00')
|
||||
self.assertEqual(QgsCoordinateFormatter.asPair(20, -10, 2), '20.00,-10.00')
|
||||
|
||||
def testFormatXDegreesMinutesSeconds(self):
|
||||
def testFormatXFormatDegreesMinutesSeconds(self):
|
||||
"""Test formatting x as DMS"""
|
||||
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(80, QgsCoordinateFormatter.DegreesMinutesSeconds, 2), u"80°0′0.00″E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(80, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"80°0′0.00″E")
|
||||
|
||||
# check precision
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(80, QgsCoordinateFormatter.DegreesMinutesSeconds, 4), u"80°0′0.0000″E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(80.12345678, QgsCoordinateFormatter.DegreesMinutesSeconds, 4), u"80°7′24.4444″E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(80.12345678, QgsCoordinateFormatter.DegreesMinutesSeconds, 0), u"80°7′24″E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(80, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 4), u"80°0′0.0000″E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(80.12345678, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 4), u"80°7′24.4444″E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(80.12345678, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 0), u"80°7′24″E")
|
||||
|
||||
# check if longitudes > 180 or <-180 wrap around
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(370, QgsCoordinateFormatter.DegreesMinutesSeconds, 2), u"10°0′0.00″E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-370, QgsCoordinateFormatter.DegreesMinutesSeconds, 2), u"10°0′0.00″W")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(181, QgsCoordinateFormatter.DegreesMinutesSeconds, 2), u"179°0′0.00″W")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-181, QgsCoordinateFormatter.DegreesMinutesSeconds, 2), u"179°0′0.00″E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(359, QgsCoordinateFormatter.DegreesMinutesSeconds, 2), u"1°0′0.00″W")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-359, QgsCoordinateFormatter.DegreesMinutesSeconds, 2), u"1°0′0.00″E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(370, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"10°0′0.00″E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-370, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"10°0′0.00″W")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(181, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"179°0′0.00″W")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-181, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"179°0′0.00″E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(359, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"1°0′0.00″W")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-359, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"1°0′0.00″E")
|
||||
|
||||
# should be no directional suffixes for 0 degree coordinates
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0, QgsCoordinateFormatter.DegreesMinutesSeconds, 2), u"0°0′0.00″")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"0°0′0.00″")
|
||||
# should also be no directional suffix for 0 degree coordinates within specified precision
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-0.000001, QgsCoordinateFormatter.DegreesMinutesSeconds, 2), u"0°0′0.00″")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-0.000001, QgsCoordinateFormatter.DegreesMinutesSeconds, 5), u"0°0′0.00360″W")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0.000001, QgsCoordinateFormatter.DegreesMinutesSeconds, 2), u"0°0′0.00″")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0.000001, QgsCoordinateFormatter.DegreesMinutesSeconds, 5), u"0°0′0.00360″E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"0°0′0.00″")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 5), u"0°0′0.00360″W")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"0°0′0.00″")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 5), u"0°0′0.00360″E")
|
||||
|
||||
# should be no directional suffixes for 180 degree longitudes
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(180, QgsCoordinateFormatter.DegreesMinutesSeconds, 2), u"180°0′0.00″")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(179.999999, QgsCoordinateFormatter.DegreesMinutesSeconds, 2), u"180°0′0.00″")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(179.999999, QgsCoordinateFormatter.DegreesMinutesSeconds, 5), u"179°59′59.99640″E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(180.000001, QgsCoordinateFormatter.DegreesMinutesSeconds, 2), u"180°0′0.00″")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(180.000001, QgsCoordinateFormatter.DegreesMinutesSeconds, 5), u"179°59′59.99640″W")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(180, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"180°0′0.00″")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(179.999999, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"180°0′0.00″")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(179.999999, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 5), u"179°59′59.99640″E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(180.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"180°0′0.00″")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(180.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 5), u"179°59′59.99640″W")
|
||||
|
||||
# test rounding does not create seconds >= 60
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(99.999999, QgsCoordinateFormatter.DegreesMinutesSeconds, 2), u"100°0′0.00″E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(89.999999, QgsCoordinateFormatter.DegreesMinutesSeconds, 2), u"90°0′0.00″E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(99.999999, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"100°0′0.00″E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(89.999999, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"90°0′0.00″E")
|
||||
|
||||
# test without direction suffix
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(80, QgsCoordinateFormatter.DegreesMinutesSeconds, 2, QgsCoordinateFormatter.FormatFlags()), u"80°0′0.00″")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(80, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2, QgsCoordinateFormatter.FormatFlags()), u"80°0′0.00″")
|
||||
|
||||
# test 0 longitude
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0, QgsCoordinateFormatter.DegreesMinutesSeconds, 2, QgsCoordinateFormatter.FormatFlags()), u"0°0′0.00″")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2, QgsCoordinateFormatter.FormatFlags()), u"0°0′0.00″")
|
||||
# test near zero longitude
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0.000001, QgsCoordinateFormatter.DegreesMinutesSeconds, 2, QgsCoordinateFormatter.FormatFlags()), u"0°0′0.00″")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2, QgsCoordinateFormatter.FormatFlags()), u"0°0′0.00″")
|
||||
# should be no "-" prefix for near-zero longitude when rounding to 2 decimal places
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-0.000001, QgsCoordinateFormatter.DegreesMinutesSeconds, 2, QgsCoordinateFormatter.FormatFlags()), u"0°0′0.00″")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0.000001, QgsCoordinateFormatter.DegreesMinutesSeconds, 5, QgsCoordinateFormatter.FormatFlags()), u"0°0′0.00360″")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-0.000001, QgsCoordinateFormatter.DegreesMinutesSeconds, 5, QgsCoordinateFormatter.FormatFlags()), u"-0°0′0.00360″")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2, QgsCoordinateFormatter.FormatFlags()), u"0°0′0.00″")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 5, QgsCoordinateFormatter.FormatFlags()), u"0°0′0.00360″")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 5, QgsCoordinateFormatter.FormatFlags()), u"-0°0′0.00360″")
|
||||
|
||||
# test with padding
|
||||
padding_and_suffix = QgsCoordinateFormatter.FormatFlags(QgsCoordinateFormatter.DegreesPadMinutesSeconds | QgsCoordinateFormatter.DegreesUseStringSuffix)
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(80, QgsCoordinateFormatter.DegreesMinutesSeconds, 2, padding_and_suffix), u"80°00′00.00″E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(85.44, QgsCoordinateFormatter.DegreesMinutesSeconds, 2, padding_and_suffix), u"85°26′24.00″E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0, QgsCoordinateFormatter.DegreesMinutesSeconds, 2, padding_and_suffix), u"0°00′00.00″")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-0.000001, QgsCoordinateFormatter.DegreesMinutesSeconds, 2, padding_and_suffix), u"0°00′00.00″")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0.000001, QgsCoordinateFormatter.DegreesMinutesSeconds, 2, padding_and_suffix), u"0°00′00.00″")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-0.000001, QgsCoordinateFormatter.DegreesMinutesSeconds, 5, padding_and_suffix), u"0°00′00.00360″W")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0.000001, QgsCoordinateFormatter.DegreesMinutesSeconds, 5, padding_and_suffix), u"0°00′00.00360″E")
|
||||
padding_and_suffix = QgsCoordinateFormatter.FormatFlags(QgsCoordinateFormatter.FlagDegreesPadMinutesSeconds | QgsCoordinateFormatter.FlagDegreesUseStringSuffix)
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(80, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2, padding_and_suffix), u"80°00′00.00″E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(85.44, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2, padding_and_suffix), u"85°26′24.00″E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2, padding_and_suffix), u"0°00′00.00″")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2, padding_and_suffix), u"0°00′00.00″")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2, padding_and_suffix), u"0°00′00.00″")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 5, padding_and_suffix), u"0°00′00.00360″W")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 5, padding_and_suffix), u"0°00′00.00360″E")
|
||||
|
||||
def testFormatYDegreesMinutesSeconds(self):
|
||||
def testFormatYFormatDegreesMinutesSeconds(self):
|
||||
"""Test formatting y as DMS"""
|
||||
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(20, QgsCoordinateFormatter.DegreesMinutesSeconds, 2), u"20°0′0.00″N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(20, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"20°0′0.00″N")
|
||||
|
||||
# check precision
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(20, QgsCoordinateFormatter.DegreesMinutesSeconds, 4), u"20°0′0.0000″N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(20.12345678, QgsCoordinateFormatter.DegreesMinutesSeconds, 4), u"20°7′24.4444″N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(20.12345678, QgsCoordinateFormatter.DegreesMinutesSeconds, 0), u"20°7′24″N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(20, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 4), u"20°0′0.0000″N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(20.12345678, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 4), u"20°7′24.4444″N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(20.12345678, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 0), u"20°7′24″N")
|
||||
|
||||
# check if latitudes > 90 or <-90 wrap around
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(190, QgsCoordinateFormatter.DegreesMinutesSeconds, 2), u"10°0′0.00″N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-190, QgsCoordinateFormatter.DegreesMinutesSeconds, 2), u"10°0′0.00″S")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(91, QgsCoordinateFormatter.DegreesMinutesSeconds, 2), u"89°0′0.00″S")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-91, QgsCoordinateFormatter.DegreesMinutesSeconds, 2), u"89°0′0.00″N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(179, QgsCoordinateFormatter.DegreesMinutesSeconds, 2), u"1°0′0.00″S")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-179, QgsCoordinateFormatter.DegreesMinutesSeconds, 2), u"1°0′0.00″N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(190, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"10°0′0.00″N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-190, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"10°0′0.00″S")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(91, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"89°0′0.00″S")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-91, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"89°0′0.00″N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(179, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"1°0′0.00″S")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-179, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"1°0′0.00″N")
|
||||
|
||||
# should be no directional suffixes for 0 degree coordinates
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0, QgsCoordinateFormatter.DegreesMinutesSeconds, 2), u"0°0′0.00″")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"0°0′0.00″")
|
||||
# should also be no directional suffix for 0 degree coordinates within specified precision
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0.000001, QgsCoordinateFormatter.DegreesMinutesSeconds, 2), u"0°0′0.00″")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0.000001, QgsCoordinateFormatter.DegreesMinutesSeconds, 5), u"0°0′0.00360″N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-0.000001, QgsCoordinateFormatter.DegreesMinutesSeconds, 2), u"0°0′0.00″")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-0.000001, QgsCoordinateFormatter.DegreesMinutesSeconds, 5), u"0°0′0.00360″S")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"0°0′0.00″")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 5), u"0°0′0.00360″N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"0°0′0.00″")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 5), u"0°0′0.00360″S")
|
||||
|
||||
# test rounding does not create seconds >= 60
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(89.999999, QgsCoordinateFormatter.DegreesMinutesSeconds, 2), u"90°0′0.00″N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(89.999999, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2), u"90°0′0.00″N")
|
||||
|
||||
# test without direction suffix
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(20, QgsCoordinateFormatter.DegreesMinutesSeconds, 2, QgsCoordinateFormatter.FormatFlags()), u"20°0′0.00″")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(20, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2, QgsCoordinateFormatter.FormatFlags()), u"20°0′0.00″")
|
||||
|
||||
# test 0 latitude
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0, QgsCoordinateFormatter.DegreesMinutesSeconds, 2, QgsCoordinateFormatter.FormatFlags()), u"0°0′0.00″")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2, QgsCoordinateFormatter.FormatFlags()), u"0°0′0.00″")
|
||||
# test near zero lat/long
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0.000001, QgsCoordinateFormatter.DegreesMinutesSeconds, 2, QgsCoordinateFormatter.FormatFlags()), u"0°0′0.00″")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2, QgsCoordinateFormatter.FormatFlags()), u"0°0′0.00″")
|
||||
# should be no "-" prefix for near-zero latitude when rounding to 2 decimal places
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-0.000001, QgsCoordinateFormatter.DegreesMinutesSeconds, 2, QgsCoordinateFormatter.FormatFlags()), u"0°0′0.00″")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0.000001, QgsCoordinateFormatter.DegreesMinutesSeconds, 5, QgsCoordinateFormatter.FormatFlags()), u"0°0′0.00360″")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-0.000001, QgsCoordinateFormatter.DegreesMinutesSeconds, 5, QgsCoordinateFormatter.FormatFlags()), u"-0°0′0.00360″")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2, QgsCoordinateFormatter.FormatFlags()), u"0°0′0.00″")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 5, QgsCoordinateFormatter.FormatFlags()), u"0°0′0.00360″")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 5, QgsCoordinateFormatter.FormatFlags()), u"-0°0′0.00360″")
|
||||
|
||||
# test with padding
|
||||
padding_and_suffix = QgsCoordinateFormatter.FormatFlags(QgsCoordinateFormatter.DegreesPadMinutesSeconds | QgsCoordinateFormatter.DegreesUseStringSuffix)
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(20, QgsCoordinateFormatter.DegreesMinutesSeconds, 2, padding_and_suffix), u"20°00′00.00″N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(85.44, QgsCoordinateFormatter.DegreesMinutesSeconds, 2, padding_and_suffix), u"85°26′24.00″N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0, QgsCoordinateFormatter.DegreesMinutesSeconds, 2, padding_and_suffix), u"0°00′00.00″")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-0.000001, QgsCoordinateFormatter.DegreesMinutesSeconds, 2, padding_and_suffix), u"0°00′00.00″")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0.000001, QgsCoordinateFormatter.DegreesMinutesSeconds, 2, padding_and_suffix), u"0°00′00.00″")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-0.000001, QgsCoordinateFormatter.DegreesMinutesSeconds, 5, padding_and_suffix), u"0°00′00.00360″S")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0.000001, QgsCoordinateFormatter.DegreesMinutesSeconds, 5, padding_and_suffix), u"0°00′00.00360″N")
|
||||
padding_and_suffix = QgsCoordinateFormatter.FormatFlags(QgsCoordinateFormatter.FlagDegreesPadMinutesSeconds | QgsCoordinateFormatter.FlagDegreesUseStringSuffix)
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(20, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2, padding_and_suffix), u"20°00′00.00″N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(85.44, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2, padding_and_suffix), u"85°26′24.00″N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2, padding_and_suffix), u"0°00′00.00″")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2, padding_and_suffix), u"0°00′00.00″")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2, padding_and_suffix), u"0°00′00.00″")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 5, padding_and_suffix), u"0°00′00.00360″S")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0.000001, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 5, padding_and_suffix), u"0°00′00.00360″N")
|
||||
|
||||
def testFormatXDegreesMinutes(self):
|
||||
"""Test formatting x as DM"""
|
||||
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(80, QgsCoordinateFormatter.DegreesMinutes, 2), u"80°0.00′E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(80, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"80°0.00′E")
|
||||
|
||||
# check precision
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(80, QgsCoordinateFormatter.DegreesMinutes, 4), u"80°0.0000′E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(80.12345678, QgsCoordinateFormatter.DegreesMinutes, 4), u"80°7.4074′E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(80.12345678, QgsCoordinateFormatter.DegreesMinutes, 0), u"80°7′E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(80, QgsCoordinateFormatter.FormatDegreesMinutes, 4), u"80°0.0000′E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(80.12345678, QgsCoordinateFormatter.FormatDegreesMinutes, 4), u"80°7.4074′E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(80.12345678, QgsCoordinateFormatter.FormatDegreesMinutes, 0), u"80°7′E")
|
||||
|
||||
# check if longitudes > 180 or <-180 wrap around
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(370, QgsCoordinateFormatter.DegreesMinutes, 2), u"10°0.00′E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-370, QgsCoordinateFormatter.DegreesMinutes, 2), u"10°0.00′W")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(181, QgsCoordinateFormatter.DegreesMinutes, 2), u"179°0.00′W")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-181, QgsCoordinateFormatter.DegreesMinutes, 2), u"179°0.00′E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(359, QgsCoordinateFormatter.DegreesMinutes, 2), u"1°0.00′W")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-359, QgsCoordinateFormatter.DegreesMinutes, 2), u"1°0.00′E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(370, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"10°0.00′E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-370, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"10°0.00′W")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(181, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"179°0.00′W")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-181, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"179°0.00′E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(359, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"1°0.00′W")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-359, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"1°0.00′E")
|
||||
|
||||
# should be no directional suffixes for 0 degree coordinates
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0, QgsCoordinateFormatter.DegreesMinutes, 2), u"0°0.00′")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"0°0.00′")
|
||||
# should also be no directional suffix for 0 degree coordinates within specified precision
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-0.000001, QgsCoordinateFormatter.DegreesMinutes, 2), u"0°0.00′")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0.000001, QgsCoordinateFormatter.DegreesMinutes, 2), u"0°0.00′")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-0.000001, QgsCoordinateFormatter.DegreesMinutes, 5), u"0°0.00006′W")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0.000001, QgsCoordinateFormatter.DegreesMinutes, 5), u"0°0.00006′E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"0°0.00′")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"0°0.00′")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 5), u"0°0.00006′W")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 5), u"0°0.00006′E")
|
||||
|
||||
# test rounding does not create minutes >= 60
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(99.999999, QgsCoordinateFormatter.DegreesMinutes, 2), u"100°0.00′E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(99.999999, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"100°0.00′E")
|
||||
|
||||
# should be no directional suffixes for 180 degree longitudes
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(180, QgsCoordinateFormatter.DegreesMinutes, 2), u"180°0.00′")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(180, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"180°0.00′")
|
||||
|
||||
# should also be no directional suffix for 180 degree longitudes within specified precision
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(180.000001, QgsCoordinateFormatter.DegreesMinutes, 2), u"180°0.00′")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(179.999999, QgsCoordinateFormatter.DegreesMinutes, 2), u"180°0.00′")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(180.000001, QgsCoordinateFormatter.DegreesMinutes, 5), u"179°59.99994′W")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(179.999999, QgsCoordinateFormatter.DegreesMinutes, 5), u"179°59.99994′E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(180.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"180°0.00′")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(179.999999, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"180°0.00′")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(180.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 5), u"179°59.99994′W")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(179.999999, QgsCoordinateFormatter.FormatDegreesMinutes, 5), u"179°59.99994′E")
|
||||
|
||||
# test without direction suffix
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(80, QgsCoordinateFormatter.DegreesMinutes, 2, QgsCoordinateFormatter.FormatFlags()), u"80°0.00′")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(80, QgsCoordinateFormatter.FormatDegreesMinutes, 2, QgsCoordinateFormatter.FormatFlags()), u"80°0.00′")
|
||||
# test 0 longitude
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0, QgsCoordinateFormatter.DegreesMinutes, 2, QgsCoordinateFormatter.FormatFlags()), u"0°0.00′")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0, QgsCoordinateFormatter.FormatDegreesMinutes, 2, QgsCoordinateFormatter.FormatFlags()), u"0°0.00′")
|
||||
# test near zero longitude
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0.000001, QgsCoordinateFormatter.DegreesMinutes, 2, QgsCoordinateFormatter.FormatFlags()), u"0°0.00′")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 2, QgsCoordinateFormatter.FormatFlags()), u"0°0.00′")
|
||||
# should be no "-" prefix for near-zero longitude when rounding to 2 decimal places
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-0.000001, QgsCoordinateFormatter.DegreesMinutes, 2, QgsCoordinateFormatter.FormatFlags()), u"0°0.00′")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0.000001, QgsCoordinateFormatter.DegreesMinutes, 5, QgsCoordinateFormatter.FormatFlags()), u"0°0.00006′")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-0.000001, QgsCoordinateFormatter.DegreesMinutes, 5, QgsCoordinateFormatter.FormatFlags()), u"-0°0.00006′")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 2, QgsCoordinateFormatter.FormatFlags()), u"0°0.00′")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 5, QgsCoordinateFormatter.FormatFlags()), u"0°0.00006′")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 5, QgsCoordinateFormatter.FormatFlags()), u"-0°0.00006′")
|
||||
|
||||
# test with padding
|
||||
padding_and_suffix = QgsCoordinateFormatter.FormatFlags(QgsCoordinateFormatter.DegreesMinutes | QgsCoordinateFormatter.DegreesUseStringSuffix)
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(80, QgsCoordinateFormatter.DegreesMinutes, 2, padding_and_suffix), u"80°00.00′E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0, QgsCoordinateFormatter.DegreesMinutes, 2, padding_and_suffix), u"0°00.00′")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-0.000001, QgsCoordinateFormatter.DegreesMinutes, 2, padding_and_suffix), u"0°00.00′")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0.000001, QgsCoordinateFormatter.DegreesMinutes, 2, padding_and_suffix), u"0°00.00′")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-0.000001, QgsCoordinateFormatter.DegreesMinutes, 5, padding_and_suffix), u"0°00.00006′W")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0.000001, QgsCoordinateFormatter.DegreesMinutes, 5, padding_and_suffix), u"0°00.00006′E")
|
||||
padding_and_suffix = QgsCoordinateFormatter.FormatFlags(QgsCoordinateFormatter.FormatDegreesMinutes | QgsCoordinateFormatter.FlagDegreesUseStringSuffix)
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(80, QgsCoordinateFormatter.FormatDegreesMinutes, 2, padding_and_suffix), u"80°00.00′E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0, QgsCoordinateFormatter.FormatDegreesMinutes, 2, padding_and_suffix), u"0°00.00′")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 2, padding_and_suffix), u"0°00.00′")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 2, padding_and_suffix), u"0°00.00′")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 5, padding_and_suffix), u"0°00.00006′W")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 5, padding_and_suffix), u"0°00.00006′E")
|
||||
|
||||
def testFormatYDegreesMinutes(self):
|
||||
"""Test formatting y as DM"""
|
||||
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(20, QgsCoordinateFormatter.DegreesMinutes, 2), u"20°0.00′N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(20, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"20°0.00′N")
|
||||
|
||||
# check precision
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(20, QgsCoordinateFormatter.DegreesMinutes, 4), u"20°0.0000′N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(20.12345678, QgsCoordinateFormatter.DegreesMinutes, 4), u"20°7.4074′N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(20.12345678, QgsCoordinateFormatter.DegreesMinutes, 0), u"20°7′N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(20, QgsCoordinateFormatter.FormatDegreesMinutes, 4), u"20°0.0000′N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(20.12345678, QgsCoordinateFormatter.FormatDegreesMinutes, 4), u"20°7.4074′N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(20.12345678, QgsCoordinateFormatter.FormatDegreesMinutes, 0), u"20°7′N")
|
||||
|
||||
# check if latitudes > 90 or <-90 wrap around
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(190, QgsCoordinateFormatter.DegreesMinutes, 2), u"10°0.00′N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-190, QgsCoordinateFormatter.DegreesMinutes, 2), u"10°0.00′S")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(91, QgsCoordinateFormatter.DegreesMinutes, 2), u"89°0.00′S")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-91, QgsCoordinateFormatter.DegreesMinutes, 2), u"89°0.00′N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(179, QgsCoordinateFormatter.DegreesMinutes, 2), u"1°0.00′S")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-179, QgsCoordinateFormatter.DegreesMinutes, 2), u"1°0.00′N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(190, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"10°0.00′N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-190, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"10°0.00′S")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(91, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"89°0.00′S")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-91, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"89°0.00′N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(179, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"1°0.00′S")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-179, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"1°0.00′N")
|
||||
|
||||
# should be no directional suffixes for 0 degree coordinates
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0, QgsCoordinateFormatter.DegreesMinutes, 2), u"0°0.00′")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"0°0.00′")
|
||||
# should also be no directional suffix for 0 degree coordinates within specified precision
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-0.000001, QgsCoordinateFormatter.DegreesMinutes, 2), u"0°0.00′")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0.000001, QgsCoordinateFormatter.DegreesMinutes, 2), u"0°0.00′")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-0.000001, QgsCoordinateFormatter.DegreesMinutes, 5), u"0°0.00006′S")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0.000001, QgsCoordinateFormatter.DegreesMinutes, 5), u"0°0.00006′N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"0°0.00′")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"0°0.00′")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 5), u"0°0.00006′S")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 5), u"0°0.00006′N")
|
||||
|
||||
# test rounding does not create minutes >= 60
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(79.999999, QgsCoordinateFormatter.DegreesMinutes, 2), u"80°0.00′N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(79.999999, QgsCoordinateFormatter.FormatDegreesMinutes, 2), u"80°0.00′N")
|
||||
|
||||
# test without direction suffix
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(20, QgsCoordinateFormatter.DegreesMinutes, 2, QgsCoordinateFormatter.FormatFlags()), u"20°0.00′")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(20, QgsCoordinateFormatter.FormatDegreesMinutes, 2, QgsCoordinateFormatter.FormatFlags()), u"20°0.00′")
|
||||
# test 0 latitude
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0, QgsCoordinateFormatter.DegreesMinutes, 2, QgsCoordinateFormatter.FormatFlags()), u"0°0.00′")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0, QgsCoordinateFormatter.FormatDegreesMinutes, 2, QgsCoordinateFormatter.FormatFlags()), u"0°0.00′")
|
||||
# test near zero latitude
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0.000001, QgsCoordinateFormatter.DegreesMinutes, 2, QgsCoordinateFormatter.FormatFlags()), u"0°0.00′")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 2, QgsCoordinateFormatter.FormatFlags()), u"0°0.00′")
|
||||
# should be no "-" prefix for near-zero latitude when rounding to 2 decimal places
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-0.000001, QgsCoordinateFormatter.DegreesMinutes, 2, QgsCoordinateFormatter.FormatFlags()), u"0°0.00′")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0.000001, QgsCoordinateFormatter.DegreesMinutes, 5, QgsCoordinateFormatter.FormatFlags()), u"0°0.00006′")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-0.000001, QgsCoordinateFormatter.DegreesMinutes, 5, QgsCoordinateFormatter.FormatFlags()), u"-0°0.00006′")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 2, QgsCoordinateFormatter.FormatFlags()), u"0°0.00′")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 5, QgsCoordinateFormatter.FormatFlags()), u"0°0.00006′")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 5, QgsCoordinateFormatter.FormatFlags()), u"-0°0.00006′")
|
||||
|
||||
# test with padding
|
||||
padding_and_suffix = QgsCoordinateFormatter.FormatFlags(QgsCoordinateFormatter.DegreesMinutes | QgsCoordinateFormatter.DegreesUseStringSuffix)
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(20, QgsCoordinateFormatter.DegreesMinutes, 2, padding_and_suffix), u"20°00.00′N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0, QgsCoordinateFormatter.DegreesMinutes, 2, padding_and_suffix), u"0°00.00′")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-0.000001, QgsCoordinateFormatter.DegreesMinutes, 2, padding_and_suffix), u"0°00.00′")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0.000001, QgsCoordinateFormatter.DegreesMinutes, 2, padding_and_suffix), u"0°00.00′")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-0.000001, QgsCoordinateFormatter.DegreesMinutes, 5, padding_and_suffix), u"0°00.00006′S")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0.000001, QgsCoordinateFormatter.DegreesMinutes, 5, padding_and_suffix), u"0°00.00006′N")
|
||||
padding_and_suffix = QgsCoordinateFormatter.FormatFlags(QgsCoordinateFormatter.FormatDegreesMinutes | QgsCoordinateFormatter.FlagDegreesUseStringSuffix)
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(20, QgsCoordinateFormatter.FormatDegreesMinutes, 2, padding_and_suffix), u"20°00.00′N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0, QgsCoordinateFormatter.FormatDegreesMinutes, 2, padding_and_suffix), u"0°00.00′")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 2, padding_and_suffix), u"0°00.00′")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 2, padding_and_suffix), u"0°00.00′")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 5, padding_and_suffix), u"0°00.00006′S")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 5, padding_and_suffix), u"0°00.00006′N")
|
||||
|
||||
def testFormatXDegrees(self):
|
||||
"""Test formatting x as decimal degrees"""
|
||||
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(80, QgsCoordinateFormatter.DecimalDegrees, 2), u"80.00°E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(80, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"80.00°E")
|
||||
|
||||
# check precision
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(80, QgsCoordinateFormatter.DecimalDegrees, 4), u"80.0000°E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(80.12345678, QgsCoordinateFormatter.DecimalDegrees, 4), u"80.1235°E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(80.12345678, QgsCoordinateFormatter.DecimalDegrees, 0), u"80°E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(80, QgsCoordinateFormatter.FormatDecimalDegrees, 4), u"80.0000°E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(80.12345678, QgsCoordinateFormatter.FormatDecimalDegrees, 4), u"80.1235°E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(80.12345678, QgsCoordinateFormatter.FormatDecimalDegrees, 0), u"80°E")
|
||||
|
||||
# check if longitudes > 180 or <-180 wrap around
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(370, QgsCoordinateFormatter.DecimalDegrees, 2), u"10.00°E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-370, QgsCoordinateFormatter.DecimalDegrees, 2), u"10.00°W")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(181, QgsCoordinateFormatter.DecimalDegrees, 2), u"179.00°W")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-181, QgsCoordinateFormatter.DecimalDegrees, 2), u"179.00°E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(359, QgsCoordinateFormatter.DecimalDegrees, 2), u"1.00°W")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-359, QgsCoordinateFormatter.DecimalDegrees, 2), u"1.00°E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(370, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"10.00°E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-370, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"10.00°W")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(181, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"179.00°W")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-181, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"179.00°E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(359, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"1.00°W")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-359, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"1.00°E")
|
||||
|
||||
# should be no directional suffixes for 0 degree coordinates
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0, QgsCoordinateFormatter.DecimalDegrees, 2), u"0.00°")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"0.00°")
|
||||
# should also be no directional suffix for 0 degree coordinates within specified precision
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-0.00001, QgsCoordinateFormatter.DecimalDegrees, 2), u"0.00°")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0.00001, QgsCoordinateFormatter.DecimalDegrees, 2), u"0.00°")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-0.00001, QgsCoordinateFormatter.DecimalDegrees, 5), u"0.00001°W")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0.00001, QgsCoordinateFormatter.DecimalDegrees, 5), u"0.00001°E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-0.00001, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"0.00°")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0.00001, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"0.00°")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-0.00001, QgsCoordinateFormatter.FormatDecimalDegrees, 5), u"0.00001°W")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0.00001, QgsCoordinateFormatter.FormatDecimalDegrees, 5), u"0.00001°E")
|
||||
|
||||
# should be no directional suffixes for 180 degree longitudes
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(180, QgsCoordinateFormatter.DecimalDegrees, 2), u"180.00°")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(180, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"180.00°")
|
||||
|
||||
# should also be no directional suffix for 180 degree longitudes within specified precision
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(180.000001, QgsCoordinateFormatter.DecimalDegrees, 2), u"180.00°")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(179.999999, QgsCoordinateFormatter.DecimalDegrees, 2), u"180.00°")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(180.000001, QgsCoordinateFormatter.DecimalDegrees, 6), u"179.999999°W")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(179.999999, QgsCoordinateFormatter.DecimalDegrees, 6), u"179.999999°E")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(180.000001, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"180.00°")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(179.999999, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"180.00°")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(180.000001, QgsCoordinateFormatter.FormatDecimalDegrees, 6), u"179.999999°W")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(179.999999, QgsCoordinateFormatter.FormatDecimalDegrees, 6), u"179.999999°E")
|
||||
|
||||
# test without direction suffix
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(80, QgsCoordinateFormatter.DecimalDegrees, 2, QgsCoordinateFormatter.FormatFlags()), u"80.00°")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(80, QgsCoordinateFormatter.FormatDecimalDegrees, 2, QgsCoordinateFormatter.FormatFlags()), u"80.00°")
|
||||
# test 0 longitude
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0, QgsCoordinateFormatter.DecimalDegrees, 2, QgsCoordinateFormatter.FormatFlags()), u"0.00°")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0, QgsCoordinateFormatter.FormatDecimalDegrees, 2, QgsCoordinateFormatter.FormatFlags()), u"0.00°")
|
||||
# test near zero longitude
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0.000001, QgsCoordinateFormatter.DecimalDegrees, 2, QgsCoordinateFormatter.FormatFlags()), u"0.00°")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0.000001, QgsCoordinateFormatter.FormatDecimalDegrees, 2, QgsCoordinateFormatter.FormatFlags()), u"0.00°")
|
||||
# should be no "-" prefix for near-zero longitude when rounding to 2 decimal places
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-0.000001, QgsCoordinateFormatter.DecimalDegrees, 2, QgsCoordinateFormatter.FormatFlags()), u"0.00°")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0.000001, QgsCoordinateFormatter.DecimalDegrees, 6, QgsCoordinateFormatter.FormatFlags()), u"0.000001°")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-0.000001, QgsCoordinateFormatter.DecimalDegrees, 6, QgsCoordinateFormatter.FormatFlags()), u"-0.000001°")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-0.000001, QgsCoordinateFormatter.FormatDecimalDegrees, 2, QgsCoordinateFormatter.FormatFlags()), u"0.00°")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(0.000001, QgsCoordinateFormatter.FormatDecimalDegrees, 6, QgsCoordinateFormatter.FormatFlags()), u"0.000001°")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatX(-0.000001, QgsCoordinateFormatter.FormatDecimalDegrees, 6, QgsCoordinateFormatter.FormatFlags()), u"-0.000001°")
|
||||
|
||||
def testFormatYDegrees(self):
|
||||
"""Test formatting y as decimal degrees"""
|
||||
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(20, QgsCoordinateFormatter.DecimalDegrees, 2), u"20.00°N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(20, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"20.00°N")
|
||||
|
||||
# check precision
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(20, QgsCoordinateFormatter.DecimalDegrees, 4), u"20.0000°N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(20.12345678, QgsCoordinateFormatter.DecimalDegrees, 4), u"20.1235°N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(20.12345678, QgsCoordinateFormatter.DecimalDegrees, 0), u"20°N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(20, QgsCoordinateFormatter.FormatDecimalDegrees, 4), u"20.0000°N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(20.12345678, QgsCoordinateFormatter.FormatDecimalDegrees, 4), u"20.1235°N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(20.12345678, QgsCoordinateFormatter.FormatDecimalDegrees, 0), u"20°N")
|
||||
|
||||
# check if latitudes > 90 or <-90 wrap around
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(190, QgsCoordinateFormatter.DecimalDegrees, 2), u"10.00°N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-190, QgsCoordinateFormatter.DecimalDegrees, 2), u"10.00°S")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(91, QgsCoordinateFormatter.DecimalDegrees, 2), u"89.00°S")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-91, QgsCoordinateFormatter.DecimalDegrees, 2), u"89.00°N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(179, QgsCoordinateFormatter.DecimalDegrees, 2), u"1.00°S")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-179, QgsCoordinateFormatter.DecimalDegrees, 2), u"1.00°N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(190, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"10.00°N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-190, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"10.00°S")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(91, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"89.00°S")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-91, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"89.00°N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(179, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"1.00°S")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-179, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"1.00°N")
|
||||
|
||||
# should be no directional suffixes for 0 degree coordinates
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0, QgsCoordinateFormatter.DecimalDegrees, 2), u"0.00°")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"0.00°")
|
||||
# should also be no directional suffix for 0 degree coordinates within specified precision
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-0.00001, QgsCoordinateFormatter.DecimalDegrees, 2), u"0.00°")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0.00001, QgsCoordinateFormatter.DecimalDegrees, 2), u"0.00°")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-0.00001, QgsCoordinateFormatter.DecimalDegrees, 5), u"0.00001°S")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0.00001, QgsCoordinateFormatter.DecimalDegrees, 5), u"0.00001°N")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-0.00001, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"0.00°")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0.00001, QgsCoordinateFormatter.FormatDecimalDegrees, 2), u"0.00°")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-0.00001, QgsCoordinateFormatter.FormatDecimalDegrees, 5), u"0.00001°S")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0.00001, QgsCoordinateFormatter.FormatDecimalDegrees, 5), u"0.00001°N")
|
||||
|
||||
# test without direction suffix
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(80, QgsCoordinateFormatter.DecimalDegrees, 2, QgsCoordinateFormatter.FormatFlags()), u"80.00°")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(80, QgsCoordinateFormatter.FormatDecimalDegrees, 2, QgsCoordinateFormatter.FormatFlags()), u"80.00°")
|
||||
# test 0 longitude
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0, QgsCoordinateFormatter.DecimalDegrees, 2, QgsCoordinateFormatter.FormatFlags()), u"0.00°")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0, QgsCoordinateFormatter.FormatDecimalDegrees, 2, QgsCoordinateFormatter.FormatFlags()), u"0.00°")
|
||||
# test near zero latitude
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0.000001, QgsCoordinateFormatter.DecimalDegrees, 2, QgsCoordinateFormatter.FormatFlags()), u"0.00°")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0.000001, QgsCoordinateFormatter.FormatDecimalDegrees, 2, QgsCoordinateFormatter.FormatFlags()), u"0.00°")
|
||||
# should be no "-" prefix for near-zero latitude when rounding to 2 decimal places
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-0.000001, QgsCoordinateFormatter.DecimalDegrees, 2, QgsCoordinateFormatter.FormatFlags()), u"0.00°")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0.000001, QgsCoordinateFormatter.DecimalDegrees, 6, QgsCoordinateFormatter.FormatFlags()), u"0.000001°")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-0.000001, QgsCoordinateFormatter.DecimalDegrees, 6, QgsCoordinateFormatter.FormatFlags()), u"-0.000001°")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-0.000001, QgsCoordinateFormatter.FormatDecimalDegrees, 2, QgsCoordinateFormatter.FormatFlags()), u"0.00°")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(0.000001, QgsCoordinateFormatter.FormatDecimalDegrees, 6, QgsCoordinateFormatter.FormatFlags()), u"0.000001°")
|
||||
self.assertEqual(QgsCoordinateFormatter.formatY(-0.000001, QgsCoordinateFormatter.FormatDecimalDegrees, 6, QgsCoordinateFormatter.FormatFlags()), u"-0.000001°")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Loading…
x
Reference in New Issue
Block a user