PostGISGeometry Input

ST_LineFromEncodedPolyline

What is ST_LineFromEncodedPolyline?

ST_LineFromEncodedPolyline decodes a Google encoded-polyline string into a LINESTRING. The default precision is 5 (matching Google Directions API); use 6 for the higher-precision format used by Mapbox and OSRM.

SQL
ST_LineFromEncodedPolyline(text polyline, integer precision = 5)geometry

The output is always in EPSG:4326.

When would you use ST_LineFromEncodedPolyline?

Use ST_LineFromEncodedPolyline to ingest route geometries from routing APIs — Google Directions, Mapbox Directions, OSRM — that return encoded polylines rather than WKT or GeoJSON. The encoded format is 30–40% smaller than raw coordinates, making it the default for bandwidth-sensitive mobile and web apps.

It is the inverse of ST_AsEncodedPolyline and enables round-tripping between PostGIS and polyline-emitting APIs.

FAQs

What precision does Google use?

Precision 5 — five decimal places of latitude/longitude. Mapbox and OSRM use precision 6 by default; set the argument accordingly.

What SRID does the result have?

EPSG:4326. Google polylines are WGS84.

Is precision lost when encoding?

Yes. Encoded polylines quantise to 10^-precision degrees. Round-trip error is sub-metre at precision 5, sub-decimetre at precision 6.

Does it parse 3D polylines?

No. Google-encoded polylines are 2D only.