Skip to content
🎉 Apache Sedona 1.8.1 is now available! Check out the new features and improvements.

ST_IsValidReason

Introduction: Returns text stating if the geometry is valid. If not, it provides a reason why it is invalid. The function can be invoked with just the geometry or with an additional flag. The flag alters the validity checking behavior. The flags parameter is a bitfield with the following options:

  • 0 (default): Use usual OGC SFS (Simple Features Specification) validity semantics.
  • 1: "ESRI flag", Accepts certain self-touching rings as valid, which are considered invalid under OGC standards.

Formats:

ST_IsValidReason (A: Geometry)
ST_IsValidReason (A: Geometry, flag: Integer)

SQL Example for valid geometry:

SELECT ST_IsValidReason(ST_GeomFromWKT('POLYGON ((100 100, 100 300, 300 300, 300 100, 100 100))')) as validity_info

Output:

Valid Geometry

SQL Example for invalid geometries:

SELECT gid, ST_IsValidReason(geom) as validity_info
FROM Geometry_table
WHERE ST_IsValid(geom) = false
ORDER BY gid

Output:

gid  |                  validity_info
-----+----------------------------------------------------
5330 | Self-intersection at or near point (32.0, 5.0, NaN)
5340 | Self-intersection at or near point (42.0, 5.0, NaN)
5350 | Self-intersection at or near point (52.0, 5.0, NaN)