ST_EnvIntersects function

The ST_EnvIntersects function takes two geometries of the same spatial reference system as input parameters and returns 1 if the envelopes of the 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, the routine will return -1. The geometries must be converted into the same spatial reference system to determine the relation, see ST_Transform.

If any of the specified geometries is null or is empty, then the null value is returned.

Syntax

Read syntax diagramSkip visual syntax diagramST_EnvIntersects(geometry1,geometry2 )

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.

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