文档首页
MySQL 8.4 参考手册
8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

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

打开官方英文原文 ↗

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

MySQL 8.4 参考手册 / 15 条 SQL 语句 / 15.1 数据定义语句 / 15.1.19 创建空间参考系统语句
中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 87%

15.1.19 CREATE SPATIAL REFERENCE SYSTEM 语句15.1.19 CREATE SPATIAL REFERENCE SYSTEM Statement

CREATE OR REPLACE SPATIAL REFERENCE SYSTEM
    srid srs_attribute ...

CREATE SPATIAL REFERENCE SYSTEM
    [IF NOT EXISTS]
    srid srs_attribute ...

srs_attribute: {
    NAME 'srs_name'
  | DEFINITION 'definition'
  | ORGANIZATION 'org_name' IDENTIFIED BY org_id
  | DESCRIPTION 'description'
}

srid, org_id: 32-bit unsigned integer

此语句创建一个空间参考系统(SRS)定义,并将其存储在数据字典中。它需要SUPER权限。生成的数据字典条目可以使用INFORMATION_SCHEMAST_SPATIAL_REFERENCE_SYSTEMS表查看。This statement creates a spatial reference system (SRS) definition and stores it in the data dictionary. It requires the SUPER privilege. The resulting data dictionary entry can be inspected using the INFORMATION_SCHEMA ST_SPATIAL_REFERENCE_SYSTEMS table.

SRID 值必须唯一,因此如果未指定OR REPLACE或IF NOT EXISTS,当存在具有给定srid值的 SRS 定义时,将发生错误。SRID values must be unique, so if neither OR REPLACE nor IF NOT EXISTS is specified, an error occurs if an SRS definition with the given srid value already exists.

使用CREATE OR REPLACE语法时,任何具有相同 SRID 值的现有 SRS 定义将被替换,除非该 SRID 值已被现有表中的某列使用。在这种情况下,将发生错误。例如:With CREATE OR REPLACE syntax, any existing SRS definition with the same SRID value is replaced, unless the SRID value is used by some column in an existing table. In that case, an error occurs. For example:

mysql> CREATE OR REPLACE SPATIAL REFERENCE SYSTEM 4326 ...;
ERROR 3716 (SR005): Can't modify SRID 4326. There is at
least one column depending on it.

要识别使用 SRID 的列,请使用此查询,并将 4326 替换为您尝试创建的定义的 SRID:To identify which column or columns use the SRID, use this query, replacing 4326 with the SRID of the definition you are trying to create:

SELECT * FROM INFORMATION_SCHEMA.ST_GEOMETRY_COLUMNS WHERE SRS_ID=4326;

使用 CREATE ... IF NOT EXISTS 语法时,任何具有相同 SRID 值的现有 SRS 定义都会导致新的定义被忽略,并且会出现警告。With CREATE ... IF NOT EXISTS syntax, any existing SRS definition with the same SRID value causes the new definition to be ignored and a warning occurs.

SRID 值必须在 32 位无符号整数的范围内,并具有以下限制:SRID values must be in the range of 32-bit unsigned integers, with these restrictions:

  • SRID 0 是一个有效的 SRID,但不能用于 CREATE SPATIAL REFERENCE SYSTEM。SRID 0 is a valid SRID but cannot be used with CREATE SPATIAL REFERENCE SYSTEM.

  • 如果该值处于保留的 SRID 范围内,则会出现警告。保留范围为 [0, 32767](由 EPSG 保留)、[60,000,000, 69,999,999](由 EPSG 保留)和 [2,000,000,000, 2,147,483,647](由 MySQL 保留)。EPSG 代表 欧洲石油测量组。If the value is in a reserved SRID range, a warning occurs. Reserved ranges are [0, 32767] (reserved by EPSG), [60,000,000, 69,999,999] (reserved by EPSG), and [2,000,000,000, 2,147,483,647] (reserved by MySQL). EPSG stands for the European Petroleum Survey Group.

  • 用户不应创建具有保留范围内 SRID 的 SRS。这样做有可能导致 SRID 与将随 MySQL 分发的未来 SRS 定义发生冲突,结果可能是新的系统提供的 SRS 未能在 MySQL 升级时安装,或者用户定义的 SRS 被覆盖。Users should not create SRSs with SRIDs in the reserved ranges. Doing so runs the risk of the SRIDs conflicting with future SRS definitions distributed with MySQL, with the result that the new system-provided SRSs are not installed for MySQL upgrades or that the user-defined SRSs are overwritten.

声明的属性必须满足以下条件:Attributes for the statement must satisfy these conditions:

  • 属性可以按任意顺序给出,但不能重复给出同一个属性。Attributes can be given in any order, but no attribute can be given more than once.

  • NAME 和 DEFINITION 属性是必填的。The NAME and DEFINITION attributes are mandatory.

  • NAME srs_name 属性值必须唯一。ORGANIZATION org_name 和 org_id 属性值的组合必须唯一。The NAME srs_name attribute value must be unique. The combination of the ORGANIZATION org_name and org_id attribute values must be unique.

  • NAME srs_name 属性值和 ORGANIZATION org_name 属性值不能为空,也不能以空格开头或结尾。The NAME srs_name attribute value and ORGANIZATION org_name attribute value cannot be empty or begin or end with whitespace.

  • 属性规格中的字符串值不能包含控制字符,包括换行符。String values in attribute specifications cannot contain control characters, including newline.

  • 下表显示了字符串属性值的最大长度。The following table shows the maximum lengths for string attribute values.

    表 15.6 创建空间参考系统属性长度Table 15.6 CREATE SPATIAL REFERENCE SYSTEM Attribute Lengths

    属性Attribute 最大长度(字符)Maximum Length (characters)
    NAMENAME 80
    DEFINITIONDEFINITION 4096
    ORGANIZATIONORGANIZATION 256
    DESCRIPTIONDESCRIPTION 2048

这是一个 CREATE SPATIAL REFERENCE SYSTEM 语句的示例。DEFINITION 的值被分多行重新格式化以便于阅读。(为了语句合法,该值实际上必须写在一行上。)Here is an example CREATE SPATIAL REFERENCE SYSTEM statement. The DEFINITION value is reformatted across multiple lines for readability. (For the statement to be legal, the value actually must be given on a single line.)

CREATE SPATIAL REFERENCE SYSTEM 4120
NAME 'Greek'
ORGANIZATION 'EPSG' IDENTIFIED BY 4120
DEFINITION
  'GEOGCS["Greek",DATUM["Greek",SPHEROID["Bessel 1841",
  6377397.155,299.1528128,AUTHORITY["EPSG","7004"]],
  AUTHORITY["EPSG","6120"]],PRIMEM["Greenwich",0,
  AUTHORITY["EPSG","8901"]],UNIT["degree",0.017453292519943278,
  AUTHORITY["EPSG","9122"]],AXIS["Lat",NORTH],AXIS["Lon",EAST],
  AUTHORITY["EPSG","4120"]]';

SRS 定义的语法基于 OpenGIS Implementation Specification: Coordinate Transformation Services,版本 1.00,OGC 01-009,2001 年 1 月 12 日,第 7.2 节中定义的语法。该规范可在 http://www.opengeospatial.org/standards/ct 获取。The grammar for SRS definitions is based on the grammar defined in OpenGIS Implementation Specification: Coordinate Transformation Services, Revision 1.00, OGC 01-009, January 12, 2001, Section 7.2. This specification is available at http://www.opengeospatial.org/standards/ct.

MySQL 将这些更改纳入规范:MySQL incorporates these changes to the specification:

  • 仅实现了 <horz cs> 生成规则(即地理和投影空间参考系统)。Only the <horz cs> production rule is implemented (that is, geographic and projected SRSs).

  • 对于 <parameter>,存在一个可选的、非标准的 <authority> 条款。这使得可以通过权威而不是名称来识别投影参数。There is an optional, nonstandard <authority> clause for <parameter>. This makes it possible to recognize projection parameters by authority instead of name.

  • 规范并未强制在 GEOGCS 空间参考系统定义中使用 AXIS 条款。然而,如果没有 AXIS 条款,MySQL 无法确定定义的轴是按纬度-经度顺序还是经度-纬度顺序。MySQL 强制要求每个 GEOGCS 定义必须包含两个 AXIS 条款,这是一个非标准要求。一个必须是 NORTH 或 SOUTH,另一个必须是 EAST 或 WEST。AXIS 条款的顺序决定了定义的轴是按纬度-经度顺序还是经度-纬度顺序。The specification does not make AXIS clauses mandatory in GEOGCS spatial reference system definitions. However, if there are no AXIS clauses, MySQL cannot determine whether a definition has axes in latitude-longitude order or longitude-latitude order. MySQL enforces the nonstandard requirement that each GEOGCS definition must include two AXIS clauses. One must be NORTH or SOUTH, and the other EAST or WEST. The AXIS clause order determines whether the definition has axes in latitude-longitude order or longitude-latitude order.

  • SRS 定义中不得包含换行符。SRS definitions may not contain newlines.

如果 SRS 定义为投影指定了一个权限代码(推荐使用),当定义缺少必需参数时会发生错误。在这种情况下,错误消息会指出问题所在。MySQL 支持的投影方法和必需参数列在 表 15.7,“支持的空间参考系统投影方法” 和 表 15.8,“空间参考系统投影参数” 中。If an SRS definition specifies an authority code for the projection (which is recommended), an error occurs if the definition is missing mandatory parameters. In this case, the error message indicates what the problem is. The projection methods and mandatory parameters that MySQL supports are shown in Table 15.7, “Supported Spatial Reference System Projection Methods” and Table 15.8, “Spatial Reference System Projection Parameters”.

下表显示了 MySQL 支持的投影方法。MySQL 允许未知投影方法,但无法检查定义中的必需参数,也无法将空间数据转换到未知投影或从未知投影转换。有关每种投影方法的详细工作原理(包括公式)的说明,请参见 EPSG 指导说明 7-2。The following table shows the projection methods that MySQL supports. MySQL permits unknown projection methods but cannot check the definition for mandatory parameters and cannot convert spatial data to or from an unknown projection. For detailed explanations of how each projection works, including formulas, see EPSG Guidance Note 7-2.

表 15.7 支持的空间参考系统投影方法Table 15.7 Supported Spatial Reference System Projection Methods

EPSG 代码EPSG Code 投影名称Projection Name 必填参数 (EPSG 代码)Mandatory Parameters (EPSG Codes)
1024 流行可视化伪墨卡托Popular Visualisation Pseudo Mercator 8801, 8802, 8806, 8807
1027 兰伯特方位等积 (球体)Lambert Azimuthal Equal Area (Spherical) 8801, 8802, 8806, 8807
1028 等距圆柱Equidistant Cylindrical 8823, 8802, 8806, 8807
1029 等距圆柱 (球体)Equidistant Cylindrical (Spherical) 8823, 8802, 8806, 8807
1041 Krovak (北向)Krovak (North Orientated) 8811, 8833, 1036, 8818, 8819, 8806, 8807
1042 Krovak 修改版Krovak Modified 8811, 8833, 1036, 8818, 8819, 8806, 8807, 8617, 8618, 1026, 1027, 1028, 1029, 1030, 1031, 1032, 1033, 1034, 1035
1043 Krovak 修改版 (北向)Krovak Modified (North Orientated) 8811, 8833, 1036, 8818, 8819, 8806, 8807, 8617, 8618, 1026, 1027, 1028, 1029, 1030, 1031, 1032, 1033, 1034, 1035
1051 兰伯特等角圆锥 (2SP 密歇根)Lambert Conic Conformal (2SP Michigan) 8821, 8822, 8823, 8824, 8826, 8827, 1038
1052 哥伦比亚城市Colombia Urban 8801, 8802, 8806, 8807, 1039
9801 兰伯特等角圆锥 (1SP)Lambert Conic Conformal (1SP) 8801, 8802, 8805, 8806, 8807
9802 兰伯特等角圆锥 (2SP)Lambert Conic Conformal (2SP) 8821, 8822, 8823, 8824, 8826, 8827
9803 兰伯特等角圆锥 (2SP 比利时)Lambert Conic Conformal (2SP Belgium) 8821, 8822, 8823, 8824, 8826, 8827
9804 墨卡托 (变体 A)Mercator (variant A) 8801, 8802, 8805, 8806, 8807
9805 墨卡托 (变体 B)Mercator (variant B) 8823, 8802, 8806, 8807
9806 卡西尼-索尔德纳Cassini-Soldner 8801, 8802, 8806, 8807
9807 横轴墨卡托Transverse Mercator 8801, 8802, 8805, 8806, 8807
9808 横轴墨卡托 (南向)Transverse Mercator (South Orientated) 8801, 8802, 8805, 8806, 8807
9809 斜等角投影Oblique Stereographic 8801, 8802, 8805, 8806, 8807
9810 极地立体投影 (变体 A)Polar Stereographic (variant A) 8801, 8802, 8805, 8806, 8807
9811 新西兰地图网格New Zealand Map Grid 8801, 8802, 8806, 8807
9812 Hotine 斜墨卡托 (变体 A)Hotine Oblique Mercator (variant A) 8811, 8812, 8813, 8814, 8815, 8806, 8807
9813 Laborde 斜墨卡托Laborde Oblique Mercator 8811, 8812, 8813, 8815, 8806, 8807
9815 Hotine 斜墨卡托 (变体 B)Hotine Oblique Mercator (variant B) 8811, 8812, 8813, 8814, 8815, 8816, 8817
9816 突尼斯矿业网格Tunisia Mining Grid 8821, 8822, 8826, 8827
9817 近似保形兰伯特圆锥Lambert Conic Near-Conformal 8801, 8802, 8805, 8806, 8807
9818 美式多圆锥American Polyconic 8801, 8802, 8806, 8807
9819 Krovak 8811, 8833, 1036, 8818, 8819, 8806, 8807
9820 兰伯特方位等积Lambert Azimuthal Equal Area 8801, 8802, 8806, 8807
9822 阿尔贝斯等积Albers Equal Area 8821, 8822, 8823, 8824, 8826, 8827
9824 横轴墨卡托分带网格系统Transverse Mercator Zoned Grid System 8801, 8830, 8831, 8805, 8806, 8807
9826 兰伯特等角圆锥 (西向)Lambert Conic Conformal (West Orientated) 8801, 8802, 8805, 8806, 8807
9828 Bonne (南向)Bonne (South Orientated) 8801, 8802, 8806, 8807
9829 极地立体投影 (变体 B)Polar Stereographic (variant B) 8832, 8833, 8806, 8807
9830 极地立体投影 (变体 C)Polar Stereographic (variant C) 8832, 8833, 8826, 8827
9831 关岛投影Guam Projection 8801, 8802, 8806, 8807
9832 改良方位等距投影Modified Azimuthal Equidistant 8801, 8802, 8806, 8807
9833 双曲卡西尼-索尔德纳Hyperbolic Cassini-Soldner 8801, 8802, 8806, 8807
9834 兰伯特圆柱等面积投影(球面)Lambert Cylindrical Equal Area (Spherical) 8823, 8802, 8806, 8807
9835 兰伯特圆柱等面积投影Lambert Cylindrical Equal Area 8823, 8802, 8806, 8807

下表显示了 MySQL 识别的投影参数。识别主要依赖于权威代码。如果没有权威代码,MySQL 会回退到对参数名称的不区分大小写的字符串匹配。有关每个参数的详细信息,请通过代码在 EPSG 在线注册表 中查询。The following table shows the projection parameters that MySQL recognizes. Recognition occurs primarily by authority code. If there is no authority code, MySQL falls back to case-insensitive string matching on the parameter name. For details about each parameter, look it up by code in the EPSG Online Registry.

表 15.8 空间参考系统投影参数Table 15.8 Spatial Reference System Projection Parameters

EPSG 代码EPSG Code 回退名称(MySQL 识别)Fallback Name (Recognized by MySQL) EPSG 名称EPSG Name
1026 c1 C1
1027 c2 C2
1028 c3 C3
1029 c4 C4
1030 c5 C5
1031 c6 C6
1032 c7 C7
1033 c8 C8
1034 c9 C9
1035 c10 C10
1036 方位角azimuth 圆锥轴的共纬度Co-latitude of cone axis
1038 椭球体缩放因子ellipsoid_scale_factor 椭球体缩放系数Ellipsoid scaling factor
1039 投影平面原点高度projection_plane_height_at_origin 投影平面原点高度Projection plane origin height
8617 评估点坐标 1evaluation_point_ordinate_1 评估点的坐标 1Ordinate 1 of evaluation point
8618 评估点坐标 2evaluation_point_ordinate_2 评估点的坐标 2Ordinate 2 of evaluation point
8801 原点纬度latitude_of_origin 自然原点纬度Latitude of natural origin
8802 中央子午线central_meridian 自然原点经度Longitude of natural origin
8805 缩放因子scale_factor 自然原点的缩放因子Scale factor at natural origin
8806 伪东坐标false_easting 伪东坐标False easting
8807 假北坐标false_northing 假北False northing
8811 中心纬度latitude_of_center 投影中心纬度Latitude of projection centre
8812 中心经度longitude_of_center 投影中心经度Longitude of projection centre
8813 方位角azimuth 初始线方位角Azimuth of initial line
8814 校正网格角rectified_grid_angle 从校正网格到斜网格的角度Angle from Rectified to Skew Grid
8815 缩放因子scale_factor 初始线缩放因子Scale factor on initial line
8816 伪东坐标false_easting 投影中心东坐标Easting at projection centre
8817 假北坐标false_northing 投影中心北坐标Northing at projection centre
8818 伪标准纬线 1pseudo_standard_parallel_1 伪标准纬线纬度Latitude of pseudo standard parallel
8819 缩放因子scale_factor 伪标准纬线缩放因子Scale factor on pseudo standard parallel
8821 原点纬度latitude_of_origin 假原点纬度Latitude of false origin
8822 中央子午线central_meridian 假原点经度Longitude of false origin
8823 标准纬线 1standard_parallel_1, standard_parallel1 第一标准纬线纬度Latitude of 1st standard parallel
8824 标准纬线 2standard_parallel_2, standard_parallel2 第二标准纬线纬度Latitude of 2nd standard parallel
8826 伪东坐标false_easting 假原点东坐标Easting at false origin
8827 假北坐标false_northing 假原点北坐标Northing at false origin
8830 初始经度initial_longitude 初始经度Initial longitude
8831 分带宽度zone_width 分带宽度Zone width
8832 标准纬线standard_parallel 标准纬线纬度Latitude of standard parallel
8833 中心经度longitude_of_center 原点经度Longitude of origin