Skip to main content

ST_IsValid

Tests whether a geometry is valid according to OGC Simple Features rules.

Syntax

ST_IsValid(geometry)

Parameters

ParameterTypeDescription
geometryGeometryInput geometry to validate

Returns

TypeDescription
BooleanTrue if geometry is valid, false otherwise

Examples

Valid Polygon

SELECT ST_IsValid(ST_GeomFromText('POLYGON((0 0, 4 0, 4 4, 0 4, 0 0))'));
-- Returns: true

Self-Intersecting Polygon (Invalid)

SELECT ST_IsValid(ST_GeomFromText('POLYGON((0 0, 2 2, 2 0, 0 2, 0 0))'));
-- Returns: false (figure-8 shape)

Filter Valid Geometries

SELECT * FROM features
WHERE ST_IsValid(geom);

Find Invalid Geometries

SELECT id, ST_GeometryType(geom) as type
FROM parcels
WHERE NOT ST_IsValid(geom);

Notes

  • Points and LineStrings are always valid
  • Common invalidity causes for polygons:
    • Self-intersection (figure-8 or bowtie shapes)
    • Ring not closed
    • Holes outside shell
    • Nested holes
  • Use ST_SimplifyPreserveTopology to fix some invalid geometries

See Also