ST_IsValidDetail

更新时间:
复制 MD 格式

Checks whether a geometry object is valid and returns a structured row containing the validity status, the reason for invalidity, and the location of the invalid part. Use this function instead of calling ST_IsValid and ST_IsValidReason separately.

Syntax

validDetail ST_IsValidDetail(geometry geom);
validDetail ST_IsValidDetail(geometry geom, integer flags);

Parameters

ParameterDescription
geomThe geometry object to validate.
flagsA bitfield that controls validity semantics. If you specify this parameter to 1, the self-intersection ring forming a hole is considered to be valid. This is known as the Environmental Systems Research Institute (ESRI) flag.

Return value

The function returns a validDetail row with three fields:

FieldTypeDescription
validBooleantrue if the geometry is valid; false otherwise.
reasonvarcharThe reason for invalidity.
locationgeometryThe location of the invalid part of the geometry.

Examples

The following example checks an invalid polygon with a self-intersection. The function returns valid=f and identifies the intersection point.

SELECT (g).valid, (g).reason, st_astext((g).location)
FROM (
  SELECT ST_IsValidDetail('POLYGON((0 0,0 1,1 0,1 1,0 0))'::geometry) AS g
) AS t;

Output:

 valid |      reason       |   st_astext
-------+-------------------+----------------
 f     | Self-intersection | POINT(0.5 0.5)
(1 row)