ST_AsLatLonText

更新时间:
复制 MD 格式

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

Syntax

text ST_AsLatLonText(geometry pt, text format)

Parameters

ParameterDescription
ptThe point object to convert. The function assumes a latitude/longitude-based projection. The x coordinate maps to longitude and the y coordinate maps to latitude. Coordinates are normalized to valid ranges: latitude to −90 to +90, longitude to −180 to +180.
formatThe output format string. Default: null. Compose the format using the tokens in the table below. Any non-token character passes through to the output unchanged.

Format tokens

TokenMeaningNotes
DDegrees
MMinutesOptional. If omitted, degrees are output as a decimal string.
SSecondsOptional. If omitted, minutes are output as a decimal string.
CCardinal direction (N/S/E/W)Optional. If omitted, south and west coordinates use a negative sign instead of a direction letter.

Examples

Default format

SELECT ST_AsLatLonText(ST_GeomFromText('POINT(116 40)', 4326));
      st_aslatlontext
----------------------------
 40°0'0.000"N 116°0'0.000"E
(1 row)

Normalize out-of-range coordinates

Longitude 476 is outside the valid range and is normalized to 116 (476 − 360 = 116).

SELECT ST_AsLatLonText(ST_GeomFromText('POINT(476 40)', 4326));
      st_aslatlontext
----------------------------
 40°0'0.000"N 116°0'0.000"E
(1 row)

Custom format string

Non-token characters in the format string pass through unchanged.

SELECT ST_AsLatLonText(
  ST_GeomFromText('POINT(116 40)', 4326),
  'D degrees M minutes S.SS seconds (C)'
);
                   st_aslatlontext
--------------------------------------
 40 degrees 0 minutes 0.00 seconds (N) 116 degrees 0 minutes 0.00 seconds (E)
(1 row)

Omit C — signed degrees instead of cardinal direction

When C is omitted, south and west coordinates use a negative sign.

Omit S — minutes as a decimal string

When S is omitted, minutes are output as a decimal number.

Omit M — degrees as a decimal string

When both M and S are omitted, degrees are output as a decimal number.