Returns the degrees, minutes, and seconds (DMS) representation of a point's coordinates as text.
Syntax
text ST_AsLatLonText(geometry pt, text format)Parameters
| Parameter | Description |
|---|---|
pt | The 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. |
format | The 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
| Token | Meaning | Notes |
|---|---|---|
D | Degrees | — |
M | Minutes | Optional. If omitted, degrees are output as a decimal string. |
S | Seconds | Optional. If omitted, minutes are output as a decimal string. |
C | Cardinal 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.
该文章对您有帮助吗?