Reduce (geometry Data Type)

Returns an approximation of the given geometry instance produced by running the Douglas-Peucker algorithm on the instance with the given tolerance.

Syntax

.Reduce ( tolerance )

Arguments

  • tolerance
    Is a value of type float. tolerance is the tolerance to input to the Douglas-Peucker algorithm.

Return Types

SQL Server return type: geometry

CLR return type: SqlGeometry

Remarks

For collection types, this algorithm operates independently on each geometry contained in the instance.

This algorithm does not modify Point instances.

On LineString instances, the Douglas-Peucker algorithm retains the original start and end points of the instance, and the algorithm iteratively adds back the point from the original instance that most deviates from the result until no point deviates more than the given tolerance.

Warning

The Douglas-Peucker algorithm may result in an invalid LineString instance, but the Reduce method will call the MakeValid method internally on the resulting instance. This may result in the removal of the original start and end points from the resulting instance. For an example, see Showing an example where the original start and end points are lost.

On Polygon instances, the Douglas-Peucker algorithm is applied independently to each ring. The method will produce a FormatException if the returned Polygon instance is not valid; for example, an invalid MultiPolygon instance is created if Reduce() is applied to simplify each ring in the instance and the resulting rings overlap.

Examples

Simplifying a LineString instance with Reduce()

The following example creates a LineString instance and uses Reduce() to simplify the instance.

DECLARE @g geometry;
SET @g = geometry::STGeomFromText('LINESTRING(0 0, 0 1, 1 0, 2 1, 3 0, 4 1)', 0);
SELECT @g.Reduce(.75).ToString();

Showing an example where the original start and end points are lost

The following example shows how the original start and endpoints may not be retained by the resulting intstance. This occurs because retaining the original start and end points would result in an invalid LineString instance.

DECLARE @g geometry = 'LINESTRING(0 0, 4 0, 2 .01, 1 0)';DECLARE @h geometry = @g.Reduce(1);SELECT @g.STIsValid() AS ValidSELECT @g.ToString() AS Original, @h.ToString() AS Reduced;

See Also

Other Resources