ST_SrEqual
Compares two spatial reference systems by parsing and matching their projection parameters, rather than comparing the strings directly.
Syntax
boolean ST_SrEqual(cstring sr1, cstring sr2, boolean strict default true);Parameters
| Parameter | Type | Description |
|---|---|---|
sr1 | cstring | The first spatial reference system. Must be an OGC Well-Known Text (WKT) or PROJ.4 string. |
sr2 | cstring | The second spatial reference system. Must be an OGC WKT or PROJ.4 string. |
strict | boolean | Specifies whether to use the strict comparison method. When true, compares the names of the reference ellipsoids if the spatial reference systems are georeferenced. Default value: true. |
Description
ST_SrEqual parses the semantics of both spatial reference systems and compares their projection methods, reference ellipsoids, and the long and short axes of the reference ellipsoids. Returns t if the systems are equivalent, or f if they differ.
Because the comparison is semantic rather than textual, ST_SrEqual can match an OGC WKT string against a PROJ.4 string that describes the same coordinate system.
Examples
Example 1: Compare an OGC WKT string against a PROJ.4 string
This example shows that ST_SrEqual recognizes WGS 84 expressed in OGC WKT format and in PROJ.4 format as the same spatial reference system.
SELECT ST_srEqual(
'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]]',
'+proj=longlat +datum=WGS84 +no_defs'
);Output:
st_srequal
------------
tExample 2: Look up the SRID for a given spatial reference system
Query the spatial_ref_sys table to find the SRID (spatial reference system identifier) that matches a PROJ.4 definition.
SELECT srid
FROM spatial_ref_sys
WHERE ST_srEqual(srtext::cstring, '+proj=longlat +ellps=GRS80 +no_defs ')
LIMIT 1;Output:
srid
------
3824