ST_ShiftLongitude

更新时间:
复制 MD 格式

Shifts the longitude coordinates of a geometry between the -180..180 and 0..360 ranges. The conversion is symmetric: coordinates in -180..0 shift to 180..360, and coordinates in 180..360 shift to -180..0.

Syntax

geometry ST_ShiftLongitude(geometry geomA)

Parameters

ParameterDescription
geomAThe input geometry object.

Description

ST_ShiftLongitude reads every vertex in the input geometry and shifts its longitude coordinate based on its current range:

  • Longitude in -180..0 shifts to 180..360

  • Longitude in 180..360 shifts to -180..0

This function only works with geometries in a longitude/latitude coordinate system, such as World Geodetic System 1984 (WGS 84), SRID 4326.
  • Preserves z-coordinates — 3D geometries are supported without any loss of elevation data.

  • Supports polyhedral surfaces, triangles, and triangulated irregular network (TIN) surfaces.

Examples

Forward transformation: 0..360 to -180..0

SELECT ST_AsText(ST_ShiftLongitude('SRID=4326;POINT(270 0)'::geometry));
POINT(-90 0)

Reverse transformation: -180..0 to 0..360

SELECT ST_AsText(ST_ShiftLongitude('SRID=4326;POINT(-90 0)'::geometry));
POINT(270 0)

LineString with mixed coordinates

SELECT ST_AsText(ST_ShiftLongitude('SRID=4326;LINESTRING(174 12, 182 13)'::geometry));
LINESTRING(174 12,-178 13)

Basic example

SELECT ST_AsText(ST_ShiftLongitude('POINT(181 30)'));
POINT(-179 30)