QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
Public Types | Static Public Member Functions | Friends | List of all members
QgsCoordinateFormatter Class Reference

Contains methods for converting coordinates for display in various formats. More...

#include <qgscoordinateformatter.h>

Public Types

enum  Format { FormatPair , FormatDegreesMinutesSeconds , FormatDegreesMinutes , FormatDecimalDegrees }
 Available formats for displaying coordinates. More...
 
enum  FormatFlag { FlagDegreesUseStringSuffix = 1 << 1 , FlagDegreesPadMinutesSeconds = 1 << 2 }
 Flags for controlling formatting of coordinates. More...
 
typedef QFlags< FormatFlagFormatFlags
 

Static Public Member Functions

static QString asPair (double x, double y, int precision=12, Qgis::CoordinateOrder order=Qgis::CoordinateOrder::XY)
 Formats coordinates as an "\a x,\a y" pair, with optional decimal precision (number of decimal places to include).
 
static QString format (const QgsPointXY &point, Format format, int precision=12, FormatFlags flags=FlagDegreesUseStringSuffix, Qgis::CoordinateOrder order=Qgis::CoordinateOrder::XY)
 Formats a point according to the specified parameters.
 
static QString formatX (double x, Format format, int precision=12, FormatFlags flags=FlagDegreesUseStringSuffix)
 Formats an x coordinate value according to the specified parameters.
 
static QString formatY (double y, Format format, int precision=12, FormatFlags flags=FlagDegreesUseStringSuffix)
 Formats a y coordinate value according to the specified parameters.
 
static QChar separator ()
 Returns the character used as X/Y separator, this is a , on locales that do not use , as decimal separator, it is a space otherwise.
 

Friends

class QgsCoordinateUtils
 

Detailed Description

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.

Definition at line 39 of file qgscoordinateformatter.h.

Member Typedef Documentation

◆ FormatFlags

Definition at line 62 of file qgscoordinateformatter.h.

Member Enumeration Documentation

◆ Format

Available formats for displaying coordinates.

Enumerator
FormatPair 

Formats coordinates as an "x,y" pair.

FormatDegreesMinutesSeconds 

Degrees, minutes and seconds, eg 30 degrees 45'30".

FormatDegreesMinutes 

Degrees and decimal minutes, eg 30degrees 45.55'.

FormatDecimalDegrees 

Decimal degrees, eg 30.7555 degrees.

Definition at line 46 of file qgscoordinateformatter.h.

◆ FormatFlag

Flags for controlling formatting of coordinates.

Enumerator
FlagDegreesUseStringSuffix 

Include a direction suffix (eg 'N', 'E', 'S' or 'W'), otherwise a "-" prefix is used for west and south coordinates.

FlagDegreesPadMinutesSeconds 

Pad minute and second values with leading zeros, eg '05' instead of '5'.

Definition at line 57 of file qgscoordinateformatter.h.

Member Function Documentation

◆ asPair()

QString QgsCoordinateFormatter::asPair ( double  x,
double  y,
int  precision = 12,
Qgis::CoordinateOrder  order = Qgis::CoordinateOrder::XY 
)
static

Formats coordinates as an "\a x,\a y" pair, with optional decimal precision (number of decimal places to include).

Since QGIS 3.26 the optional order argument can be used to control the order of the coordinates.

Definition at line 79 of file qgscoordinateformatter.cpp.

◆ format()

QString QgsCoordinateFormatter::format ( const QgsPointXY point,
QgsCoordinateFormatter::Format  format,
int  precision = 12,
FormatFlags  flags = FlagDegreesUseStringSuffix,
Qgis::CoordinateOrder  order = Qgis::CoordinateOrder::XY 
)
static

Formats a point according to the specified parameters.

The format argument indicates the desired display format for the coordinate.

The precision argument gives the number of decimal places to include for coordinates.

Optional flags can be specified to control the output format.

Since QGIS 3.26 the optional order argument can be used to control the order of the coordinates.

Definition at line 62 of file qgscoordinateformatter.cpp.

◆ formatX()

QString QgsCoordinateFormatter::formatX ( double  x,
QgsCoordinateFormatter::Format  format,
int  precision = 12,
FormatFlags  flags = FlagDegreesUseStringSuffix 
)
static

Formats an x coordinate value according to the specified parameters.

The format argument indicates the desired display format for the coordinate.

The precision argument gives the number of decimal places to include for coordinates.

Optional flags can be specified to control the output format.

See also
formatY()

Definition at line 24 of file qgscoordinateformatter.cpp.

◆ formatY()

QString QgsCoordinateFormatter::formatY ( double  y,
QgsCoordinateFormatter::Format  format,
int  precision = 12,
FormatFlags  flags = FlagDegreesUseStringSuffix 
)
static

Formats a y coordinate value according to the specified parameters.

The format argument indicates the desired display format for the coordinate.

The precision argument gives the number of decimal places to include for coordinates.

Optional flags can be specified to control the output format.

See also
formatX()

Definition at line 43 of file qgscoordinateformatter.cpp.

◆ separator()

QChar QgsCoordinateFormatter::separator ( )
static

Returns the character used as X/Y separator, this is a , on locales that do not use , as decimal separator, it is a space otherwise.

Since
QGIS 3.20

Definition at line 96 of file qgscoordinateformatter.cpp.

Friends And Related Symbol Documentation

◆ QgsCoordinateUtils

friend class QgsCoordinateUtils
friend

Definition at line 131 of file qgscoordinateformatter.h.


The documentation for this class was generated from the following files: