The ST_Intersects() function

The ST_Intersects() function returns t (TRUE) if the intersection of two geometries does not result in an empty set; otherwise, returns f (FALSE).

Syntax

ST_Intersects (g1 ST_Geometry, g2 ST_Geometry)

Usage

The following figure shows various geometric objects that intersect.
Figure 1: A selection of geometries that intersect

This graphic shows various geometric objects that intersect.

The results of the spatial relationship of the ST_Intersects() function can be understood or verified by comparing the results with a pattern matrix that represents the acceptable values for the DE-9IM. The ST_Intersects() function returns TRUE if the conditions of any of the following pattern matrices returns TRUE.

The ST_Intersects() function returns TRUE if the interiors of both geometries intersect.
Table 1. Pattern matrix for the ST_Intersects() function

The table is a matrix. The top row and first column identify the geometry.

Interior (b) Boundary (b) Exterior (b)
Interior (a) T * *
Boundary (a) * * *
Exterior (a) * * *
The ST_Intersects() function returns TRUE if the boundary of the first geometry intersects the boundary of the second geometry.
Interior (b) Boundary (b) Exterior (b)
Interior (a) * T *
Boundary (a) * * *
Exterior (a) * * *
The ST_Intersects() function returns TRUE if the boundary of the first geometry intersects the interior of the second.
Interior (b) Boundary (b) Exterior (b)
Interior (a) * * *
Boundary (a) T * *
Exterior (a) * * *
The ST_Intersects() function returns TRUE if the boundaries of either geometry intersect.
Interior (b) Boundary (b) Exterior (b)
Interior (a) * * *
Boundary (a) * T *
Exterior (a) * * *

Return type

BOOLEAN

Example

The fire marshal wants a list of sensitive areas within a 5-mile radius of a hazardous waste site.

The sensitive areas are stored in the following sensitive_areas table. The zone column is defined as an ST_Polygon type and stores the outline of the sensitive areas:
CREATE TABLE sensitive_areas (id     integer,
                              name   varchar(128),
                              size   float,
                              type   varchar(10),
                              zone   ST_Polygon);
The hazardous sites are stored in the hazardous_sites table that is created with the CREATE TABLE statement that follows. The location column, which is defined as an ST_Point type, stores the geographic center of each hazardous site:
CREATE TABLE hazardous_sites (site_id   integer,
                              name      varchar(40),
                              location  ST_Point);
The query returns a list of sensitive-area and hazardous-site names for sensitive areas that intersect the 5-mile buffer radius of the hazardous sites:
SELECT sa.name, hs.name
   FROM sensitive_areas sa, hazardous_sites hs
   WHERE ST_Intersects(ST_Buffer(hs.location,(5 * 5280)),sa.zone);


name  Johnson County Hospital
name  W. H. Kleenare Chemical Repository

name  Johnson County Hospital
name  Landmark Industrial

name  Summerhill Elementary School
name  Landmark Industrial