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
POINT
LINESTRING
POLYGON
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.POINT
、LINESTRING
和POLYGON
)将其值限制为特定的几何图形类型。
The other spatial data types hold collections of values:其他空间数据类型包含值集合:
MULTIPOINT
MULTILINESTRING
MULTIPOLYGON
GEOMETRYCOLLECTION
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.MULTIPOINT
、MULTILINESTRING
和MULTIPOLYGON
)将集合成员限制为具有特定几何体类型的成员。
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受限,这意味着:
The column can contain only values with the given SRID. 列只能包含具有给定SRID的值。Attempts to insert values with a different SRID produce an error.尝试插入具有不同SRID的值会产生错误。
The optimizer can use 优化器可以在列上使用SPATIAL
indexes on the column. SPATIAL
索引。See Section 8.3.3, “SPATIAL Index Optimization”.请参阅第8.3.3节“空间索引优化”。
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节“空间参考系统支持”。