ST_LocateAlong
What is ST_LocateAlong?
ST_LocateAlong is a PostGIS function that returns the point or multipoint on a measure-parameterised (M-valued) geometry where a given measure value occurs. An optional offset displaces the result perpendicular to the line.
ST_LocateAlong(geometry ageom_with_measure, float a_measure, float offset = 0) → geometryIt operates on geometries with M coordinates — typically LINESTRING M or MULTILINESTRING M.
When would you use ST_LocateAlong?
Use ST_LocateAlong for classical linear referencing — finding the point at kilometer 12.5 on a highway, placing a mile marker at measure 10000, or locating the river station at a given hydrographic mileage. The measure values in your linestring carry the semantics (kilometers, miles, chainage) and this function returns the geometry at that measure.
1SELECT ST_LocateAlong(geom, 12500) AS km_12_5
2FROM roads
3WHERE name = 'A1';FAQs
What exactly is the M coordinate?
M stands for "measure" — a fourth per-vertex value independent of X, Y, Z that can encode any scalar (distance, time, chainage). M is stored in LINESTRING M or LINESTRING ZM types, and PostGIS interpolates it linearly between vertices.
What if the measure occurs more than once?
ST_LocateAlong returns a MULTIPOINT containing every location where the measure is reached. For a non-monotonic measure (unusual, but allowed), this can produce multiple points.
What does the offset parameter do?
It displaces each result perpendicular to the line by a fixed distance — positive offsets go to the left of the line direction, negative to the right. Useful for placing mile markers beside the road instead of directly on it.
Does the input have to carry M?
Yes — ST_LocateAlong is meaningless without M values. If your linestring is XY only, first add measures with ST_AddMeasure(geom, start_measure, end_measure).