This topic describes the ST_AsLatLonText function. This function returns the degrees, minutes, and seconds that represent the coordinates of a point object.

Syntax

text  ST_AsLatLonText(geometry  pt , text  format);

Parameters

Parameter Description
pt The point object whose degree, minute, and second representation you want to obtain.
format The format in which the degrees, minutes, and seconds are returned. Default value: null. Valid tokens are D, M, S, and C. D represents the degrees, M represents the minutes, S represents the seconds, and C represents the cardinal direction. The cardinal direction can be north, south, east, or west.

Description

  • This function assumes that the point object is in a projection that is based on latitude and longitude coordinates. The x coordinate (longitude) and the y coordinate (latitude) are normalized in the return result by using the following normal ranges: the longitude ranges from -90 to +90, and the latitude ranges from -180 to +180.
  • Tokens M, S, and C are optional.
    • If you do not specify C, the degrees are displayed as a hyphen (-) when the cardinal direction is south or west.
    • If you do not specify S, the minutes are displayed as a decimal string that consists of as many decimal places as you specify.
    • If you do not specify M, the degrees are displayed as a decimal string that consists of as many decimal places as you specify.

Examples

  • Retain the default parameter settings.
    SELECT ST_AsLatLonText(ST_GeomFromText('POINT(116 40)',4326));
          st_aslatlontext
    ----------------------------
     40°0'0.000"N 116°0'0.000"E
    (1 row)
                        
  • Generalize the latitude and the longitude.
    SELECT ST_AsLatLonText(ST_GeomFromText('POINT(476 40)',4326));
          st_aslatlontext
    ----------------------------
     40°0'0.000"N 116°0'0.000"E
    (1 row)
  • Specify the format parameter.
    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)