Getting started

Understanding spatial relations

A primary function of a geographic information system is determining the spatial relationships between features. The distance separating a hazardous waste disposal site and hospital, school, or housing development is an example of a spatial relationship.

Predicates are Boolean functions that return TRUE if a test passes and FALSE, otherwise, to determine if a specific relationship exists between a pair of geometries. Other functions return a value as a result of a spatial relationship. The result returned by the distance function, the space separating two geometries, is a double precision number. Alternatively, functions like intersection return a geometry as the result of combining two geometries.

Predicates

Predicates return t (TRUE) if a comparison meets the functions criteria; otherwise, they return f (FALSE). Predicates that test for a spatial relationship compare pairs of geometry that can be a different type or dimension.

Predicates compare the X and Y coordinates of the submitted geometries. The Z coordinates and measure values, if they exist, are ignored. Geometries that have Z coordinates or measures can be compared with those that dont.

The Dimensionally Extended 9 Intersection Model (DE-9IM) developed by Clementini, et al., dimensionally extends the 9 Intersection Model of Egenhofer and Herring. DE-9IM is a mathematical approach that defines the pair-wise spatial relationship between geometries of different types and dimensions. This model expresses spatial relationships among all types of geometry as pair-wise intersections of their interior, boundary, and exterior with consideration for the dimension of the resulting intersections.

Given geometries a and b, I(a), B(a), and E(a) represent the interior, boundary, and exterior of a, and I(b), B(b), and E(b) represent the interior, boundary, and exterior of b. The intersections of I(a), B(a), and E(a) with I(b), B(b), and E(b) produces a 3-by-3 matrix. Each intersection can result in geometries of different dimensions. For example, the intersection of the boundaries of two polygons could consist of a point and a linestring, in which case the dim function would return the maximum dimension of 1.

The dim function returns a value of -1, 0, 1, or 2. The -1 corresponds to the null set that is returned when no intersection was found or dim().

                                Interior                          Boundary                       Exterior

Interior                     dim(I(a)I(b))                  dim(I(a)B(b))                 dim(I(a)E(b))

Boundary                dim(B(a)I(b))                 dim(B(a)B(b))               dim(B(a)E(b))

Exterior                    dim(E(a)I(b))                 dim(E(a)B(b))               dim(E(a)E(b))

 

The results of the spatial relationship predicates can be understood or verified by comparing the results of the predicate with a pattern matrix that represents the acceptable values for the DE-9IM.

The pattern matrix contains the acceptable values for each of the intersection matrix cells. The possible pattern values are

TAn intersection must exist; dim = 0, 1, or 2.
FAn intersection must not exist; dim = -1.
*It does not matter if an intersection exists or not; dim = -1, 0, 1, or 2.
0An intersection must exist and its maximum dimension must be 0; dim = 0.
1An intersection must exist and its maximum dimension must be 1; dim = 1.
2An intersection must exist and its maximum dimension must be 2; dim = 2.

Each predicate has at least one pattern matrix, but some require more than one to describe the relationships of various geometry type combinations.

The pattern matrix of the within predicate for geometry combinations has the following form:

 

 

 

b

 

 

 

Interior

Boundary

Exterior

 

Interior

T

*

F

a

Boundary

*

*

F

 

Exterior

*

*

*

Simply put, the within predicate returns true when the interiors of both geometries intersect, and the interior and boundary of a does not intersect the exterior of b. All other conditions do not matter.

Equal

Equal returns t (TRUE) if two geometries of the same type have identical X,Y coordinate values.

Geometries are equal if they have matching X,Y coordinates.

The DE-9IM pattern matrix for equality ensures that the interiors intersect and that no part
interior or boundary of either geometry intersects the exterior of the other.

 

 

 

b

 

 

 

Interior

Boundary

Exterior

 

Interior

T

*

F

a

Boundary

*

*

F

 

Exterior

F

F

*

 

Disjoint

Disjoint returns t (TRUE) if the intersection of the two geometries is an empty set.

Geometries are disjoint if they do not intersect one another in any way.

The disjoint predicates pattern matrix simply states that neither the interiors nor the boundaries of either geometry intersect.

 

 

 

b

 

 

 

Interior

Boundary

Exterior

 

Interior

F

F

*

a

Boundary

F

F

*

 

Exterior

*

*

*

 

Intersects

Intersects returns t (TRUE) if the intersection does not result in an empty set. Intersects returns the exact opposite result of disjoint.

The intersects predicate will return TRUE if the conditions of any of the following pattern matrices returns TRUE.

The intersects predicate returns TRUE if the interiors of both geometries intersect.

 

 

 

b

 

 

 

Interior

Boundary

Exterior

 

Interior

T

*

*

a

Boundary

*

*

*

 

Exterior

*

*

*

 

The intersects predicate returns TRUE if the boundary of the first geometry intersects the boundary of the second geometry.

 

 

 

b

 

 

 

Interior

Boundary

Exterior

 

Interior

*

T

*

a

Boundary

*

*

*

 

Exterior

*

*

*

 

The intersects predicate returns TRUE if the boundary of the first geometry intersects the
interior of the second.

 

 

 

b

 

 

 

Interior

Boundary

Exterior

 

Interior

*

*

*

a

Boundary

T

*

*

 

Exterior

*

*

*

 

The intersects predicate returns TRUE if the boundaries of either geometry intersect.

 

 

 

b

 

 

 

Interior

Boundary

Exterior

 

Interior

*

*

*

a

Boundary

*

T

*

 

Exterior

*

*

*

 

Touch

Touch returns t (TRUE) if none of the points common to both geometries intersect the interiors of both geometries. At least one geometry must be a linestring, polygon, multilinestring, or multipolygon.

Touch returns TRUE if either of the geometrys boundaries intersect or if only one of the geometrys
interiors intersects the others boundary.

The pattern matrices show us that the touch predicate returns TRUE when the interiors of the geometry dont intersect and the boundary of either geometry intersects the others interior or boundary.

The touch predicate returns TRUE if the boundary of one geometry intersects the interior of the
other but the interiors do not intersect.

 

 

 

b

 

 

 

Interior

Boundary

Exterior

 

Interior

F

T

*

a

Boundary

*

*

*

 

Exterior

*

*

*

 

The touch predicate returns TRUE if the boundary of one geometry intersects the interior of the
other but the interiors do not intersect.

 

 

 

b

 

 

 

Interior

Boundary

Exterior

 

Interior

F

*

*

a

Boundary

T

*

*

 

Exterior

*

*

*

 

The touch predicate returns TRUE if the boundaries of both geometries intersect but the interiors do not.

 

 

 

b

 

 

 

Interior

Boundary

Exterior

 

Interior

F

*

*

a

Boundary

*

T

*

 

Exterior

*

*

*

 

Overlap

Overlap compares two geometries of the same dimension and returns t (TRUE) if their intersection set results in a geometry different from both but of the same dimension.

Overlap returns t (TRUE) only for geometries of the same dimension and only when their intersection set results in a geometry of the same dimension. In other words, if the intersection of two polygons results in polygon, then overlap returns t (TRUE).

This pattern matrix applies to polygon/polygon, multipoint/multipoint and multipolygon/multipolygon overlays. For these combinations the overlap predicate returns TRUE if the interior of both geometries intersects the others interior and exterior.

 

 

 

b

 

 

 

Interior

Boundary

Exterior

 

Interior

T

*

T

a

Boundary

*

*

*

 

Exterior

T

*

*

This pattern matrix applies to linestring/linestring and multilinestring/multilinestring overlaps. In this case the intersection of the geometries must result in a geometry that has a dimension of 1 (another linestring). If the dimension of the intersection of the interiors had resulted in 0 (a point) the overlap predicate would return FALSE; however, the cross predicate would have returned TRUE.

 

 

 

b

 

 

 

Interior

Boundary

Exterior

 

Interior

1

*

T

a

Boundary

*

*

*

 

Exterior

T

*

*

 

Cross

Cross returns t (TRUE) if the intersection results in a geometry whose dimension is one less than the maximum dimension of the two source geometries and the intersection set is interior to both source geometries. Cross returns t (TRUE) for only multipoint/polygon, multipoint/linestring, linestring/linestring, linestring/polygon, and linestring/multipolygon comparisons.

 

Cross returns t (TRUE) if the dimension of the intersection is one less than the maximum dimension of the source geometries and the interiors of both geometries are intersected.

This cross predicate pattern matrix applies to multipoint/linestring, multipoint/multilinestring, multipoint/polygon, multipoint/multipolygon, linestring/polygon, and linestring/multipolygon. The
matrix states that the interiors must intersect and that at least the interior of the primary (geometry a)
must intersect the exterior of the secondary (geometry b).

 

 

 

b

 

 

 

Interior

Boundary

Exterior

 

Interior

T

*

T

a

Boundary

*

*

*

 

Exterior

*

*

*

 

This cross predicate matrix applies to linestring/linestring, linestring/multilinestring, and multilinestring/multilinestring. The matrix states that the dimension of the intersection of the interiors
must be 0 (intersect at a point). If the dimension of this intersection was 1 (intersect at a linestring) the
cross predicate would return FALSE but the overlap predicate would return TRUE.

 

 

 

b

 

 

 

Interior

Boundary

Exterior

 

Interior

0

*

*

a

Boundary

*

*

*

 

Exterior

*

*

*

 

Within

Within returns t (TRUE) if the first geometry is completely within the second geometry. Within tests for the exact opposite result of contains.

Within returns t (TRUE) if the first geometry is completely inside the second geometry. The boundary and interior of the first geometry are not allowed to intersect the exterior of the second geometry and the first geometry may not equal the second geometry.

The within predicate pattern matrix states that the interiors of both geometries must intersect and that the interior and boundary of the primary geometry (geometry a) must not intersect the exterior of the secondary (geometry b).

 

 

 

b

 

 

 

Interior

Boundary

Exterior

 

Interior

T

*

F

a

Boundary

*

*

F

 

Exterior

*

*

*

 

Contains

Contains returns t (TRUE) if the second geometry is completely contained by the first geometry. The contains predicate returns the exact opposite result of the within predicate.

Contains returns t (TRUE) if the second geometry is completely inside the first. The boundary and interior of the second geometry are not allowed to intersect the exterior of the first geometry and the geometries may not be equal.

The pattern matrix of the contains predicate states that the interiors of both geometries must intersect and that the interior and boundary of the secondary (geometry b) must not intersect the exterior of the primary (geometry a).

 

 

 

b

 

 

 

Interior

Boundary

Exterior

 

Interior

T

*

*

a

Boundary

*

*

*

 

Exterior

F

F

*

Minimum distance

The minimum distance separating disjoint features could represent the shortest distance an aircraft must travel between two locations. The distance function reports the minimum distance separating two disjoint features. If the features arent disjoint the function will report a zero minimum distance.

Intersection of geometries

The intersection function returns the intersection set of two geometries. The intersection set is always returned as a collection that is the minimum dimension of the source geometries. For example, for a linestring that intersects a polygon, the intersection function returns that portion of the linestring common to the interior and boundary of the polygon as a multilinestring. The multilinestring contains more than one linestring if the source linestring intersected the polygon with two or more discontinuous segments. If the geometries do not intersect or if the intersection results in a dimension less than both source geometries, an empty geometry is returned. The following figure illustrates some examples of the intersection function.

The intersection function returns the intersection set as the geometry that is the minimum dimension of the source geometries.

Difference of geometries

The difference function returns the portion of the primary geometry that isnt intersected by the secondary geometrythe logical AND NOT of space. The difference function only operates on geometries of like dimension and returns a collection that has the same dimension as the source geometries. In the event that the source geometries are equal, an empty geometry is returned.

Difference returns that portion of the first geometry that is not intersected by the second.

Union of geometries

The union function returns the union set of two geometriesthe Boolean logical OR of space. The source geometries must have the same dimension. Union always returns the result as a collection.

Union returns the union set of two geometries.

Symmetric difference of geometries

The symmetricdiff function returns the symmetric difference of two geometriesthe logical XOR of space. The source geometries must have the same dimension. If the geometries are equal, the symmetricdiff function returns an empty geometry; otherwise, the function returns the result as a collection.

Symmetricdiff returns the portions of the source geometries that are not part of the intersection set. The source geometries must be of the same dimension.