Registers a spatial reference system (SRS) in the database. If the SRS already exists, returns its existing SRID. If it does not exist, inserts a new record into the spatial_ref_sys table and returns the new SRID.
When to use this function
Call ST_SrReg when:
The SRS you need is not in the built-in set (for example, a custom coordinate system for a regional survey)
You want to register an SRS using a PROJ.4 string instead of an EPSG code
Syntax
integer ST_SrReg(cstring sr);
integer ST_SrReg(cstring auth_name, integer auth_id, cstring sr);Parameters
| Parameter | Description |
|---|---|
sr | The SRS definition string. Must be an OGC Well-Known Text (WKT) or PROJ.4 string. |
auth_name | The name of the authority that defines the SRS (for example, EPSG). |
auth_id | The spatial reference system identifier (SRID) of the spatial reference system. |
Return value
integer — the SRID of the registered spatial reference system.
Examples
Register a standard SRS that already exists
This example passes the WKT for EPSG:4490 (China Geodetic Coordinate System 2000). Because the SRS is already in spatial_ref_sys, the function returns its existing SRID.
select 4490, 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 custom SRS with authority metadata
This example registers a new SRS under the user_defined authority. The function inserts a record into spatial_ref_sys and returns a new 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
Use this form when you have a PROJ.4 definition instead of a WKT string.
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
----------
10002