PostGISLinear Referencing

ST_AddMeasure

What is ST_AddMeasure?

ST_AddMeasure is a PostGIS function that adds interpolated M (measure) values to a linestring or multilinestring. M values are distributed linearly along the 2D length between a given start and end measure.

SQL
ST_AddMeasure(geometry geom_mline, float measure_start, float measure_end)geometry

When would you use ST_AddMeasure?

Use ST_AddMeasure to convert a plain 2D route into a measure-parameterised one so that the full linear-referencing family (ST_LocateAlong, ST_LocateBetween, ST_InterpolatePoint) becomes usable. Typical example: labelling a highway's geometry with chainage in metres, or stamping a river alignment with river-mile values.

SQL
1UPDATE roads
2SET geom = ST_AddMeasure(geom, 0, ST_Length(geom));

FAQs

Does ST_AddMeasure use 2D or 3D length?

It interpolates based on 2D length along the line. If you need 3D-aware measures, you must compute them manually or use a custom interpolation that accounts for Z delta.

What happens if the input already has M?

The existing M values are overwritten. Any vertices that previously carried M will be replaced by the newly interpolated values.

Can ST_AddMeasure handle MultiLineStrings?

Yes — the start and end measures span the entire multilinestring in order, with intermediate parts receiving linearly interpolated measures. Measures do not reset per part; they flow continuously through the multi-parts.

Why would I want a reversed measure range?

For routes that are digitised in the opposite direction of their stationing — for example, a road drawn from south to north but where kilometer 0 is at the north end. In those cases, pass measure_start greater than measure_end to produce decreasing M along the geometry.