ST_InterpolatePoint
What is ST_InterpolatePoint?
ST_InterpolatePoint is a PostGIS function that returns the interpolated M (measure) value of a point when projected onto a measure-parameterised linestring. The result is a float equal to the linear interpolation of M at the projected location.
ST_InterpolatePoint(geometry line_with_measure, geometry point) → floatWhen would you use ST_InterpolatePoint?
Use ST_InterpolatePoint to map an arbitrary observation to a route's measure system — for example, converting a GPS observation to its equivalent chainage on a highway, computing the river mile of an incident, or identifying the pipeline offset at which a leak was detected.
1SELECT event.id,
2 ST_InterpolatePoint(road.geom, event.geom) AS chainage
3FROM roads road, incidents event
4WHERE road.id = event.road_id;FAQs
Does the input line need M values?
Yes. The linestring must be M-parameterised (e.g. LINESTRING M or LINESTRING ZM). Otherwise the function has nothing to interpolate. Add measures with ST_AddMeasure if your line is 2D.
What if the point is not exactly on the line?
PostGIS projects the point to its nearest location on the line and returns the M at that projected location. This is the expected behaviour for real-world GPS data that is rarely exactly on a digitised route.
How is it different from ST_LineLocatePoint?
ST_LineLocatePoint returns a fraction of total length (0 to 1). ST_InterpolatePoint returns the actual M value stored in the geometry. If your line has chainage in metres, ST_InterpolatePoint returns metres directly.
Does the point input need to be 2D?
The point's XY is used for projection. Z and M values on the input point are ignored. The output M comes from the line, not the point.