QGIS API Documentation  3.21.0-Master (909859188c)
qgscoordinateformatter.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscoordinateformatter.h
3  ------------------------
4  begin : Decemeber 2015
5  copyright : (C) 2015 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSCOORDINATEFORMATTER_H
19 #define QGSCOORDINATEFORMATTER_H
20 
21 #include <QString>
22 #include "qgis_sip.h"
23 #include "qgspointxy.h"
24 
40 class CORE_EXPORT QgsCoordinateFormatter
41 {
42  public:
43 
47  enum Format
48  {
53  };
54 
59  {
60  FlagDegreesUseStringSuffix = 1 << 1,
61  FlagDegreesPadMinutesSeconds = 1 << 2,
62  };
63  Q_DECLARE_FLAGS( FormatFlags, FormatFlag )
64 
65 
76  static QString formatX( double x, Format format, int precision = 12, FormatFlags flags = FlagDegreesUseStringSuffix );
77 
89  static QString formatY( double y, Format format, int precision = 12, FormatFlags flags = FlagDegreesUseStringSuffix );
90 
100  static QString format( const QgsPointXY &point, Format format, int precision = 12, FormatFlags flags = FlagDegreesUseStringSuffix );
101 
106  static QString asPair( double x, double y, int precision = 12 );
107 
113  static QChar separator( );
114 
115  private:
116 
117  static QString formatAsPair( double val, int precision );
118 
119  static QString formatXAsDegreesMinutesSeconds( double val, int precision, FormatFlags flags );
120  static QString formatYAsDegreesMinutesSeconds( double val, int precision, FormatFlags flags );
121 
122  static QString formatXAsDegreesMinutes( double val, int precision, FormatFlags flags );
123  static QString formatYAsDegreesMinutes( double val, int precision, FormatFlags flags );
124 
125  static QString formatXAsDegrees( double val, int precision, FormatFlags flags );
126  static QString formatYAsDegrees( double val, int precision, FormatFlags flags );
127 };
128 
129 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsCoordinateFormatter::FormatFlags )
130 
131 #endif // QGSCOORDINATEFORMATTER_H
Contains methods for converting coordinates for display in various formats.
Format
Available formats for displaying coordinates.
@ FormatDecimalDegrees
Decimal degrees, eg 30.7555 degrees.
@ FormatPair
Formats coordinates as an "x,y" pair.
@ FormatDegreesMinutes
Degrees and decimal minutes, eg 30degrees 45.55'.
@ FormatDegreesMinutesSeconds
Degrees, minutes and seconds, eg 30 degrees 45'30".
FormatFlag
Flags for controlling formatting of coordinates.
A class to represent a 2D point.
Definition: qgspointxy.h:59
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsField::ConfigurationFlags) CORE_EXPORT QDataStream &operator<<(QDataStream &out
Writes the field to stream out. QGIS version compatibility is not guaranteed.
int precision