CG_NurbsCurveApproximate — Creates an approximating NURBS curve fitting data points within a tolerance
geometry CG_NurbsCurveApproximate(geometry data_points, integer degree, float8 tolerance, integer max_control_points=100);
Creates a NURBS curve that approximates the given data points within the specified tolerance. Unlike interpolation, the curve does not necessarily pass through all points but provides a smooth fit with fewer control points.
Parameters:
data_points - A LINESTRING geometry containing the points to approximate.
degree - Polynomial degree of the NURBS curve.
tolerance - Maximum allowed distance between the curve and data points.
max_control_points - Optional maximum number of control points (default: 100). Limits curve complexity.
Availability: 3.7.0 - requires SFCGAL >= 2.3.0.
This method needs SFCGAL backend.
This function supports 3d and will not drop the z-index.
-- Approximate noisy data with tolerance
SELECT CG_NurbsCurveApproximate(
'LINESTRING(0 0, 1 2.1, 2 1.9, 3 3.2, 4 2.8, 5 1)'::geometry,
2,
0.5
);
-- Control maximum complexity
SELECT CG_NurbsCurveApproximate(
'LINESTRING(0 0, 1 2, 2 2, 3 3, 4 3, 5 1, 6 0, 7 -1, 8 0)'::geometry,
3,
0.2,
20 -- max 20 control points
);