Skip to content
Permalink
Browse files

Initial implementation of QgsCoordinateFormatter

  • Loading branch information
nyalldawson committed Nov 15, 2017
1 parent 80ad163 commit 916c56b9377164586d2abe95520dc0205ec6480a
@@ -0,0 +1,70 @@
/** \ingroup core
* \class QgsCoordinateFormatter
* \brief Contains methods for converting coordinates for display in various formats.
*
* QgsCoordinateFormatter contains static methods for converting numeric coordinates into different
* formats, for instance as degrees, minutes, seconds values. Note that QgsCoordinateFormatter has
* no consideration for the validity of converting coordinates to the various display formats, and it
* is up to the caller to ensure that sensible formats are used for particular coordinates. For instance,
* ensuring that only geographic coordinates and not projected coordinates are formatted to degree
* based formats.
*
* \note Added in version 2.14
*/

class QgsCoordinateFormatter
{
%TypeHeaderCode
#include <qgscoordinateformatter.h>
%End

public:

/** Available formats for displaying coordinates.
*/
enum Format
{
Pair, /*!< Formats coordinates as an "x,y" pair */
DegreesMinutesSeconds, /*!< Degrees, minutes and seconds, eg 30 degrees 45'30" */
DegreesMinutes, /*!< Degrees and decimal minutes, eg 30degrees 45.55' */
DecimalDegrees, /*!< Decimal degrees, eg 30.7555 degrees */
};

/** Flags for controlling formatting of coordinates.
*/
enum FormatFlag
{
DegreesUseStringSuffix, /*!< include a direction suffix (eg 'N', 'E', 'S' or 'W'), otherwise a "-" prefix is used for west and south coordinates */
DegreesPadMinutesSeconds, /*!< pad minute and second values with leading zeros, eg '05' instead of '5' */
};
typedef QFlags<QgsCoordinateFormatter::FormatFlag> FormatFlags;

/** Formats an X coordinate value according to the specified parameters.
* @param x x-coordinate
* @param format string format to use for coordinate
* @param precision number of decimal places to include
* @param flags flags controlling format options
* @returns formatted X coordinate string
* @see formatY()
*/
static QString formatX( double x, Format format, int precision = 12, FormatFlags flags = DegreesUseStringSuffix );

/** Formats an Y coordinate value according to the specified parameters.
* @param y y-coordinate
* @param format string format to use for coordinate
* @param precision number of decimal places to include
* @param flags flags controlling format options
* @returns formatted Y coordinate string
* @see formatX()
*/
static QString formatY( double y, Format format, int precision = 12, FormatFlags flags = DegreesUseStringSuffix );

/** Formats coordinates as an "x,y" pair, with optional decimal precision.
* @param x x-coordinate
* @param y y-coordinate
* @param precision number of decimal places to include
* @returns formatted coordinate string
*/
static QString asPair( double x, double y, int precision = 12 );

};
@@ -145,6 +145,7 @@ SET(QGIS_CORE_SRCS
qgscolorscheme.cpp
qgscolorschemeregistry.cpp
qgsconditionalstyle.cpp
qgscoordinateformatter.cpp
qgscoordinatereferencesystem.cpp
qgscoordinatetransform.cpp
qgscoordinatetransform_p.cpp
@@ -832,6 +833,7 @@ SET(QGIS_CORE_HDRS
qgscolorschemeregistry.h
qgsconnectionpool.h
qgsconditionalstyle.h
qgscoordinateformatter.h
qgscoordinatetransform.h
qgscoordinateutils.h
qgscrscache.h

0 comments on commit 916c56b

Please sign in to comment.
You can’t perform that action at this time.