EnvelopesIntersect function
Use the EnvelopesIntersect function to determine whether two geometries intersect or a geometry instersect with an envelop defined by the four type DOUBLE values.
EnvelopesIntersect accepts two types of input parameters:
- Two geometries
EnvelopesIntersect returns 1 if the envelope of the first geometry intersects the envelope of the second geometry. Otherwise, 0 (zero) is returned.
- A geometry, four type DOUBLE coordinate values that define the
lower-left and upper-right corners of a rectangular window, and the
spatial reference system identifier.
EnvelopesIntersect returns 1 if the envelope of the first geometry intersects with the envelope defined by the four type DOUBLE values. Otherwise, 0 (zero) is returned.
Syntax
Parameters
- 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 either geometry2 or the rectangular window defined by the four type DOUBLE values.
- 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.
- x_min
- Specifies the minimum X coordinate value for
the envelope. You must specify a non-null value for this parameter.
The data type of this parameter is DOUBLE.
- y_min
- Specifies the minimum Y coordinate value for
the envelope. You must specify a non-null value for this parameter.
The data type of this parameter is DOUBLE.
- x_max
- Specifies the maximum X coordinate
value for the envelope. You must specify a non-null value for this
parameter.
The data type of this parameter is DOUBLE.
- y_max
- Specifies the maximum Y coordinate
value for the envelope. You must specify a non-null value for this
parameter.
The data type of this parameter is DOUBLE.
- srs_id
- Uniquely identifies the spatial reference system. The spatial
reference system identifier must match the spatial reference system
identifier of the geometry parameter. You must specify a non-null
value for this parameter.
The data type of this parameter is INTEGER.
Return type
INTEGER
Example
This example creates two polygons
that represent counties and then determines if any of them intersect
a geographic area specified by the four type DOUBLE values.
SET CURRENT FUNCTION PATH = CURRENT FUNCTION PATH, db2gse
CREATE TABLE counties (id INTEGER, name CHAR(20), geometry ST_Polygon)
INSERT INTO counties VALUES
(1, 'County_1', ST_Polygon('polygon((0 0, 30 0, 40 30, 40 35,
5 35, 5 10, 20 10, 20 5, 0 0))' ,0))
INSERT INTO counties VALUES
(2, 'County_2', ST_Polygon('polygon((15 15, 15 20, 60 20, 60 15,
15 15))' ,0))
INSERT INTO counties VALUES
(3, 'County_3', ST_Polygon('polygon((115 15, 115 20, 160 20, 160 15,
115 15))' ,0))
SELECT name
FROM counties as c
WHERE EnvelopesIntersect(c.geometry, 15, 15, 60, 20, 0) =1
Results:
Name
--------------------
County_1
County_2
