ST_IsValidDetail

更新时间:
复制 MD 格式

Returns a valid_detail row describing whether a geometry is valid. For invalid geometries, the row includes the reason for invalidity and the location of the invalid element.

Syntax

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

Parameters

ParameterDescription
geomThe geometry to validate.
flagsA flag value 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) validation flag.

Return value

Returns a valid_detail composite row with the following fields:

FieldTypeDescription
validBooleanIndicates whether the geometry is valid.
reasonvarcharThe reason the geometry is invalid.
locationgeometryThe location of the invalid element.

Description

ST_IsValidDetail replaces the combined use of ST_IsValid and ST_IsValidReason by returning all validity information — the validity status, the reason, and the exact location — in a single row.

Examples

The following example checks whether a self-intersecting polygon is valid. The polygon POLYGON((0 0,0 1,1 0,1 1,0 0)) forms a bowtie shape that crosses itself at POINT(0.5 0.5).

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)

The valid field returns f (false), confirming the geometry is invalid. The reason field identifies the problem as a self-intersection, and the location field pinpoints where the intersection occurs.