All Products
Search
Document Center

PolarDB:ST_LineFromEncodedPolyline

Last Updated:Mar 28, 2026

ST_LineFromEncodedPolyline constructs a LineString geometry from an encoded polyline string. The encoding format is the Encoded Polyline Algorithm Format used by Google Maps and other routing services.

Syntax

geometry ST_LineFromEncodedPolyline(text polyline, integer precision);

Parameters

ParameterTypeDescription
polylinetextThe encoded polyline string to decode.
precisionintegerThe number of decimal places used during encoding. The precision used for encoding and decoding must match; a mismatch produces incorrect coordinates.

Examples

Decode an encoded polyline

The following example decodes an encoded polyline string into a LineString geometry.

SELECT ST_AsText(ST_LineFromEncodedPolyline('_gvzE_ol{U_glW_c`|@_}hQ~flW'));

Output:

            st_astext
----------------------------------
 LINESTRING(120 36,130 40,126 43)
(1 row)
Important

The precision used for encoding and decoding must be identical. Using the wrong precision returns incorrect coordinates without raising an error.

Usage notes

  • The encoding format is the Encoded Polyline Algorithm Format. For details, see Encoded Polyline Algorithm Format.

  • The precision of encoding and the precision of decoding must be the same. Otherwise, coordinates are inaccurate.