ST_IsValid

更新时间:
复制 MD 格式

Checks whether a geometry object is in a valid format and returns details about any validity violations.

Syntax

boolean ST_IsValid(geometry g);
boolean ST_IsValid(geometry g, integer flags);

Parameters

ParameterDescription
gThe geometry object to validate.
flagsA bitfield that controls validity rules. Set to 1 to treat a self-intersection ring forming a hole as valid. This is the Environmental Systems Research Institute (ESRI) flag.

Description

When the input geometry object is invalid, ST_IsValid returns false and emits a NOTICE message describing the violation, such as the location of a self-intersection.

Examples

The following example checks a self-intersecting polygon. Because the polygon's edges cross each other, the geometry is invalid and the function returns f (false).

SELECT ST_IsValid('POLYGON((0 0,0 1,1 0,1 1,0 0))'::geometry);
NOTICE:  Self-intersection at or near point 0.5 0.5
 st_isvalid
------------
 f
(1 row)