ST_AsLatLonText

更新时间:
复制 MD 格式

Returns the degrees, minutes, and seconds (DMS) representation of a point's coordinates as a text string.

Syntax

text ST_AsLatLonText(geometry pt, text format)

Parameters

ParameterDescription
ptThe point object whose coordinates to convert. The function assumes the point uses a latitude/longitude-based projection.
formatThe format string for the output. Default value: null. Use the tokens D, M, S, and C to control the output format. D represents degrees, M represents minutes, S represents seconds, and C represents the cardinal direction (north, south, east, or west). Tokens M, S, and C are optional.

Usage notes

  • The x coordinate corresponds to longitude, and the y coordinate corresponds to latitude. Coordinates are normalized to the following ranges before output: latitude from -90 to +90, and longitude from -180 to +180.

  • If C is omitted, a hyphen (-) is used to indicate south or west directions instead of a cardinal letter.

  • If S is omitted, minutes are expressed as a decimal string with as many decimal places as specified.

  • If M is omitted, degrees are expressed as a decimal string with as many decimal places as specified.

Examples

Use the default format

SELECT ST_AsLatLonText(ST_GeomFromText('POINT(116 40)',4326));

Output:

      st_aslatlontext
----------------------------
 40°0'0.000"N 116°0'0.000"E
(1 row)

Use out-of-range coordinates (normalization)

Coordinates outside the normal range are normalized. In this example, longitude 476 normalizes to 116, producing the same result as the previous example.

SELECT ST_AsLatLonText(ST_GeomFromText('POINT(476 40)',4326));

Output:

      st_aslatlontext
----------------------------
 40°0'0.000"N 116°0'0.000"E
(1 row)

Specify a custom format string

SELECT ST_AsLatLonText(ST_GeomFromText('POINT(116 40)',4326),'D degrees M minutes S.SS seconds (C)');

Output:

               st_aslatlontext
--------------------------------------
 40 degrees 0 minutes 0.00 seconds (N) 116 degrees 0 minutes 0.00 seconds (E)
(1 row)