ST_GeographyFromText

更新时间:
复制 MD 格式

Constructs a geography object from a Well-Known Text (WKT) or Extended Well-Known Text (EWKT) string.

Syntax

geography ST_GeographyFromText(text eWKT)

Parameters

ParameterDescription
eWKTA standard WKT string or an EWKT string.

Usage notes

  • If the input string does not include a spatial reference identifier (SRID), the function uses the default SRID 4326 (WGS 84, the standard longitude/latitude coordinate system).

  • Specify coordinates in longitude, latitude order. Longitude maps to the x-axis and latitude to the y-axis, so longitude comes first.

Examples

Use the default SRID 4326

Omit the SRID prefix to use the WGS 84 default:

SELECT ST_SRID(ST_GeographyFromText('POINT(116 40)'));
 st_srid
---------
    4326
(1 row)

Specify a custom SRID

Prefix the WKT string with SRID=<value>; to override the default:

SELECT ST_SRID(ST_GeographyFromText('SRID=4256;POINT(116 40)'));
 st_srid
---------
    4256
(1 row)

Store coordinates from an existing table as a geography column

A common pattern is to build a geography column from separate longitude and latitude columns:

ALTER TABLE locations ADD COLUMN geog geography(POINT, 4326);

UPDATE locations
SET geog = ST_GeographyFromText('SRID=4326;POINT(' || lon || ' ' || lat || ')');