32 return formatXAsDegreesMinutesSeconds( x,
precision, flags );
35 return formatXAsDegreesMinutes( x,
precision, flags );
38 return formatXAsDegrees( x,
precision, flags );
51 return formatYAsDegreesMinutesSeconds( y,
precision, flags );
54 return formatYAsDegreesMinutes( y,
precision, flags );
57 return formatYAsDegrees( y,
precision, flags );
81 const QString formattedX = formatAsPair( x,
precision );
82 const QString formattedY = formatAsPair( y,
precision );
98 return QLocale().decimalPoint() == QLatin1Char(
',' ) ? QLatin1Char(
' ' ) : QLatin1Char(
',' );
101QString QgsCoordinateFormatter::formatAsPair(
double val,
int precision )
103 return std::isfinite( val ) ? QLocale().toString( val,
'f',
precision ) : QObject::tr(
"infinite" );
106QString QgsCoordinateFormatter::formatXAsDegreesMinutesSeconds(
double val,
int precision, FormatFlags flags )
109 double wrappedX = std::fmod( val, 360.0 );
111 if ( wrappedX > 180.0 )
113 wrappedX = wrappedX - 360.0;
115 else if ( wrappedX < -180.0 )
117 wrappedX = wrappedX + 360.0;
120 const double precisionMultiplier = std::pow( 10.0,
precision );
122 int degreesX = int( std::fabs( wrappedX ) );
123 const double floatMinutesX = ( std::fabs( wrappedX ) - degreesX ) * 60.0;
124 int intMinutesX = int( floatMinutesX );
125 double secondsX = ( floatMinutesX - intMinutesX ) * 60.0;
128 if ( std::round( secondsX * precisionMultiplier ) >= 60 * precisionMultiplier )
130 secondsX = std::max( secondsX - 60, 0.0 );
132 if ( intMinutesX >= 60 )
143 hemisphere = wrappedX < 0 ? QObject::tr(
"W" ) : QObject::tr(
"E" );
149 sign = QLocale().negativeSign();
154 if ( degreesX == 0 && intMinutesX == 0 && std::round( secondsX * precisionMultiplier ) == 0 )
161 if ( degreesX == 180 && intMinutesX == 0 && std::round( secondsX * precisionMultiplier ) == 0 )
172 minutesX = QString(
"%L1" ).arg( intMinutesX, 2, 10, QChar(
'0' ) );
174 strSecondsX = QString(
"%L1" ).arg( secondsX, digits,
'f',
precision, QChar(
'0' ) );
178 minutesX = QLocale().toString( intMinutesX );
179 strSecondsX = QLocale().toString( secondsX,
'f',
precision );
182 return sign + QLocale().toString( degreesX ) + QChar( 176 ) +
183 minutesX + QChar( 0x2032 ) +
184 strSecondsX + QChar( 0x2033 ) +
188QString QgsCoordinateFormatter::formatYAsDegreesMinutesSeconds(
double val,
int precision, FormatFlags flags )
191 double wrappedY = std::fmod( val, 180.0 );
193 if ( wrappedY > 90.0 )
195 wrappedY = wrappedY - 180.0;
197 else if ( wrappedY < -90.0 )
199 wrappedY = wrappedY + 180.0;
202 const double precisionMultiplier = std::pow( 10.0,
precision );
204 int degreesY = int( std::fabs( wrappedY ) );
205 const double floatMinutesY = ( std::fabs( wrappedY ) - degreesY ) * 60.0;
206 int intMinutesY = int( floatMinutesY );
207 double secondsY = ( floatMinutesY - intMinutesY ) * 60.0;
210 if ( std::round( secondsY * precisionMultiplier ) >= 60 * precisionMultiplier )
212 secondsY = std::max( secondsY - 60, 0.0 );
214 if ( intMinutesY >= 60 )
225 hemisphere = wrappedY < 0 ? QObject::tr(
"S" ) : QObject::tr(
"N" );
231 sign = QLocale().negativeSign();
236 if ( degreesY == 0 && intMinutesY == 0 && std::round( secondsY * precisionMultiplier ) == 0 )
248 strMinutesY = QString(
"%L1" ).arg( intMinutesY, 2, 10, QChar(
'0' ) );
250 strSecondsY = QString(
"%L1" ).arg( secondsY, digits,
'f',
precision, QChar(
'0' ) );
254 strMinutesY = QLocale().toString( intMinutesY );
255 strSecondsY = QLocale().toString( secondsY,
'f',
precision );
258 return sign + QLocale().toString( degreesY ) + QChar( 176 ) +
259 strMinutesY + QChar( 0x2032 ) +
260 strSecondsY + QChar( 0x2033 ) +
264QString QgsCoordinateFormatter::formatXAsDegreesMinutes(
double val,
int precision, FormatFlags flags )
267 double wrappedX = std::fmod( val, 360.0 );
269 if ( wrappedX > 180.0 )
271 wrappedX = wrappedX - 360.0;
273 else if ( wrappedX < -180.0 )
275 wrappedX = wrappedX + 360.0;
278 int degreesX = int( std::fabs( wrappedX ) );
279 double floatMinutesX = ( std::fabs( wrappedX ) - degreesX ) * 60.0;
281 const double precisionMultiplier = std::pow( 10.0,
precision );
284 if ( std::round( floatMinutesX * precisionMultiplier ) >= 60 * precisionMultiplier )
286 floatMinutesX = std::max( floatMinutesX - 60, 0.0 );
294 hemisphere = wrappedX < 0 ? QObject::tr(
"W" ) : QObject::tr(
"E" );
300 sign = QLocale().negativeSign();
305 if ( degreesX == 0 && std::round( floatMinutesX * precisionMultiplier ) == 0 )
312 if ( degreesX == 180 && std::round( floatMinutesX * precisionMultiplier ) == 0 )
320 : QLocale().toString( floatMinutesX,
'f',
precision );
322 return sign + QLocale().toString( degreesX ) + QChar( 176 ) +
323 strMinutesX + QChar( 0x2032 ) +
327QString QgsCoordinateFormatter::formatYAsDegreesMinutes(
double val,
int precision, FormatFlags flags )
330 double wrappedY = std::fmod( val, 180.0 );
332 if ( wrappedY > 90.0 )
334 wrappedY = wrappedY - 180.0;
336 else if ( wrappedY < -90.0 )
338 wrappedY = wrappedY + 180.0;
341 int degreesY = int( std::fabs( wrappedY ) );
342 double floatMinutesY = ( std::fabs( wrappedY ) - degreesY ) * 60.0;
344 const double precisionMultiplier = std::pow( 10.0,
precision );
347 if ( std::round( floatMinutesY * precisionMultiplier ) >= 60 * precisionMultiplier )
349 floatMinutesY = std::max( floatMinutesY - 60, 0.0 );
357 hemisphere = wrappedY < 0 ? QObject::tr(
"S" ) : QObject::tr(
"N" );
363 sign = QLocale().negativeSign();
368 if ( degreesY == 0 && std::round( floatMinutesY * precisionMultiplier ) == 0 )
378 : QLocale().toString( floatMinutesY,
'f',
precision );
380 return sign + QLocale().toString( degreesY ) + QChar( 176 ) +
381 strMinutesY + QChar( 0x2032 ) +
385QString QgsCoordinateFormatter::formatXAsDegrees(
double val,
int precision, FormatFlags flags )
388 double wrappedX = std::fmod( val, 360.0 );
390 if ( wrappedX > 180.0 )
392 wrappedX = wrappedX - 360.0;
394 else if ( wrappedX < -180.0 )
396 wrappedX = wrappedX + 360.0;
399 const double absX = std::fabs( wrappedX );
401 const double precisionMultiplier = std::pow( 10.0,
precision );
407 hemisphere = wrappedX < 0 ? QObject::tr(
"W" ) : QObject::tr(
"E" );
413 sign = QLocale().negativeSign();
418 if ( std::round( absX * precisionMultiplier ) == 0 )
425 if ( std::round( absX * precisionMultiplier ) == 180 * precisionMultiplier )
431 return sign + QLocale().toString( absX,
'f',
precision ) + QChar( 176 ) + hemisphere;
434QString QgsCoordinateFormatter::formatYAsDegrees(
double val,
int precision, FormatFlags flags )
437 double wrappedY = std::fmod( val, 180.0 );
439 if ( wrappedY > 90.0 )
441 wrappedY = wrappedY - 180.0;
443 else if ( wrappedY < -90.0 )
445 wrappedY = wrappedY + 180.0;
448 const double absY = std::fabs( wrappedY );
450 const double precisionMultiplier = std::pow( 10.0,
precision );
456 hemisphere = wrappedY < 0 ? QObject::tr(
"S" ) : QObject::tr(
"N" );
462 sign = QLocale().negativeSign();
467 if ( std::round( absY * precisionMultiplier ) == 0 )
473 return sign + QLocale().toString( absY,
'f',
precision ) + QChar( 176 ) + hemisphere;
CoordinateOrder
Order of coordinates.
@ XY
Easting/Northing (or Longitude/Latitude for geographic CRS)
@ Default
Respect the default axis ordering for the CRS, as defined in the CRS's parameters.
@ YX
Northing/Easting (or Latitude/Longitude for geographic CRS)
A class to represent a 2D point.
#define BUILTIN_UNREACHABLE