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. 6). The importance of these concepts will become clearer ahead.
Fig. 6 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.
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. |
contains |
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.
Resources
spatial_relationships.qgz a QGIS project preloading a geopackage containing the following layers:
lines (just some lines)
points (just some points)
polygons (just some polygons)
Task Open the QGIS project and observe the map. WITHOUT using the software, try to fill in Table 2 keeping in mind the definitions given in Table 1.
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 |
… |
Task From the
Processing toolboxuse theSelect by location(Fig. 7) tool to verify your answers.
Fig. 7 Select by location¶
Joins¶
Resources
For this exercise you need to download this dataset. The dataset contains the following layers:
dorset_cadaster.qgz a QGIS project preloading a geopackage containing the following layers:
roads (road network)
water_plan (area a water management plan where special provisions may apply)
power_cable_(plan) (proposed route for a high voltage aereal cable)
parcels (the cadaster)
land_use (land uses as of 2015)
parish (admninistrative boundary of the parishes within the Dorset municipality - Tasmania)
party (fictional list of parties)
building (empty layer of type polygon)
topographic_map (a sample topographic map generated from Open Street Map)
building_type (fictional list of types of buildings)
In additon to the project and respective datasets, there are also folders with auxiliary files the exercise may refer to.
Often the information we need is scattered through more that one table. when that happens we have to resort to joins. There are two types of joins: the join by attribute and the join by location.
A join simply binds information together based on a common attribute. To demonstrate this idea, we will first perform a join by attribute
Task Go to the layer properties
parcelslayer, and under theJoinstab, define a join as illustrated in (Fig. 8).
Fig. 8 Join by attributes¶
After defining this join, if you open the attribute table of the layer parcels, you should observe that it now has three extra attributes (Fig. 9).
Fig. 9 Attribute table after the Join by attributes¶
Sometimes there is no common attribute that allows a direct link between datasets. When that happens, using a spatial join might be an option
Now that you are more familiar with the types of spatial relationships, try to use Join attributes by location tool from the Processing toolbox to perform spatial joins.
Task Considering the spatial problems formulated in Table 3, complete the table with your solutions
Problem formulation |
Type of spatial join |
Rationale |
|---|---|---|
Add to the attribute table of parcels, the parish they belong to |
based on ‘within’ + ‘one to many’ |
In principle parcels will fall inside an administrative area. |
Add the land use type to the attribute table of the roads |
… |
… |
Add the land use type to the attribute table of the parcels |