Create spatial references using SQL

Esri recommends creating spatial references using ArcGIS for Desktop tools when creating feature classes. ArcGIS provides a full suite of tools for this task and will calculate x-, y-, z-, and m-units and offsets for you to maintain high-precision data. Esri understands, though, that some users and application developers want to have options when creating spatial references. This topic provides examples of using SQL to create spatial references.

The spatial reference system is assigned to a geometry during its construction. The spatial reference system must exist in the spatial reference table. All geometries in a column must have the same spatial reference system.

Creating a spatial reference in IBM DB2

In DB2, the command to create a spatial reference is db2se create_srs (or invoke the db2se.ST_create_srs stored procedure). The following example creates a spatial reference record with a scale factor of 10 and using a specific coordinate system:

db2se create_srs mydb -srsName \"mysrs\" 
-srsID 310000 -xScale 10 -coordsysName \"GCS_North_American_1983\"

For more information about using this command, see the "Creating a spatial reference system" section of the DB2 Spatial Extender and Geodetic Extender User's Guide and Reference.

Creating a spatial reference in IBM Informix

Informix users can create a spatial reference record in the spatial_references table using an INSERT statement similar to this example. Be sure to replace the SRID with a unique value.

INSERT INTO sde.spatial_references (srid, description, 
auth_name, auth_srid, falsex, falsey, xyunits, falsez, 
zunits, falsem, munits, srtext, object_flags, 
xycluster_tol, zcluster_tol, mcluster_tol)
VALUES (
 310000, 
 'GCS_North_American_1983', 
 NULL, 
 NULL, 
 -400,
 -400,
 1000000000,
 -100000,
 100000,
 -100000,
 10000, 
 'GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]',
 1,
 0,
 0,
 0
);

For more information about creating a spatial reference in Informix, see the "Using the spatial references table" section of the IBM Informix Spatial DataBlade Module User's Guide.

Creating a spatial reference in Oracle

Creating a spatial reference for tables using the spatial type in Oracle is conducted via an INSERT statement like the one below. Be sure to replace the SRID with a unique value.

INSERT INTO SDE.ST_SPATIAL_REFERENCES (SR_NAME, SRID, 
X_OFFSET, Y_OFFSET, XYUNITS, Z_OFFSET, Z_SCALE, M_OFFSET, 
M_SCALE, MIN_X, MAX_X, MIN_Y, MAX_Y, MIN_Z, MAX_Z, MIN_M, 
MAX_M, CS_ID, CS_NAME, CS_TYPE, ORGANIZATION, 
ORG_COORDSYS_ID, DEFINITION, DESCRIPTION)
VALUES (
 'GCS_North_American_1983', 
 310000,
 -400,
 -400,
 1000000000, 
 -100000, 
 100000, 
 -100000, 
 100000, 
 9.999E35,
 -9.999E35, 
 9.999E35, 
 -9.999E35, 
 9.999E35, 
 -9.999E35, 
 9.999E35, 
 -9.999E35, 
 4269, 
 'GCS_North_American_1983',
 'PROJECTED', 
 NULL,
 NULL,
 'GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]',
 'ArcSDE SpRef'
);

Creating a spatial reference in PostgreSQL

To create a spatial reference system for the spatial type in PostgreSQL, use an INSERT statement similar to the one below. Be sure to replace the SRID with a unique value.

INSERT INTO sde.st_spatial_references (sr_name, srid, 
x_offset, y_offset, xyunits, z_offset, z_scale, m_offset, 
m_scale, min_x, max_x, min_y, max_y, min_z, max_z, min_m, 
max_m, cs_id, cs_name, cs_type, organization, 
org_coordsys_id, definition, description)
VALUES (
 'GCS_North_American_1983',
 310000, 
 -400, 
 -400, 
 1000000000,
 -100000, 
 100000, 
 -100000, 
 100000, 
 9.999E35,
 -9.999E35, 
 9.999E35, 
 -9.999E35, 
 9.999E35, 
 -9.999E35, 
 9.999E35, 
 -9.999E35, 
 4269, 
 'GCS_North_American_1983',
 'PROJECTED', 
 NULL,
 NULL,
 'GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]',
 'ArcSDE SpRef'
);

Creating a spatial reference in SQLite

Use an INSERT statement similar to the following example to add spatial reference to the st_aux_spatial_reference_systems table in a SQLite database that uses ST_Geometry. Be sure to replace the SRID with a unique value.

INSERT INTO st_aux_spatial_reference_systems (srid, auth_name, auth_srid, 
sr_text, falsex, falsey, xyunits, falsez, zunits, falsem, 
munits, xycluster_tol, zcluster_tol, mcluster_tol)
VALUES (
 310000, 
 NULL, 
 4269, 
 'GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]',
 -400, 
 -400, 
 1000000000,
 -100000, 
 1.0, 
 -100000, 
 1.0, 
 0,
 0,
 0 
);

Related Topics

6/19/2015