8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 96%

13.4.1 空间数据类型13.4.1 Spatial Data Types

MySQL 拥有与 OpenGIS 类对应的空间数据类型。这些类型的基础在 第 13.4.2 节,“OpenGIS 几何模型” 中有描述。MySQL has spatial data types that correspond to OpenGIS classes. The basis for these types is described in Section 13.4.2, “The OpenGIS Geometry Model”.

一些空间数据类型保存单一几何值:Some spatial data types hold single geometry values:

  • GEOMETRYGEOMETRY

  • POINTPOINT

  • LINESTRING

  • POLYGONPOLYGON

GEOMETRY 可以存储任何类型的几何值。其他单值类型(POINT、LINESTRING 和 POLYGON)将它们的值限制为特定的几何类型。GEOMETRY can store geometry values of any type. The other single-value types (POINT, LINESTRING, and POLYGON) restrict their values to a particular geometry type.

其他空间数据类型包含值的集合:The other spatial data types hold collections of values:

  • MULTIPOINTMULTIPOINT

  • MULTILINESTRINGMULTILINESTRING

  • MULTIPOLYGONMULTIPOLYGON

  • GEOMETRYCOLLECTIONGEOMETRYCOLLECTION

GEOMETRYCOLLECTION 可以存储任何类型对象的集合。其他集合类型(MULTIPOINT、MULTILINESTRING 和 MULTIPOLYGON)将集合成员限制为具有特定几何类型的对象。GEOMETRYCOLLECTION can store a collection of objects of any type. The other collection types (MULTIPOINT, MULTILINESTRING, and MULTIPOLYGON) restrict collection members to those having a particular geometry type.

示例:要创建一个名为 geom 的表,该表有一列名为 g,可存储任何几何类型的值,请使用以下语句:Example: To create a table named geom that has a column named g that can store values of any geometry type, use this statement:

CREATE TABLE geom (g GEOMETRY);

具有空间数据类型的列可以具有 SRID 属性,用于明确指示该列中存储值的空间参考系统 (SRS)。例如:Columns with a spatial data type can have an SRID attribute, to explicitly indicate the spatial reference system (SRS) for values stored in the column. For example:

CREATE TABLE geom (
    p POINT SRID 0,
    g GEOMETRY NOT NULL SRID 4326
);

SPATIAL 索引可以在空间列上创建,如果它们是 NOT NULL 并且具有特定的 SRID,因此如果您计划对该列建立索引,请使用 NOT NULL 和 SRID 属性声明该列:SPATIAL indexes can be created on spatial columns if they are NOT NULL and have a specific SRID, so if you plan to index the column, declare it with the NOT NULL and SRID attributes:

CREATE TABLE geom (g GEOMETRY NOT NULL SRID 4326);

InnoDB 表允许笛卡尔和地理 SRS 的 SRID 值。MyISAM 表允许笛卡尔 SRS 的 SRID 值。InnoDB tables permit SRID values for Cartesian and geographic SRSs. MyISAM tables permit SRID values for Cartesian SRSs.

SRID 属性使空间列具有 SRID 限制,其含义如下:The SRID attribute makes a spatial column SRID-restricted, which has these implications:

没有SRID属性的空间列不受 SRID 限制,可以接受任意 SRID 的值。然而,在列定义修改以包含SRID属性之前,优化器不能在这些列上使用SPATIAL索引,这可能需要首先修改列内容,以便所有值具有相同的 SRID。Spatial columns with no SRID attribute are not SRID-restricted and accept values with any SRID. However, the optimizer cannot use SPATIAL indexes on them until the column definition is modified to include an SRID attribute, which may require that the column contents first be modified so that all values have the same SRID.

有关在 MySQL 中使用空间数据类型的其他示例,请参阅 第 13.4.6 节,“创建空间列”。有关空间参考系统的信息,请参阅 第 13.4.5 节,“空间参考系统支持”。For other examples showing how to use spatial data types in MySQL, see Section 13.4.6, “Creating Spatial Columns”. For information about spatial reference systems, see Section 13.4.5, “Spatial Reference System Support”.