Was this page helpful?
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

MakeValid (geometry Data Type)


Applies To: SQL Server 2014, SQL Server 2016 Preview

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

Applies to: SQL Server (SQL Server 2012 through current version), Azure SQL Database.

.MakeValid ()

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.

SELECT @g.ToString();

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))

The following example converts the CircularString instance into a Point instance.

DECLARE @g geometry = 'CIRCULARSTRING(1 1, 1 1, 1 1)';
SELECT @g.MakeValid().ToString();
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2015 Microsoft