Class: QgsCoordinateFormatter

class qgis.core.QgsCoordinateFormatter

Bases: sip.wrapper

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.

New in version 3.0:

Methods

asPair

Formats coordinates as an “x,``y``” pair, with optional decimal precision (number of decimal places to include).

format

Formats a point according to the specified parameters.

formatX

Formats an x coordinate value according to the specified parameters.

formatY

Formats a y coordinate value according to the specified parameters.

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.

Attributes

FlagDegreesPadMinutesSeconds

FlagDegreesUseStringSuffix

FormatDecimalDegrees

FormatDegreesMinutes

FormatDegreesMinutesSeconds

FormatPair

FlagDegreesPadMinutesSeconds = 4
FlagDegreesUseStringSuffix = 2
class Format

Bases: int

FormatDecimalDegrees = 3
FormatDegreesMinutes = 2
FormatDegreesMinutesSeconds = 1
class FormatFlag

Bases: int

class FormatFlags
class FormatFlags(Union[QgsCoordinateFormatter.FormatFlags, QgsCoordinateFormatter.FormatFlag]) None
class FormatFlags(QgsCoordinateFormatter.FormatFlags) None

Bases: sip.wrapper

FormatPair = 0
asPair(x: float, y: float, precision: int = 12) str

Formats coordinates as an “x,``y``” pair, with optional decimal precision (number of decimal places to include).

Parameters
  • x (float) –

  • y (float) –

  • precision (int = 12) –

Return type

str

format(point: QgsPointXY, format: QgsCoordinateFormatter.Format, precision: int = 12, flags: Union[QgsCoordinateFormatter.FormatFlags, QgsCoordinateFormatter.FormatFlag] = QgsCoordinateFormatter.FlagDegreesUseStringSuffix) str

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.

Parameters
Return type

str

formatX(x: float, format: QgsCoordinateFormatter.Format, precision: int = 12, flags: Union[QgsCoordinateFormatter.FormatFlags, QgsCoordinateFormatter.FormatFlag] = QgsCoordinateFormatter.FlagDegreesUseStringSuffix) str

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()

Parameters
Return type

str

formatY(y: float, format: QgsCoordinateFormatter.Format, precision: int = 12, flags: Union[QgsCoordinateFormatter.FormatFlags, QgsCoordinateFormatter.FormatFlag] = QgsCoordinateFormatter.FlagDegreesUseStringSuffix) str

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()

Parameters
Return type

str

separator() str

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.

New in version 3.20.

Return type

str