ST_PointM
What is ST_PointM?
ST_PointM is a PostGIS function (added in 3.2) that constructs a POINT M — a 2D point with a measure coordinate — and takes the SRID as an explicit argument. It is the modern equivalent of ST_SetSRID(ST_MakePointM(x, y, m), srid).
ST_PointM(float x, float y, float m, integer srid) → geometryThe measure value is typically used for linear referencing — distance along a route, time, chainage, or any scalar attached to a vertex.
When would you use ST_PointM?
Use ST_PointM when building measured points for linear-referencing workflows along roads, pipelines, or rail — for example when inserting milestones whose M value represents kilometre post:
1INSERT INTO pipeline_markers (pipeline_id, geom)
2SELECT pipeline_id,
3 ST_PointM(lon, lat, chainage_km, 4326)
4FROM staging_markers;M is preserved through most PostGIS operations and can be read back with ST_M(point). Use together with ST_LocateAlong, ST_AddMeasure, and other linear referencing functions.
FAQs
How does ST_PointM differ from ST_PointZ?
ST_PointM assigns the third coordinate the semantic of measure (M); ST_PointZ assigns it elevation (Z). The WKT output differs (POINT M (...) vs POINT Z (...)) and downstream functions treat them differently — always match the semantic of your data.
Do spatial predicates use M?
No. M is carried through as metadata but does not influence standard 2D predicates like ST_Intersects or ST_DWithin. Access M explicitly via ST_M(point) for calculations.
When should I use ST_PointM versus ST_MakePointM?
Both produce the same geometry structurally. ST_PointM accepts the SRID inline (cleaner), while ST_MakePointM requires an ST_SetSRID wrapper. Prefer ST_PointM on PostGIS 3.2+.
Can I have both Z and M?
Yes — use ST_PointZM(x, y, z, m, srid) to construct a point with both dimensions.