Functions / PostGIS / ST_Angle
PostGISMeasurement

ST_Angle

What is ST_Angle?

ST_Angle returns the clockwise angle between two vectors. You can define the vectors either by three points (P1 → P2 and P2 → P3) or by two line segments (L1 and L2, each taken as the vector from its start to end point). The result is in radians in the range [0, 2π).

SQL
1ST_Angle(geometry point1, geometry point2, geometry point3, geometry point4)float
2ST_Angle(geometry point1, geometry point2, geometry point3)float
3ST_Angle(geometry line1, geometry line2)float

The three-point form is equivalent to ST_Angle(point1, point2, point2, point3) — the angle at point2 looking from point1 to point3. The two-line form computes the angle between the directions of the two line segments.

When would you use ST_Angle?

Use ST_Angle to measure the turn at a vertex — for example, the angle between consecutive road segments at an intersection, or the interior angle of a polygon corner. It is also useful for classifying junctions (sharp turns vs. straight-throughs) in routable road networks, for validating that architectural footprints are orthogonal, or for computing the angle between wind and a fence line in a microclimate model.

SQL
1-- Interior angle at the middle vertex of a polyline's three first points
2SELECT degrees(ST_Angle(
3  ST_PointN(geom, 1),
4  ST_PointN(geom, 2),
5  ST_PointN(geom, 3)
6)) AS corner_angle
7FROM polylines;

FAQs

What units is the result in?

Radians, in the range [0, 2π). Wrap with PostgreSQL's degrees() to convert to degrees.

Does ST_Angle work on geography?

No. ST_Angle operates on geometry only. Reproject to a suitable planar CRS if your data is in lat/lon and you need local angle measurements.

What is the difference between the three-point and four-point forms?

The three-point form treats point2 as the vertex, measuring the angle from the vector P1→P2 to the vector P2→P3. The four-point form measures the angle between two independent vectors P1→P2 and P3→P4 that need not share a vertex.

Is the angle signed?

ST_Angle always returns a positive value in [0, 2π) measured clockwise. If you need a signed or directed angle (e.g. "left turn vs. right turn"), compute both ST_Angle(a,b,c) and ST_Angle(c,b,a) or derive the sign from a cross-product of the two vectors.