ST_OffsetCurve

更新时间:
复制 MD 格式

Returns an offset curve at a given distance from an input line geometry. Useful for computing parallel lines about a center line, such as road corridors and river buffers.

Syntax

geometry ST_OffsetCurve(geometry line, float signedDistance, text styleParameters)

Parameters

ParameterTypeDescription
linegeometryThe input line geometry.
signedDistancefloatThe offset distance, measured in the units of the spatial reference system (SRS) of the input geometry. A positive value offsets to the left; a negative value offsets to the right.
styleParameterstextStyle options for the offset curve. Defaults to an empty string. See Style parameters for details.

Usage notes

  • All points on the returned geometry are within the specified distance from the input geometry.

  • A positive signedDistance places the offset curve on the left side of the input geometry, in the same direction. A negative value places it on the right side, in the opposite direction.

  • Z coordinates are ignored. If the input is a 3D geometry object, the function returns a 2D geometry object.

  • Accepts GeometryCollection and MultiLineString as input.

Style parameters

Pass style options as a space-separated string in styleParameters, for example: 'quad_segs=4 join=round'.

FieldTypeDefaultDescription
quad_segsinteger8Number of segments used to approximate a quarter circle. A higher value produces a smoother curve.
joinstringroundJoin style for the offset curve. Valid values: round, mitre, bevel.
mitre_limitfloatMitre limit for the join. Applies only when join is set to mitre.

Examples

Effect of quad_segs

Compares offset curves generated 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;
1

Effect of join style

Compares round, mitre, and bevel join styles:

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;
2

Effect of mitre_limit

Compares mitre_limit values of 0.1, 0.5, and 1 with join=mitre:

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;
3

Positive vs. negative signed distance

Compares left-side (positive) and right-side (negative) offsets:

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;
4