- Categories:
ST_ISVALID¶
Returns TRUE if the specified GEOGRAPHY or GEOMETRY object represents a valid shape. Examples of invalid shapes include shapes with self-intersections and spikes.
Syntax¶
Arguments¶
geography_or_geometry_expressionThe argument must be an expression of type GEOGRAPHY or GEOMETRY.
Returns¶
Returns a BOOLEAN value.
Usage notes¶
ST_ISVALID only checks for the validity of a shape. It doesn’t modify data. When constructing objects from spatial formats (such as WKT, WKB, EWKT, EWKB, or GeoJSON), conversion functions (for example, TO_GEOGRAPHY, TO_GEOMETRY, ST_GEOGRAPHYFROMWKT, or ST_GEOMETRYFROMWKT) parse input and by default attempt to validate or repair shapes. If a conversion function can’t repair a shape, it returns an error unless you accept invalid shapes.
To ingest data that might be invalid (for example, data that you plan to correct later), specify TRUE for the additional
allow_invalidargument when you call the conversion function to allow an invalid shape. You can then use the ST_ISVALID function to flag invalid rows in a table.Some geospatial functions might return an error or unusable results when given invalid shapes. Use the ST_ISVALID function to check validity. You can correct invalid shapes before performing spatial analytics.
When shapes are invalid, simple corrections include buffering with a small positive or negative distance (for example, to remove tiny spikes or resolve self-intersections) and then rechecking validity using the ST_ISVALID function.
Examples¶
The following examples use the ST_ISVALID function.
Determine whether a polygon is a valid shape:
Correct an invalid shape by using the ST_BUFFER function to add small buffer: