ST_EnvIntersects function
The ST_EnvIntersects function takes two geometries as input parameters and returns 1 if the envelopes of two geometries intersect. Otherwise, 0 (zero) is returned.
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 given geometries is null or is empty, then null value is returned.
Syntax
Parameter
- geometry1
- A value of type ST_Geometry or one of its subtypes that represents the geometry whose envelope is to be tested for intersection with the envelope of geometry2.
- geometry2
- A value of type ST_Geometry or one of its subtypes that represents the geometry whose envelope is to be tested for intersection with the envelope of geometry1.
Return type
INTEGER
Example
This example creates two parallel
linestrings and checks them for intersection. The linestrings themselves
do not intersect, but the envelopes for them do.
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('linestring (10 10, 50 50)',0))
INSERT INTO sample_geoms VALUES
(2, ST_Geometry('linestring (10 20, 50 60)',0))
SELECT a.id, b.id, ST_Intersects(a.geometry, b.geometry) Intersects,
ST_EnvIntersects(a.geometry, b.geometry) Envelope_Intersects
FROM sample_geoms a , sample_geoms b
WHERE a.id = 1 and b.id=2
Results:
ID ID INTERSECTS ENVELOPE_INTERSECTS
----------- ----------- ----------- -------------------
1 2 0 1