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 );
79 return QLocale().decimalPoint() == QLatin1Char(
',' ) ? QLatin1Char(
' ' ) : QLatin1Char(
',' );
82 QString QgsCoordinateFormatter::formatAsPair(
double val,
int precision )
84 return std::isfinite( val ) ? QLocale().toString( val,
'f',
precision ) : QObject::tr(
"infinite" );
87 QString QgsCoordinateFormatter::formatXAsDegreesMinutesSeconds(
double val,
int precision, FormatFlags flags )
90 double wrappedX = std::fmod( val, 360.0 );
92 if ( wrappedX > 180.0 )
94 wrappedX = wrappedX - 360.0;
96 else if ( wrappedX < -180.0 )
98 wrappedX = wrappedX + 360.0;
101 const int precisionMultiplier = std::pow( 10.0,
precision );
103 int degreesX = int( std::fabs( wrappedX ) );
104 const double floatMinutesX = ( std::fabs( wrappedX ) - degreesX ) * 60.0;
105 int intMinutesX = int( floatMinutesX );
106 double secondsX = ( floatMinutesX - intMinutesX ) * 60.0;
109 if ( std::round( secondsX * precisionMultiplier ) >= 60 * precisionMultiplier )
111 secondsX = std::max( secondsX - 60, 0.0 );
113 if ( intMinutesX >= 60 )
124 hemisphere = wrappedX < 0 ? QObject::tr(
"W" ) : QObject::tr(
"E" );
130 sign = QLocale().negativeSign();
135 if ( degreesX == 0 && intMinutesX == 0 && std::round( secondsX * precisionMultiplier ) == 0 )
142 if ( degreesX == 180 && intMinutesX == 0 && std::round( secondsX * precisionMultiplier ) == 0 )
153 minutesX = QString(
"%L1" ).arg( intMinutesX, 2, 10, QChar(
'0' ) );
155 strSecondsX = QString(
"%L1" ).arg( secondsX, digits,
'f',
precision, QChar(
'0' ) );
159 minutesX = QLocale().toString( intMinutesX );
160 strSecondsX = QLocale().toString( secondsX,
'f',
precision );
163 return sign + QLocale().toString( degreesX ) + QChar( 176 ) +
164 minutesX + QChar( 0x2032 ) +
165 strSecondsX + QChar( 0x2033 ) +
169 QString QgsCoordinateFormatter::formatYAsDegreesMinutesSeconds(
double val,
int precision, FormatFlags flags )
172 double wrappedY = std::fmod( val, 180.0 );
174 if ( wrappedY > 90.0 )
176 wrappedY = wrappedY - 180.0;
178 else if ( wrappedY < -90.0 )
180 wrappedY = wrappedY + 180.0;
183 const int precisionMultiplier = std::pow( 10.0,
precision );
185 int degreesY = int( std::fabs( wrappedY ) );
186 const double floatMinutesY = ( std::fabs( wrappedY ) - degreesY ) * 60.0;
187 int intMinutesY = int( floatMinutesY );
188 double secondsY = ( floatMinutesY - intMinutesY ) * 60.0;
191 if ( std::round( secondsY * precisionMultiplier ) >= 60 * precisionMultiplier )
193 secondsY = std::max( secondsY - 60, 0.0 );
195 if ( intMinutesY >= 60 )
206 hemisphere = wrappedY < 0 ? QObject::tr(
"S" ) : QObject::tr(
"N" );
212 sign = QLocale().negativeSign();
217 if ( degreesY == 0 && intMinutesY == 0 && std::round( secondsY * precisionMultiplier ) == 0 )
229 strMinutesY = QString(
"%L1" ).arg( intMinutesY, 2, 10, QChar(
'0' ) );
231 strSecondsY = QString(
"%L1" ).arg( secondsY, digits,
'f',
precision, QChar(
'0' ) );
235 strMinutesY = QLocale().toString( intMinutesY );
236 strSecondsY = QLocale().toString( secondsY,
'f',
precision );
239 return sign + QLocale().toString( degreesY ) + QChar( 176 ) +
240 strMinutesY + QChar( 0x2032 ) +
241 strSecondsY + QChar( 0x2033 ) +
245 QString QgsCoordinateFormatter::formatXAsDegreesMinutes(
double val,
int precision, FormatFlags flags )
248 double wrappedX = std::fmod( val, 360.0 );
250 if ( wrappedX > 180.0 )
252 wrappedX = wrappedX - 360.0;
254 else if ( wrappedX < -180.0 )
256 wrappedX = wrappedX + 360.0;
259 int degreesX = int( std::fabs( wrappedX ) );
260 double floatMinutesX = ( std::fabs( wrappedX ) - degreesX ) * 60.0;
262 const int precisionMultiplier = std::pow( 10.0,
precision );
265 if ( std::round( floatMinutesX * precisionMultiplier ) >= 60 * precisionMultiplier )
267 floatMinutesX = std::max( floatMinutesX - 60, 0.0 );
275 hemisphere = wrappedX < 0 ? QObject::tr(
"W" ) : QObject::tr(
"E" );
281 sign = QLocale().negativeSign();
286 if ( degreesX == 0 && std::round( floatMinutesX * precisionMultiplier ) == 0 )
293 if ( degreesX == 180 && std::round( floatMinutesX * precisionMultiplier ) == 0 )
301 : QLocale().toString( floatMinutesX,
'f',
precision );
303 return sign + QLocale().toString( degreesX ) + QChar( 176 ) +
304 strMinutesX + QChar( 0x2032 ) +
308 QString QgsCoordinateFormatter::formatYAsDegreesMinutes(
double val,
int precision, FormatFlags flags )
311 double wrappedY = std::fmod( val, 180.0 );
313 if ( wrappedY > 90.0 )
315 wrappedY = wrappedY - 180.0;
317 else if ( wrappedY < -90.0 )
319 wrappedY = wrappedY + 180.0;
322 int degreesY = int( std::fabs( wrappedY ) );
323 double floatMinutesY = ( std::fabs( wrappedY ) - degreesY ) * 60.0;
325 const int precisionMultiplier = std::pow( 10.0,
precision );
328 if ( std::round( floatMinutesY * precisionMultiplier ) >= 60 * precisionMultiplier )
330 floatMinutesY = std::max( floatMinutesY - 60, 0.0 );
338 hemisphere = wrappedY < 0 ? QObject::tr(
"S" ) : QObject::tr(
"N" );
344 sign = QLocale().negativeSign();
349 if ( degreesY == 0 && std::round( floatMinutesY * precisionMultiplier ) == 0 )
359 : QLocale().toString( floatMinutesY,
'f',
precision );
361 return sign + QLocale().toString( degreesY ) + QChar( 176 ) +
362 strMinutesY + QChar( 0x2032 ) +
366 QString QgsCoordinateFormatter::formatXAsDegrees(
double val,
int precision, FormatFlags flags )
369 double wrappedX = std::fmod( val, 360.0 );
371 if ( wrappedX > 180.0 )
373 wrappedX = wrappedX - 360.0;
375 else if ( wrappedX < -180.0 )
377 wrappedX = wrappedX + 360.0;
380 const double absX = std::fabs( wrappedX );
382 const int precisionMultiplier = std::pow( 10.0,
precision );
388 hemisphere = wrappedX < 0 ? QObject::tr(
"W" ) : QObject::tr(
"E" );
394 sign = QLocale().negativeSign();
399 if ( std::round( absX * precisionMultiplier ) == 0 )
406 if ( std::round( absX * precisionMultiplier ) == 180 * precisionMultiplier )
412 return sign + QLocale().toString( absX,
'f',
precision ) + QChar( 176 ) + hemisphere;
415 QString QgsCoordinateFormatter::formatYAsDegrees(
double val,
int precision, FormatFlags flags )
418 double wrappedY = std::fmod( val, 180.0 );
420 if ( wrappedY > 90.0 )
422 wrappedY = wrappedY - 180.0;
424 else if ( wrappedY < -90.0 )
426 wrappedY = wrappedY + 180.0;
429 const double absY = std::fabs( wrappedY );
431 const int precisionMultiplier = std::pow( 10.0,
precision );
437 hemisphere = wrappedY < 0 ? QObject::tr(
"S" ) : QObject::tr(
"N" );
443 sign = QLocale().negativeSign();
448 if ( std::round( absY * precisionMultiplier ) == 0 )
454 return sign + QLocale().toString( absY,
'f',
precision ) + QChar( 176 ) + hemisphere;
A class to represent a 2D point.