Spatial relationships

A GIS works with data whose location is known. This means we can use Tobler's first law of geography ‘Everything is related with everything, but near things are more related than distant things’ to discover how objects relate to each other in space. The predicates used to describe those relationships are known as Spatial relantionships.

The structure of a geometry

In order to take full advantage of the spatial relantionships predicates, we have to understand how a geometry is stored in a GIS system To do that we have to understand that every geometry as an exterior, and interior and a boundary (Fig. 5). The importance of these concepts will become clearer ahead.

vector_data_model

Fig. 5 The boundary, interior and exterior of polygons, lines and points.

Types of spatial relationships

The most generic spatial relantionship is the intersection, defined as any space shared by two geometries. This means counter intuitive results like the intersection between two polygons returning a point is a possibility. All the other spatial relationships are specific types of intersection.

Table 1 Overview of spatial relationships

relationship

definition

overlap

A and B are the same type of geometry and A is not within B

touch

A and B intersect only at the boundary

cross

A shares a part of its interior with the interior of B

within

The interior of A is inside B.

contain

The contrary of within: if A is within B then B contains A.

equal

A and B are equal if they occupy exactly the same space

disjoint

A and B do not share space (do not intersect)

Attention

Spatial relationships must not be confused with overlay operations. The former are primarily a logical test, while the latter consist of geoprocessing operations that produce a new dataset resulting from overlaying two datasets. This overlay may be based on a spatial relationship though.

Exercise

Resources

For this exercise you will need this dataset. The dataset contains the following layers:
  • spatial_relationships.qgs a QGIS project preloading a geopackage containing the following layers:

    • lines (just some lines)

    • points (just some points)

    • polygons (just some polygons)

  1. Task Open the QGIS project and observe the map. WITHOUT using the software, try to fill in the table below keeping in mind the definitions given in Table 1.

Table 2 Spatial relationships outcomes

Relationship

Outcome

Points intersecting polygons

Point A and Point B

Points touching lines

Lines crossing polygons

Points within polygons

Points overlapping polygons

Points disjointed from lines

Polygons touching lines

Lines touching polygons

Polygons containing points

  1. Task From the Processing toolbox use the Select by location (Fig. 6) tool to verify your answers.

vector_data_model

Fig. 6 The select by location tool