MakeValid (geometry Data Type)
Converts an invalid geometry instance into a geometry instance with a valid Open Geospatial Consortium (OGC) type.
SQL Server return type: geometry
CLR return type: SqlGeometry
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.
The first example creates 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();
The second example uses 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();
The third example verifies how the instance has been changed to make it a valid instance.
In this example, when the LineString instance is selected, the values are returned as a valid MultiLineString instance.
MULTILINESTRING ((0 2, 1 1, 2 2), (1 1, 1 0))