Registers a spatial reference system (SRS) and returns its spatial reference system identifier (SRID).
Syntax
integer ST_SrReg(cstring sr);
integer ST_SrReg(cstring auth_name, integer auth_id, cstring sr);Parameters
| Parameter | Type | Description |
|---|---|---|
sr | cstring | The SRS definition string. Must be an OGC Well-Known Text (WKT) or PROJ.4 string. |
auth_name | cstring | The authority that defines the SRS. For example, EPSG. |
auth_id | integer | The SRID assigned by the authority. |
How it works
The function is idempotent:
If the SRS already exists, the function returns the SRID of the existing entry without inserting a duplicate.
If the SRS does not exist, the function inserts a new record into
spatial_ref_sysand returns the SRID of the new entry.
Examples
Register an existing SRS
The following example registers EPSG:4490 (China Geodetic Coordinate System 2000). Because this SRS already exists in spatial_ref_sys, the function returns its existing SRID.
SELECT ST_SrReg('GEOGCS["China Geodetic Coordinate System 2000",DATUM["China_2000",SPHEROID["CGCS2000",6378137,298.257222101,AUTHORITY["EPSG","1024"]],AUTHORITY["EPSG","1043"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4490"]]');Output:
st_srreg
----------
4490Register a new SRS with an authority name and ID
The following example registers a user-defined SRS, specifying user_defined as the authority and 100 as the authority-assigned ID. Because this SRS does not exist, the function inserts it into spatial_ref_sys and returns a new auto-assigned SRID.
SELECT ST_SrReg('user_defined', 100, 'GEOGCS["User Geodetic Coordinate System ",DATUM["China_2000",SPHEROID["CGCS2000",6378137,298.257222101,AUTHORITY["EPSG","903"]],AUTHORITY["EPSG","1043"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4491"]]');Output:
st_srreg
----------
10001Register a new SRS using a PROJ.4 string
The following example registers a new SRS using a PROJ.4 definition string. The function returns a new auto-assigned SRID.
SELECT ST_SrReg('+proj=tmerc +lat_0=1 +lon_0=112 +k=1 +x_0=19500001 +y_0=0 +ellps=krass +towgs84=24.47,-130.89,-81.56,0,0,0.13,-0.22 +units=m +no_defs');Output:
st_srreg
----------
10002Usage notes
To look up the WKT or PROJ.4 string for a standard coordinate system, use epsg.io or spatialreference.org.
The SRID returned by
ST_SrRegcan be used directly in other spatial functions to reference the registered coordinate system.