MakeValid (geometry)

MakeValid (geometry)#

Converts an invalid geometry instance into a geometry instance with a valid Open Geospatial Consortium (OGC) type.


.MakeValid ()

Return type#



This method may cause a change in the type of the geometry instance, as well as cause the points of a geometry instance to shift slightly.


Create an invalid LineString instance that overlaps itself and uses STIsValid() to confirm that it is an invalid instance. STIsValid() returns the value of 0 for an invalid instance.

DECLARE @g geometry;
SET @g = geometry::STGeomFromText('LINESTRING(0 2, 1 1, 1 0, 1 1, 2 2)', 0);
SELECT @g.STIsValid();

Use MakeValid() to make the instance valid and to test that the instance is indeed valid. STIsValid() returns the value of 1 for a valid instance.

SET @g = @g.MakeValid();
SELECT @g.STIsValid();

Verify how the instance has been changed to make it a valid instance.

SELECT @g.ToString();

-- returns a valid MULTILINESTRING ((0 2, 1 1, 2 2), (1 1, 1 0))

Convert the CircularString instance into a Point instance.

DECLARE @g geometry = 'CIRCULARSTRING(1 1, 1 1, 1 1)';
SELECT @g.MakeValid().ToString();

See Also#