ST_IsValidReason

更新时间:
复制 MD 格式

Returns a text description of whether a geometry object is valid. If the geometry is invalid, the description states the reason.

Syntax

boolean ST_IsValidReason(geometry geomA);
boolean ST_IsValidReason(geometry geomA, integer flags);

Parameters

ParameterDescription
geomAThe geometry object to validate.
flagsAn integer bitfield that controls validation behavior. Set to 1 to treat self-intersecting rings that form holes as valid. This is the Environmental Systems Research Institute (ESRI) standard.

Description

ST_IsValidReason returns a text string describing the validity of a geometry object. For invalid geometries, it returns the reason of the first validity problem detected.

Use ST_IsValidReason together with ST_IsValid to generate detailed validity reports — ST_IsValid identifies whether a geometry is invalid, and ST_IsValidReason explains why.

Examples

The following example checks a self-intersecting polygon. The polygon (0 0, 0 1, 1 0, 1 1, 0 0) forms a bowtie shape where the edges cross at point (0.5, 0.5).

SELECT ST_IsValidReason('POLYGON((0 0,0 1,1 0,1 1,0 0))'::geometry);

Output:

      st_isvalidreason
----------------------------
 Self-intersection[0.5 0.5]
(1 row)