geometry.MakeValid
spatial method MakeValid (instance.MakeValid(...))
What changes
- Input
- spatial instance (and arguments)
- Output or change
- geometry
- Return type
- SQL Server return type: geometry CLR return type: SqlGeometry
Syntax at a glance
.MakeValid ()
Work example
Use geometry.MakeValid to repair an invalid spatial value before a topology operation.
Compare the repaired output with the source because repair can split or change its type. Keep the geometry type and SRID in the review.
Check your work MakeValid produces a valid shape. Its type and point arrangement can change.
Practice SQL
Open in SQL FlowOpen the SQL for a walkthrough. Run the example in SQL Server to check its result.
-- Planar geometry. SRID 0 coordinates here are synthetic units, not metres.
DECLARE @invalid geometry;
SET @invalid = geometry::STGeomFromText(N'POLYGON((0 0, 4 4, 0 4, 4 0, 0 0))', 0);
DECLARE @repaired geometry;
SET @repaired = @invalid.MakeValid();
SELECT @invalid.STIsValid() AS source_is_valid,
@repaired.STIsValid() AS repaired_is_valid,
@repaired.STGeometryType() AS repaired_type,
@repaired.STAsText() AS repaired_shape;
Open Microsoft Learn for full syntax, permissions, and details for your version.