ST_OffsetCurve
Returns an offset curve at the specified distance from a line geometry. Use this function to compute parallel lines on either side of a center line—for example, generating road buffers or offset tracks.
Syntax
geometry ST_OffsetCurve(geometry line, float signedDistance, text styleParameters);Parameters
| Parameter | Type | Description |
|---|---|---|
line | geometry | The input line geometry. |
signedDistance | float | The offset distance. A positive value offsets to the left of the input line (in the same direction); a negative value offsets to the right (in the opposite direction). |
styleParameters | text | Style options for the offset curve. Defaults to an empty string. |
Usage notes
Points on the returned geometry are within the specified distance of the input geometry.
Ignores z coordinates. If the input is a 3D geometry, the output is a 2D geometry.
Supports
GeometryCollectionandMultiLineStringinputs.
styleParameters options
quad_segs=#— Number of segments used to approximate a quarter circle. Defaults to8. A higher value produces a smoother curve.join=round|mitre|bevel— Join style for offset lines. Defaults toround.mitre_limit=#.#— Miter ratio limit. Applies only whenjoin=mitre.
Examples
Effect of quad_segs on curve smoothness
All three calls use the same line LINESTRING(0 0,0 1,1 1) with quad_segs values of 2, 3, and the default (8):
SELECT
st_curvetoline(ST_OffsetCurve(g, 1, 'quad_segs=2')),
st_curvetoline(ST_OffsetCurve(g, 1.1, 'quad_segs=3')),
st_curvetoline(ST_OffsetCurve(g, 1.2))
FROM (SELECT 'LINESTRING(0 0,0 1,1 1)'::geometry AS g) AS t;
Effect of join style
Compares round, mitre, and bevel join styles on the same line:
SELECT
st_curvetoline(ST_OffsetCurve(g, 1, 'join=round')),
st_curvetoline(ST_OffsetCurve(g, 1.1, 'join=mitre')),
st_curvetoline(ST_OffsetCurve(g, 1.2, 'join=bevel')),
g
FROM (SELECT 'LINESTRING(0 0,0 1,1 1)'::geometry AS g) AS t;
Effect of mitre_limit
Controls how far a mitered join extends before it is clipped. Smaller values clip more aggressively:
SELECT
st_curvetoline(ST_OffsetCurve(g, 1, 'join=mitre mitre_limit=0.1')),
st_curvetoline(ST_OffsetCurve(g, 1.1, 'join=mitre mitre_limit=0.5')),
st_curvetoline(ST_OffsetCurve(g, 1.2, 'join=mitre mitre_limit=1')),
g
FROM (SELECT 'LINESTRING(0 0,0 1,1 1)'::geometry AS g) AS t;
Positive vs. negative signedDistance
A positive signedDistance offsets the curve to the left; a negative value offsets to the right. Both results are shown alongside the original line:
SELECT
st_curvetoline(ST_OffsetCurve(g, 2)),
st_curvetoline(ST_OffsetCurve(g, -2)),
g
FROM (SELECT 'LINESTRING(0 0,0 1,1 2)'::geometry AS g) AS t;