11.4.1 Spatial Data Types空间数据类型

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

Some spatial data types hold single geometry values:某些空间数据类型包含单个几何体值:

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

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

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

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

CREATE TABLE geom (g GEOMETRY);

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. 具有空间数据类型的列可以具有SRID属性,以显式指示存储在列中的值的空间参考系(SRS)。For example:

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

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:如果空间列是NOT NULL并且具有特定的SRID,则可以在空间列上创建SPATIAL索引,因此如果计划对该列编制索引,请使用NOT NULL和SRID属性声明该列:

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

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

The SRID attribute makes a spatial column SRID-restricted, which has these implications:SRID属性使空间列SRID受限,这意味着:

Spatial columns with no SRID attribute are not SRID-restricted and accept values with any SRID. 没有SRID属性的空间列不受SRID限制,并接受具有任何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.但是,在修改列定义以包含SRID属性之前,优化器不能对其使用SPATIAL索引,这可能需要首先修改列内容,以便所有值都具有相同的SRID。

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