ST_Equals function

The ST_Equals function takes two geometries as input parameters and returns 1 if the geometries are equal. Otherwise 0 (zero) is returned. The order of the points used to define the geometry is not relevant for the test for equality.

If the second geometry is not represented in the same spatial reference system as the first geometry, it will be converted to the other spatial reference system.

If any of the two given geometries is null, then null is returned.

Syntax

Read syntax diagramSkip visual syntax diagramdb2gse.ST_Equals(geometry1,geometry2 )

Parameter

geometry1
A value of type ST_Geometry that represents the geometry that is to be compared with geometry2.
geometry2
A value of type ST_Geometry that represents the geometry that is to be compared with geometry1.

Return type

INTEGER

Examples

Example 1
This example creates two polygons that have their coordinates in a different order. ST_Equal is used to show that these polygons are considered equal.

SET CURRENT FUNCTION PATH = CURRENT FUNCTION PATH, db2gse
CREATE TABLE sample_geoms (id INTEGER, geometry ST_Geometry)

INSERT INTO sample_geoms VALUES
       (1, ST_Geometry('polygon((50 30, 30 30, 30 50, 50 50, 50 30))' ,0))

INSERT INTO sample_geoms VALUES
       (2, ST_Geometry('polygon((50 30, 50 50, 30 50, 30 30, 50 30))' ,0))


SELECT a.id, b.id, ST_Equals(a.geometry, b.geometry) Equals
FROM sample_geoms a, sample_geoms b
WHERE a.id = 1 and b.id = 2

Results:

ID          ID          EQUALS
----------- ----------- -----------
          1           2           1

 
Example 2
In this example, two geometries are created with the same X and Y coordinates, but different M coordinates (measures). When the geometries are compared with the ST_Equal function, a 0 (zero) is returned to indicate that these geometries are not equal.

SET CURRENT FUNCTION PATH = CURRENT FUNCTION PATH, db2gse
CREATE TABLE sample_geoms (id INTEGER, geometry ST_Geometry)

INSERT INTO sample_geoms VALUES
       (3, ST_Geometry('multipoint m(80 80 6, 90 90 7)' ,0))

INSERT INTO sample_geoms VALUES
       (4, ST_Geometry('multipoint m(80 80 6, 90 90 4)' ,0))


SELECT a.id, b.id, ST_Equals(a.geometry, b.geometry) Equals
FROM sample_geoms a, sample_geoms b
WHERE a.id = 3 and b.id = 4

Results:

ID          ID          EQUALS
----------- ----------- -----------
          3           4           0


Example 3
In this example, two geometries are created with a different set of coordinates, but both represent the same geometry. ST_Equal compares the geometries and indicates that both geometries are indeed equal.

SET current function path = current function path, db2gse
CREATE TABLE sample_geoms ( id INTEGER, geometry ST_Geometry )

INSERT INTO sample_geoms VALUES
   (5, ST_LineString('linestring ( 10 10, 40 40 )', 0)),
   (6, ST_LineString('linestring ( 10 10, 20 20, 40 40)', 0))

SELECT a.id, b.id, ST_Equals(a.geometry, b.geometry) Equals
FROM   sample_geoms a, sample_geoms b
WHERE  a.id = 5 AND b.id = 6

Results:

ID          ID          EQUALS
----------- ----------- -----------
          5           6           1