ST_SrsId or ST_SRID function

The ST_SrsId or ST_SRID function takes a geometry and, optionally, a spatial reference system identifier as input parameters.

What it returns depends on what input parameters are specified:
  • If the spatial reference system identifier is specified, it returns the geometry with its spatial reference system changed to the specified spatial reference system. No transformation of the geometry is performed.
  • If no spatial reference system identifier is given as an input parameter, the current spatial reference system identifier of the given geometry is returned.

If the given geometry is null, then null is returned.

These functions can also be called as methods.

Syntax

Read syntax diagramSkip visual syntax diagramdb2gse.ST_SrsIddb2gse.ST_SRID(geometry ,srs_id )

Parameters

geometry
A value of type ST_Geometry or one of its subtypes that represents the geometry for which the spatial reference system identifier is to be set or returned.
srs_id
A value of type INTEGER that identifies the spatial reference system to be used for the resulting geometry.
Attention: If this parameter is specified, the geometry is not transformed, but is returned with its spatial reference system changed to the specified spatial reference system. As a result of changing to the new spatial reference system, the data might be corrupted. For transformations, use ST_Transform instead.

If srs_id does not identify a spatial reference system listed in the catalog view DB2GSE.ST_SPATIAL_REFERENCE_SYSTEMS, then an exception condition is raised (SQLSTATE 38SU1).

Return types

  • INTEGER, if an srs_id is not specified
  • db2gse.ST_Geometry, if an srs_id is specified

Example

Two points are created in two different spatial reference systems. The ID of the spatial reference system that is associated with each point can be found by using the ST_SrsId function.

SET CURRENT FUNCTION PATH = CURRENT FUNCTION PATH, db2gse
CREATE TABLE sample_points (id INTEGER, geometry ST_Point)

INSERT INTO sample_points
  VALUES (1, ST_Point( 'point (80 180)', 0 ) )
INSERT INTO sample_points
  VALUES (2, ST_Point( 'point (-74.21450127 + 42.03415094)', 1 ) )

SELECT id, ST_SRSId (geometry) SRSID
  FROM sample_points

Results:

ID           SRSID
----------- ------------
          1            0
          2            1