28 return formatAsPair( x, precision );
31 return formatXAsDegreesMinutesSeconds( x, precision, flags );
34 return formatXAsDegreesMinutes( x, precision, flags );
37 return formatXAsDegrees( x, precision, flags );
47 return formatAsPair( y, precision );
50 return formatYAsDegreesMinutesSeconds( y, precision, flags );
53 return formatYAsDegreesMinutes( y, precision, flags );
56 return formatYAsDegrees( y, precision, flags );
69 QString s = formatAsPair( x, precision );
71 s += formatAsPair( y, precision );
75 QString QgsCoordinateFormatter::formatAsPair(
double val,
int precision )
77 return std::isfinite( val ) ? QString::number( val,
'f', precision ) : QObject::tr(
"infinite" );
80 QString QgsCoordinateFormatter::formatXAsDegreesMinutesSeconds(
double val,
int precision, FormatFlags flags )
83 double wrappedX = std::fmod( val, 360.0 );
85 if ( wrappedX > 180.0 )
87 wrappedX = wrappedX - 360.0;
89 else if ( wrappedX < -180.0 )
91 wrappedX = wrappedX + 360.0;
94 int precisionMultiplier = std::pow( 10.0,
precision );
96 int degreesX = int( std::fabs( wrappedX ) );
97 double floatMinutesX = ( std::fabs( wrappedX ) - degreesX ) * 60.0;
98 int intMinutesX = int( floatMinutesX );
99 double secondsX = ( floatMinutesX - intMinutesX ) * 60.0;
102 if ( std::round( secondsX * precisionMultiplier ) >= 60 * precisionMultiplier )
104 secondsX = std::max( secondsX - 60, 0.0 );
106 if ( intMinutesX >= 60 )
117 hemisphere = wrappedX < 0 ? QObject::tr(
"W" ) : QObject::tr(
"E" );
123 sign = QObject::tr(
"-" );
128 if ( degreesX == 0 && intMinutesX == 0 && std::round( secondsX * precisionMultiplier ) == 0 )
135 if ( degreesX == 180 && intMinutesX == 0 && std::round( secondsX * precisionMultiplier ) == 0 )
146 minutesX = QString(
"%1" ).arg( intMinutesX, 2, 10, QChar(
'0' ) );
148 strSecondsX = QString(
"%1" ).arg( secondsX, digits,
'f',
precision, QChar(
'0' ) );
152 minutesX = QString::number( intMinutesX );
153 strSecondsX = QString::number( secondsX,
'f',
precision );
156 return sign + QString::number( degreesX ) + QChar( 176 ) +
157 minutesX + QChar( 0x2032 ) +
158 strSecondsX + QChar( 0x2033 ) +
162 QString QgsCoordinateFormatter::formatYAsDegreesMinutesSeconds(
double val,
int precision, FormatFlags flags )
165 double wrappedY = std::fmod( val, 180.0 );
167 if ( wrappedY > 90.0 )
169 wrappedY = wrappedY - 180.0;
171 else if ( wrappedY < -90.0 )
173 wrappedY = wrappedY + 180.0;
176 int precisionMultiplier = std::pow( 10.0,
precision );
178 int degreesY = int( std::fabs( wrappedY ) );
179 double floatMinutesY = ( std::fabs( wrappedY ) - degreesY ) * 60.0;
180 int intMinutesY = int( floatMinutesY );
181 double secondsY = ( floatMinutesY - intMinutesY ) * 60.0;
184 if ( std::round( secondsY * precisionMultiplier ) >= 60 * precisionMultiplier )
186 secondsY = std::max( secondsY - 60, 0.0 );
188 if ( intMinutesY >= 60 )
199 hemisphere = wrappedY < 0 ? QObject::tr(
"S" ) : QObject::tr(
"N" );
205 sign = QObject::tr(
"-" );
210 if ( degreesY == 0 && intMinutesY == 0 && std::round( secondsY * precisionMultiplier ) == 0 )
222 strMinutesY = QString(
"%1" ).arg( intMinutesY, 2, 10, QChar(
'0' ) );
224 strSecondsY = QString(
"%1" ).arg( secondsY, digits,
'f',
precision, QChar(
'0' ) );
228 strMinutesY = QString::number( intMinutesY );
229 strSecondsY = QString::number( secondsY,
'f',
precision );
232 return sign + QString::number( degreesY ) + QChar( 176 ) +
233 strMinutesY + QChar( 0x2032 ) +
234 strSecondsY + QChar( 0x2033 ) +
238 QString QgsCoordinateFormatter::formatXAsDegreesMinutes(
double val,
int precision, FormatFlags flags )
241 double wrappedX = std::fmod( val, 360.0 );
243 if ( wrappedX > 180.0 )
245 wrappedX = wrappedX - 360.0;
247 else if ( wrappedX < -180.0 )
249 wrappedX = wrappedX + 360.0;
252 int degreesX = int( std::fabs( wrappedX ) );
253 double floatMinutesX = ( std::fabs( wrappedX ) - degreesX ) * 60.0;
255 int precisionMultiplier = std::pow( 10.0,
precision );
258 if ( std::round( floatMinutesX * precisionMultiplier ) >= 60 * precisionMultiplier )
260 floatMinutesX = std::max( floatMinutesX - 60, 0.0 );
268 hemisphere = wrappedX < 0 ? QObject::tr(
"W" ) : QObject::tr(
"E" );
274 sign = QObject::tr(
"-" );
279 if ( degreesX == 0 && std::round( floatMinutesX * precisionMultiplier ) == 0 )
286 if ( degreesX == 180 && std::round( floatMinutesX * precisionMultiplier ) == 0 )
294 : QString::number( floatMinutesX,
'f',
precision );
296 return sign + QString::number( degreesX ) + QChar( 176 ) +
297 strMinutesX + QChar( 0x2032 ) +
301 QString QgsCoordinateFormatter::formatYAsDegreesMinutes(
double val,
int precision, FormatFlags flags )
304 double wrappedY = std::fmod( val, 180.0 );
306 if ( wrappedY > 90.0 )
308 wrappedY = wrappedY - 180.0;
310 else if ( wrappedY < -90.0 )
312 wrappedY = wrappedY + 180.0;
315 int degreesY = int( std::fabs( wrappedY ) );
316 double floatMinutesY = ( std::fabs( wrappedY ) - degreesY ) * 60.0;
318 int precisionMultiplier = std::pow( 10.0,
precision );
321 if ( std::round( floatMinutesY * precisionMultiplier ) >= 60 * precisionMultiplier )
323 floatMinutesY = std::max( floatMinutesY - 60, 0.0 );
331 hemisphere = wrappedY < 0 ? QObject::tr(
"S" ) : QObject::tr(
"N" );
337 sign = QObject::tr(
"-" );
342 if ( degreesY == 0 && std::round( floatMinutesY * precisionMultiplier ) == 0 )
352 : QString::number( floatMinutesY,
'f',
precision );
354 return sign + QString::number( degreesY ) + QChar( 176 ) +
355 strMinutesY + QChar( 0x2032 ) +
359 QString QgsCoordinateFormatter::formatXAsDegrees(
double val,
int precision, FormatFlags flags )
362 double wrappedX = std::fmod( val, 360.0 );
364 if ( wrappedX > 180.0 )
366 wrappedX = wrappedX - 360.0;
368 else if ( wrappedX < -180.0 )
370 wrappedX = wrappedX + 360.0;
373 double absX = std::fabs( wrappedX );
375 int precisionMultiplier = std::pow( 10.0,
precision );
381 hemisphere = wrappedX < 0 ? QObject::tr(
"W" ) : QObject::tr(
"E" );
387 sign = QObject::tr(
"-" );
392 if ( std::round( absX * precisionMultiplier ) == 0 )
399 if ( std::round( absX * precisionMultiplier ) == 180 * precisionMultiplier )
405 return sign + QString::number( absX,
'f',
precision ) + QChar( 176 ) + hemisphere;
408 QString QgsCoordinateFormatter::formatYAsDegrees(
double val,
int precision, FormatFlags flags )
411 double wrappedY = std::fmod( val, 180.0 );
413 if ( wrappedY > 90.0 )
415 wrappedY = wrappedY - 180.0;
417 else if ( wrappedY < -90.0 )
419 wrappedY = wrappedY + 180.0;
422 double absY = std::fabs( wrappedY );
424 int precisionMultiplier = std::pow( 10.0,
precision );
430 hemisphere = wrappedY < 0 ? QObject::tr(
"S" ) : QObject::tr(
"N" );
436 sign = QObject::tr(
"-" );
441 if ( std::round( absY * precisionMultiplier ) == 0 )
447 return sign + QString::number( absY,
'f',
precision ) + QChar( 176 ) + hemisphere;
A class to represent a 2D point.