Documentation Home
MySQL 9.3 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 40.8Mb
PDF (A4) - 40.9Mb
Man Pages (TGZ) - 261.1Kb
Man Pages (Zip) - 368.3Kb
Info (Gzip) - 4.1Mb
Info (Zip) - 4.1Mb


MySQL 9.3 Reference Manual  / ...  / SQL Statements  / Data Definition Statements  /  CREATE SPATIAL REFERENCE SYSTEM Statement

15.1.21 CREATE SPATIAL REFERENCE SYSTEM Statement

CREATE OR REPLACE SPATIAL REFERENCE SYSTEMsridsrs_attribute ...CREATE SPATIAL REFERENCE SYSTEM    [IF NOT EXISTS]sridsrs_attribute ...srs_attribute: {    NAME 'srs_name'  | DEFINITION 'definition'  | ORGANIZATION 'org_name' IDENTIFIED BYorg_id  | DESCRIPTION 'description'}srid,org_id:32-bit unsigned integer

This statement creates aspatial reference system (SRS) definition and stores it in the data dictionary, and requires theCREATE_SPATIAL_REFERENCE_SYSTEM privilege (orSUPER). The resulting data dictionary entry can be inspected using theINFORMATION_SCHEMAST_SPATIAL_REFERENCE_SYSTEMS table.

SRID values must be unique, so if neitherOR REPLACE norIF NOT EXISTS is specified, an error occurs if an SRS definition with the givensrid value already exists.

WithCREATE 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 atleast one column depending on it.

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;

WithCREATE ... 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 values must be in the range of 32-bit unsigned integers, with these restrictions:

  • SRID 0 is a valid SRID but cannot be used withCREATE SPATIAL REFERENCE SYSTEM.

  • 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 theEuropean Petroleum Survey Group.

  • 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.

  • TheNAME andDEFINITION attributes are mandatory.

  • TheNAMEsrs_name attribute value must be unique. The combination of theORGANIZATIONorg_name andorg_id attribute values must be unique.

  • TheNAMEsrs_name attribute value andORGANIZATIONorg_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.

    Table 15.6 CREATE SPATIAL REFERENCE SYSTEM Attribute Lengths

    AttributeMaximum Length (characters)
    NAME80
    DEFINITION4096
    ORGANIZATION256
    DESCRIPTION2048

Here is an exampleCREATE SPATIAL REFERENCE SYSTEM statement. TheDEFINITION 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 4120NAME 'Greek'ORGANIZATION 'EPSG' IDENTIFIED BY 4120DEFINITION  '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"]]';

The grammar for SRS definitions is based on the grammar defined inOpenGIS Implementation Specification: Coordinate Transformation Services, Revision 1.00, OGC 01-009, January 12, 2001, Section 7.2. This specification is available athttp://www.opengeospatial.org/standards/ct.

MySQL incorporates these changes to the specification:

  • Only the<horz cs> production rule is implemented (that is, geographic and projected SRSs).

  • There is an optional, nonstandard<authority> clause for<parameter>. This makes it possible to recognize projection parameters by authority instead of name.

  • The specification does not makeAXIS clauses mandatory inGEOGCS spatial reference system definitions. However, if there are noAXIS clauses, MySQL cannot determine whether a definition has axes in latitude-longitude order or longitude-latitude order. MySQL enforces the nonstandard requirement that eachGEOGCS definition must include twoAXIS clauses. One must beNORTH orSOUTH, and the otherEAST orWEST. TheAXIS clause order determines whether the definition has axes in latitude-longitude order or longitude-latitude order.

  • SRS definitions may not contain newlines.

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 inTable 15.7, “Supported Spatial Reference System Projection Methods” andTable 15.8, “Spatial Reference System Projection Parameters”.

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, seeEPSG Guidance Note 7-2.

Table 15.7 Supported Spatial Reference System Projection Methods

EPSG CodeProjection NameMandatory Parameters (EPSG Codes)
1024Popular Visualisation Pseudo Mercator8801, 8802, 8806, 8807
1027Lambert Azimuthal Equal Area (Spherical)8801, 8802, 8806, 8807
1028Equidistant Cylindrical8823, 8802, 8806, 8807
1029Equidistant Cylindrical (Spherical)8823, 8802, 8806, 8807
1041Krovak (North Orientated)8811, 8833, 1036, 8818, 8819, 8806, 8807
1042Krovak Modified8811, 8833, 1036, 8818, 8819, 8806, 8807, 8617, 8618, 1026, 1027, 1028, 1029, 1030, 1031, 1032, 1033, 1034, 1035
1043Krovak Modified (North Orientated)8811, 8833, 1036, 8818, 8819, 8806, 8807, 8617, 8618, 1026, 1027, 1028, 1029, 1030, 1031, 1032, 1033, 1034, 1035
1051Lambert Conic Conformal (2SP Michigan)8821, 8822, 8823, 8824, 8826, 8827, 1038
1052Colombia Urban8801, 8802, 8806, 8807, 1039
9801Lambert Conic Conformal (1SP)8801, 8802, 8805, 8806, 8807
9802Lambert Conic Conformal (2SP)8821, 8822, 8823, 8824, 8826, 8827
9803Lambert Conic Conformal (2SP Belgium)8821, 8822, 8823, 8824, 8826, 8827
9804Mercator (variant A)8801, 8802, 8805, 8806, 8807
9805Mercator (variant B)8823, 8802, 8806, 8807
9806Cassini-Soldner8801, 8802, 8806, 8807
9807Transverse Mercator8801, 8802, 8805, 8806, 8807
9808Transverse Mercator (South Orientated)8801, 8802, 8805, 8806, 8807
9809Oblique Stereographic8801, 8802, 8805, 8806, 8807
9810Polar Stereographic (variant A)8801, 8802, 8805, 8806, 8807
9811New Zealand Map Grid8801, 8802, 8806, 8807
9812Hotine Oblique Mercator (variant A)8811, 8812, 8813, 8814, 8815, 8806, 8807
9813Laborde Oblique Mercator8811, 8812, 8813, 8815, 8806, 8807
9815Hotine Oblique Mercator (variant B)8811, 8812, 8813, 8814, 8815, 8816, 8817
9816Tunisia Mining Grid8821, 8822, 8826, 8827
9817Lambert Conic Near-Conformal8801, 8802, 8805, 8806, 8807
9818American Polyconic8801, 8802, 8806, 8807
9819Krovak8811, 8833, 1036, 8818, 8819, 8806, 8807
9820Lambert Azimuthal Equal Area8801, 8802, 8806, 8807
9822Albers Equal Area8821, 8822, 8823, 8824, 8826, 8827
9824Transverse Mercator Zoned Grid System8801, 8830, 8831, 8805, 8806, 8807
9826Lambert Conic Conformal (West Orientated)8801, 8802, 8805, 8806, 8807
9828Bonne (South Orientated)8801, 8802, 8806, 8807
9829Polar Stereographic (variant B)8832, 8833, 8806, 8807
9830Polar Stereographic (variant C)8832, 8833, 8826, 8827
9831Guam Projection8801, 8802, 8806, 8807
9832Modified Azimuthal Equidistant8801, 8802, 8806, 8807
9833Hyperbolic Cassini-Soldner8801, 8802, 8806, 8807
9834Lambert Cylindrical Equal Area (Spherical)8823, 8802, 8806, 8807
9835Lambert Cylindrical Equal Area8823, 8802, 8806, 8807

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 theEPSG Online Registry.

Table 15.8 Spatial Reference System Projection Parameters

EPSG CodeFallback Name (Recognized by MySQL)EPSG Name
1026c1C1
1027c2C2
1028c3C3
1029c4C4
1030c5C5
1031c6C6
1032c7C7
1033c8C8
1034c9C9
1035c10C10
1036azimuthCo-latitude of cone axis
1038ellipsoid_scale_factorEllipsoid scaling factor
1039projection_plane_height_at_originProjection plane origin height
8617evaluation_point_ordinate_1Ordinate 1 of evaluation point
8618evaluation_point_ordinate_2Ordinate 2 of evaluation point
8801latitude_of_originLatitude of natural origin
8802central_meridianLongitude of natural origin
8805scale_factorScale factor at natural origin
8806false_eastingFalse easting
8807false_northingFalse northing
8811latitude_of_centerLatitude of projection centre
8812longitude_of_centerLongitude of projection centre
8813azimuthAzimuth of initial line
8814rectified_grid_angleAngle from Rectified to Skew Grid
8815scale_factorScale factor on initial line
8816false_eastingEasting at projection centre
8817false_northingNorthing at projection centre
8818pseudo_standard_parallel_1Latitude of pseudo standard parallel
8819scale_factorScale factor on pseudo standard parallel
8821latitude_of_originLatitude of false origin
8822central_meridianLongitude of false origin
8823standard_parallel_1, standard_parallel1Latitude of 1st standard parallel
8824standard_parallel_2, standard_parallel2Latitude of 2nd standard parallel
8826false_eastingEasting at false origin
8827false_northingNorthing at false origin
8830initial_longitudeInitial longitude
8831zone_widthZone width
8832standard_parallelLatitude of standard parallel
8833longitude_of_centerLongitude of origin