3.1 Introduction

Attribute data is non-spatial information associated with geographic (geometry) data.A bus stop provides a simple example: its position would typically be represented by latitude and longitude coordinates (geometry data), in addition to its name.The name is an attribute of the feature (to use Simple Features terminology) that bears no relation to its geometry.

Another example is the elevation value (attribute) for a specific grid cell in raster data.Unlike the vector data model, the raster data model stores the coordinate of the grid cell indirectly, meaning the distinction between attribute and spatial information is less clear.To illustrate the point, think of a pixel in the 3rd row and the 4th column of a raster matrix.Its spatial location is defined by its index in the matrix: move from the origin four cells in the x direction (typically east and right on maps) and three cells in the y direction (typically south and down).The raster’s resolution defines the distance for each x- and y-step which is specified in a header.The header is a vital component of raster datasets which specifies how pixels relate to geographic coordinates (see also Chapter 4).

The focus of this chapter is manipulating geographic objects based on attributes such as the name of a bus stop and elevation.For vector data, this means operations such as subsetting and aggregation (see Sections 3.2.1 and 3.2.2).These non-spatial operations have spatial equivalents:the [ operator in base R, for example, works equally for subsetting objects based on their attribute and spatial objects, as we will see in Chapter 4.This is good news: skills developed here are cross-transferable, meaning that this chapter lays the foundation for Chapter 4, which extends the methods presented here to the spatial world.Sections 3.2.3 and 3.2.4 demonstrate how to join data onto simple feature objects using a shared ID and how to create new variables, respectively.

Raster attribute data operations are covered in Section 3.3, which covers creating continuous and categorical raster layers and extracting cell values from one layer and multiple layers (raster subsetting).Section 3.3.2 provides an overview of ‘global’ raster operations which can be used to characterize entire raster datasets.