PostGISGeometry Accessors

ST_EndPoint

What is ST_EndPoint?

ST_EndPoint is a PostGIS function that returns the last point of a LINESTRING (or CIRCULARSTRING) as a POINT geometry. For non-line input, it returns NULL in standard PostGIS; some newer versions also handle MULTILINESTRING when it contains a single component.

SQL
ST_EndPoint(geometry line)geometry

SRID and dimensionality (Z, M) are preserved.

When would you use ST_EndPoint?

Use ST_EndPoint to grab the terminal vertex of a line for joining, snapping, or connectivity analysis — classic patterns include matching trip ends to destinations, snapping route endpoints to network nodes, or computing origin/destination pairs:

SQL
1SELECT id,
2       ST_StartPoint(route_geom) AS origin,
3       ST_EndPoint(route_geom)   AS destination
4FROM trips;

Pair with ST_StartPoint for O/D analysis, or with ST_ClosestPoint to find which network node the endpoint should snap to.

FAQs

What does ST_EndPoint return for a MultiLineString?

In most PostGIS versions, NULL. Use ST_GeometryN(mls, ST_NumGeometries(mls)) to fetch the last component and call ST_EndPoint on that, or flatten with ST_LineMerge if the components are contiguous.

Does ST_EndPoint preserve Z and M?

Yes. The returned point has the same dimensionality as the source line's last vertex.

What is ST_EndPoint for a closed line?

Numerically equal to ST_StartPoint — a closed ring's last point matches its first by definition.

Why is ST_EndPoint returning NULL on my data?

Most often because the input is a MULTILINESTRING or a non-line type. Check with GeometryType(geom) and either filter to LINESTRING rows or unpack the multi geometry first.