对于几何值,MySQL 区分语法上良构和几何上有效的概念。For geometry values, MySQL distinguishes between the concepts of syntactically well-formed and geometrically valid.
如果几何对象满足如本(非详尽)列表中的条件,则它在语法上是良构的:A geometry is syntactically well-formed if it satisfies conditions such as those in this (nonexhaustive) list:
线串至少有两个点Linestrings have at least two points
多边形至少有一个环Polygons have at least one ring
多边形环是闭合的(第一个和最后一个点相同)Polygon rings are closed (first and last points the same)
多边形环至少有 4 个点(最小的多边形是首尾点相同的三角形)Polygon rings have at least 4 points (minimum polygon is a triangle with first and last points the same)
集合不为空(
GeometryCollection除外)Collections are not empty (exceptGeometryCollection)
如果一个几何形状在语法上是良好形成的,并且满足此(非详尽)列表中的条件,则该几何形状在几何上是有效的:A geometry is geometrically valid if it is syntactically well-formed and satisfies conditions such as those in this (nonexhaustive) list:
多边形不自相交Polygons are not self-intersecting
多边形的内部环位于外部环内部Polygon interior rings are inside the exterior ring
多多边形不重叠Multipolygons do not have overlapping polygons
如果几何形状在语法上不良好形成,空间函数将失败。解析 WKT 或 WKB 值的空间导入函数在尝试创建语法上不良好形成的几何形状时会引发错误。在尝试将几何形状存储到表中时也会检查语法良好性。Spatial functions fail if a geometry is not syntactically well-formed. Spatial import functions that parse WKT or WKB values raise an error for attempts to create a geometry that is not syntactically well-formed. Syntactic well-formedness is also checked for attempts to store geometries into tables.
允许插入、选择和更新几何上无效的几何图形,但它们必须在语法上是良构的。由于计算开销较大,MySQL 不会明确检查几何的有效性。空间计算可能会检测到某些无效几何的情况并引发错误,但也可能在未检测到无效性的情况下返回未定义的结果。需要几何上有效的几何图形的应用程序应使用 ST_IsValid() 函数进行检查。It is permitted to insert, select, and update geometrically
invalid geometries, but they must be syntactically well-formed.
Due to the computational expense, MySQL does not check
explicitly for geometric validity. Spatial computations may
detect some cases of invalid geometries and raise an error, but
they may also return an undefined result without detecting the
invalidity. Applications that require geometrically-valid
geometries should check them using the
ST_IsValid() function.