Skip to content

Latest commit

 

History

History
79 lines (59 loc) · 2.36 KB

makevalid-geometry-data-type.md

File metadata and controls

79 lines (59 loc) · 2.36 KB
title description author ms.author ms.date ms.service ms.subservice ms.topic ms.custom f1_keywords helpviewer_keywords dev_langs
MakeValid (geometry Data Type)
MakeValid (geometry Data Type)
MladjoA
mlandzic
08/03/2017
sql
t-sql
reference
ignite-2024
MakeValid
MakeValid_TSQL
MakeValid (geometry Data Type)
TSQL

MakeValid (geometry Data Type)

[!INCLUDE SQL Server Azure SQL Database Azure SQL Managed Instance FabricSQLDB]

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

Syntax

  
.MakeValid ()  

Return Types

[!INCLUDEssNoVersion] return type: geometry

CLR return type: SqlGeometry

Remarks

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.

Examples

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

See Also

STIsValid (geometry Data Type)
Extended Methods on Geometry Instances