The ST_Disjoint() function

The ST_Disjoint() function takes two geometries and returns t (TRUE) if the two geometries are completely non-intersecting; otherwise, it returns f (FALSE).

Syntax

ST_Disjoint(g1 ST_Geometry, g2 ST_Geometry)

Usage

The following figure shows various geometric objects that do not touch each other.

Figure 1: Disjoint geometries

This graphic shows various geometric objects that do not touch each other.

The results of the spatial relationship of the ST_Disjoint() 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_Disjoint() function pattern matrix states that neither the interiors nor the boundaries of either geometry intersect.

Table 1. Pattern matrix for the ST_Disjoint() function

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

b
Interior Boundary Exterior
Interior F F *
a Boundary F F *
Exterior * * *

Return type

BOOLEAN

Example

An insurance company wants to assess the insurance coverage for the town's hospital, nursing homes, and schools. Part of this process includes determining the threat that the hazardous waste sites pose to each institution. Currently, the insurance company wants to consider only those institutions that are not at risk of contamination. The insurance company commissions a GIS consultant to locate all institutions that are outside a 5-mile radius of a hazardous waste storage facility.

The sensitive_areas table contains several columns that describe the threatened institutions in addition to the zone column, which stores the institutions' polygon geometries:
CREATE TABLE sensitive_areas (id     integer,
                              name   varchar(128),
                              size   float,
                              type   varchar(10),
                              zone   ST_Polygon);
The hazardous_sites table stores the identity of the sites in the site_id and name columns, The actual geographic location of each site is stored in the location point column:
CREATE TABLE hazardous_sites (site_id   integer,
                              name      varchar(40),
                              location  ST_Point);
The SELECT statement lists the names of all sensitive areas that are outside the 5-mile radius of a hazardous waste site:
SELECT sa.name
   FROM sensitive_areas sa, hazardous_sites hs
   WHERE ST_Disjoint(ST_Buffer(hs.location,(5 * 5280)), sa.zone);
You can also use the ST_Intersects() function to perform this query because ST_Intersects() and ST_Disjoint() return the opposite results:
SELECT sa.name
   FROM sensitive_areas sa, hazardous_sites hs
   WHERE NOT ST_Intersects(ST_Buffer(hs.location,(5 * 5280)), sa.zone);
The following figure shows that the nursing home is the only sensitive area for which the ST_Disjoint() function returns t (TRUE) when comparing sensitive sites to the 5-mile radius of the hazardous waste sites. The ST_Disjoint() function returns t whenever two geometries do not intersect in any way.
Figure 2: Sensitive Sites and Hazardous Waste Sites

This graphic is described in the surrounding text.