QGIS API Documentation  3.6.0-Noosa (5873452)
Public Types | Static Public Member Functions | 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...
 

Static Public Member Functions

static QString asPair (double x, double y, int precision=12)
 Formats coordinates as an "\a x,\a y" pair, with optional decimal precision (number of decimal places to include). More...
 
static QString format (const QgsPointXY &point, Format format, int precision=12, FormatFlags flags=FlagDegreesUseStringSuffix)
 Formats a point according to the specified parameters. More...
 
static QString formatX (double x, Format format, int precision=12, FormatFlags flags=FlagDegreesUseStringSuffix)
 Formats an x coordinate value according to the specified parameters. More...
 
static QString formatY (double y, Format format, int precision=12, FormatFlags flags=FlagDegreesUseStringSuffix)
 Formats a y coordinate value according to the specified parameters. More...
 

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.

Since
QGIS 3.0

Definition at line 40 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 47 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 58 of file qgscoordinateformatter.h.

Member Function Documentation

◆ asPair()

QString QgsCoordinateFormatter::asPair ( double  x,
double  y,
int  precision = 12 
)
static

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

Definition at line 67 of file qgscoordinateformatter.cpp.

◆ format()

QString QgsCoordinateFormatter::format ( const QgsPointXY point,
QgsCoordinateFormatter::Format  format,
int  precision = 12,
FormatFlags  flags = FlagDegreesUseStringSuffix 
)
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.

Definition at line 61 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 23 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 42 of file qgscoordinateformatter.cpp.


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