- 类别:
ST_ISVALID¶
如果指定的 GEOGRAPHY 或 GEOMETRY 对象表示 有效形状,则返回 TRUE。
语法¶
实参¶
geography_or_geometry_expression实参必须是 GEOGRAPHY 或 GEOMETRY 类型的表达式。
返回¶
返回 BOOLEAN。
使用说明¶
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.
示例¶
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: