ST_SrReg

更新时间:
复制 MD 格式

Registers a spatial reference system (SRS) in the spatial_ref_sys table and returns the spatial reference system identifier (SRID).

Syntax

integer ST_SrReg(cstring sr);
integer ST_SrReg(cstring auth_name, integer auth_id, cstring sr);

Parameters

ParameterTypeDescription
srcstringThe SRS definition string. Must be a Well-Known Text (WKT) string conforming to the OGC standard, or a PROJ.4 string.
auth_namecstringThe name of the authority that defines the SRS. For example, EPSG.
auth_idintegerThe SRID assigned by the authority specified in auth_name.

Description

ST_SrReg registers an SRS definition in the spatial_ref_sys table.

  • If the SRS already exists in spatial_ref_sys, the function returns the SRID of the existing record without inserting a new one.

  • If the SRS does not exist, the function inserts a new record and returns the assigned SRID.

Examples

Example 1: Register an existing SRS (returns existing SRID)

The following example registers China Geodetic Coordinate System 2000 (CGCS2000), which is already present in spatial_ref_sys as EPSG:4490. The function returns the existing SRID 4490.

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
----------
      4490

Example 2: Register a new SRS with authority information

The following example registers a custom SRS using a WKT string and specifies the authority name and ID. Because the SRS does not exist, the function inserts a new record and returns the assigned SRID 10001.

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
----------
     10001

Example 3: Register a new SRS with a PROJ.4 string

The following example registers a new SRS using only a PROJ.4 string. The function returns the SRID 10002.

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