Skip to main content

1  Introduction to Spatial Data Science

NoteLearning objectives

By the end of this chapter you should be able to:

  1. Explain what spatial data science is, and how data become information, knowledge, and wisdom.
  2. Explain why location matters, with examples from several fields.
  3. Describe three ideas that make spatial data different from other data: spatial autocorrelation, scale, and spatial heterogeneity.
  4. Recognize a spatial data science question, and write one of your own.
  5. Describe the tools and the path this book follows.

This book is about answering questions with data that have a location attached. Where are thefts and burglaries concentrated in a town? Which neighborhoods are far from a hospital? How much forest was lost in the mountains after a hurricane? Questions like these come up in planning, public health, business, environmental science, and nearly every other field, and they share a common set of skills: finding the right data, turning it into useful information, and communicating what you found.

This first chapter steps back from the code to look at the big picture. It explains what spatial data science is, why location deserves special attention, and what kinds of questions you will be able to answer by the end of the book. Every later chapter fills in one part of that picture.

1.1 What this book will teach you

By the end of the book, you will be able to do three things:

  1. Use R to collect and manage spatial data.
  2. Turn spatial data into information, such as tables, statistics, and maps.
  3. Answer spatial data science questions.

Each of these builds on the one before it. You can’t make a useful map until you can load and clean the data behind it, and you can’t answer a question until you can turn raw data into something that speaks to it.

TipA word about math

Spatial data science uses statistics, and some chapters include formulas. Don’t let that put you off. The emphasis throughout is on what a method does and when to use it, and R does the arithmetic. If you can read a formula slowly and say in words what each part means, you have all the math you need.

1.2 What is spatial data science?

1.2.1 From data to wisdom

It helps to start with the word data itself, and with how it differs from the things we actually want from it. A common way to describe this is a ladder with four rungs (Figure 1.1).

  • Data are facts and figures: a column of numbers, a list of addresses, the pixel values of a satellite image.
  • Information is data organized so that it is useful: a table of average income by county, or a map of where those addresses fall.
  • Knowledge is information accumulated and integrated over time and across a broad range of situations: an understanding of why income varies the way it does, built from many studies of many places.
  • Wisdom is the application of principles, reason, and knowledge to discern what is true and right: deciding what a city should actually do about it.
flowchart LR
  A["Data<br/>facts and figures"] --> B["Information<br/>organized and useful"]
  B --> C["Knowledge<br/>integrated over time<br/>and situations"]
  C --> D["Wisdom<br/>judging what is<br/>true and right"]
Figure 1.1: The data–information–knowledge–wisdom ladder. Each step adds organization, context, and judgment. This book focuses on the first step: turning data into information.

Most of this book is about the first step, from data to information. That step is where code does the most work: no one can read a million rows of data, but anyone can read a well-made map or a short table that summarizes them. The later steps depend on people, but they can only be as good as the information they rest on.

1.2.2 Spatial, data, science

The name of the field is a good summary of what it involves. Each of its three words covers a different set of skills (Table 1.1).

Table 1.1: The three parts of spatial data science, and some of what each involves.
Spatial Data Science
Location Processing Research
Environmental data Organizing Structure
Satellite imagery Parsing Questioning
Demographics and the Census File formats Reporting
Transportation Databases Critiquing
Visualizing with maps and graphs

Spatial is about what we study: things that happen in places, measured by sources such as satellites, environmental sensors, the Census, and transportation networks. Data is about how we handle it: reading files in many formats, organizing and cleaning them, storing them, and visualizing them. Science is about why: asking a clear question, structuring an analysis to answer it, reporting the results, and critiquing them honestly, including your own.

1.3 Why does location matter?

Everything happens somewhere. From changes in trade policy to the spread of a disease, location is a fundamental attribute of almost everything we might want to study. Knowing where something happens often tells you a great deal about why it happens, and about who it affects. A few examples show how widely this applies:

  • Urban planning. Where should a city build new parks or schools so that the most people can reach them?
  • Environmental science. How does air or water pollution spread across a region from its sources?
  • Public health. Where are the hotspots of a disease outbreak, and what do those places have in common?
  • Business. Where should a company put its next store or warehouse, and how should goods move between them?
  • Social sciences. How are demographic trends, such as aging or migration, distributed across a country?

In each case, a table without locations would miss the point. The question is about place.

TipThink about it

How could you use spatial data science to understand the effects of a change in tariffs, the taxes a country charges on imported goods? What would you map? Which places might be affected most: ports, farming regions that export crops, towns built around one factory? What data would you need to find out?

1.4 The spatial data science workflow

Whatever the question, a spatial data science project moves through the same three stages (Figure 1.2).

flowchart LR
  Q["Question"] --> A["Get reliable data"]
  A --> B["Understand and<br/>process the data"]
  B --> C["Find patterns and<br/>communicate results"]
  C -.-> Q
Figure 1.2: The spatial data science workflow. A question leads to data, data must be processed before they can be analyzed, and results must be communicated. What you learn often raises a new question.
  1. Get reliable data. Whatever question you want to ask, the answer can only be as good as the data behind it. That means knowing where your data came from, who collected it and how, what each column means, and what is missing.
  2. Understand and process the data. Real data are rarely ready to use. They need to be read into R, cleaned, reshaped, joined to other data, and often given a location or put into the right coordinate system. This stage usually takes the most time.
  3. Find patterns and communicate the results. Look for patterns, relationships, and trends in the data, then present them in a way that answers your question. A clear map, table, or paragraph is the product of the whole project. Results that no one can understand might as well not exist.

The arrow back to the start of Figure 1.2 matters, too. Answering one question usually raises another, and good projects often loop through the workflow several times.

1.5 Spatial thinking

Much of traditional statistics, and much of data science, treats each observation as independent of the others: knowing one tells you nothing about the next. For data about places, that assumption is usually wrong. Spatial thinking means taking seriously how location connects observations. Three ideas come up again and again in this book.

1.5.1 Spatial autocorrelation

Spatial autocorrelation is the tendency for things that are close together to be more alike than things that are far apart. Neighboring homes tend to have similar values. Neighboring counties tend to have similar incomes, voting patterns, and rainfall. The geographer Waldo Tobler put it as what is now called the first law of geography: “everything is related to everything else, but near things are more related than distant things” (Tobler 1970).

Spatial autocorrelation is both a problem and an opportunity. It is a problem because standard statistical tests assume independence, and they can be badly overconfident when observations are really echoes of their neighbors. It is an opportunity because it is often exactly what we want to find: a cluster of high values is a hotspot, and hotspots are where to look first. Later chapters show how to measure it.

1.5.2 Scale

Scale is the level of detail you work at: individual addresses, neighborhoods, counties, states. A pattern that is clear at one scale can vanish, or even reverse, at another. A county can have a high average income while containing neighborhoods with very low incomes, and a trend across a whole city might not exist within any single neighborhood.

The way areas are drawn matters as well as their size. Grouping the same individual data into different sets of boundaries, such as different districts of the same size, can change the results of an analysis. This is known as the modifiable areal unit problem (Openshaw 1984). The practical lesson is to choose your scale deliberately, to match the question, and to be careful about drawing conclusions at one scale from data collected at another.

1.5.3 Spatial heterogeneity

Spatial heterogeneity means that relationships between variables can change from place to place. The link between, say, distance to downtown and home prices might be strong in one city and weak in another, or even differ between the east and west sides of the same city. A single number that summarizes a relationship for a whole region can hide those differences. Spatial data science often means asking not just “what is the relationship?” but “where is it strongest, and where does it break down?”

NoteThree questions to ask of any spatial data
  1. Are nearby values similar? (spatial autocorrelation)
  2. Would the pattern look different with larger or smaller areas? (scale)
  3. Does the relationship I’m studying hold everywhere, or only in some places? (spatial heterogeneity)

1.6 Our toolbox

This book uses the R programming language, written and run in RStudio. Both are free. On top of R, a few packages do most of the work:

Table 1.2: The main R packages used in this book.
Package What it does
tidyverse Reading, cleaning, reshaping, and summarizing data
sf Storing and working with spatial vector data: points, lines, and polygons
tmap Making maps quickly, with sensible defaults
Others Statistics, downloading data, and special tasks as they come up

The next chapter, R, RStudio, and R Markdown, introduces these tools and the R Markdown documents you will write your work in.

1.7 The road ahead

The course is organized in three units, each building on the last (Table 1.3).

Table 1.3: The three units of the course.
Unit Focus Topics
1 Getting started with data science Getting started with R; processing data with the tidyverse; exploring data for information; a map contest with tmap
2 Working with spatial data Overlaying two spatial layers; joining tables; spatial statistics; a map contest with online data
3 Spatial data science ANOVA; regression; clustering; a spatial data science project

Unit 1 builds general data skills: you learn to load, clean, summarize, and map data. Unit 2 adds what is special about spatial data: combining layers by location, joining tables, and measuring spatial patterns. Unit 3 brings it together with statistical methods for comparing groups, modeling relationships, and finding clusters, and ends with a project of your own.

1.8 What makes a spatial data science question?

A spatial data science question is one where location is part of the answer, and where data can settle it. Here are some examples from North Carolina. Notice the key word in each, which hints at the kind of analysis it needs.

Table 1.4: Examples of spatial data science questions.
Question Key idea Kind of analysis
Where are there higher clusters of theft and burglary in Chapel Hill? Where Mapping and cluster detection
Are incomes different between Durham and Raleigh? Difference Comparing groups (e.g., ANOVA)
What location factors contribute to housing prices in Charlotte? Factors Modeling relationships (regression)
How has forest cover changed in the Blue Ridge Mountains after Hurricane Helene? Change Comparing data over time
Which neighborhoods have less access to hospitals? Accessibility Distance and network analysis

Good questions have a few things in common. They are specific about what is being measured and where. They can be answered with data that exist, or that you can collect. And the answer would be useful to someone: a planner, a business, a public health department, or the people who live there.

TipThink about it

What is a spatial data science project you could do in your own field or area of interest? Spatial data science is used in business, computer science, environmental science, geography, geology, law, real estate, public health, the social sciences, urban planning, communications and journalism, government, transportation, and much more. Write your question down. You will come back to it at the end of the course.

1.9 Check your understanding

  1. Organizing raw facts and figures into a table of average income by county turns data into…

  2. The idea that near things are more related than distant things is called…

  3. A relationship between two variables that is strong in one city but weak in another is an example of…

  4. True or false: a trend you find at the county level is guaranteed to hold within each neighborhood of that county.

  5. Which R package in our toolbox is used to store and work with points, lines, and polygons?

Think about scale: a pattern at one level of detail can disappear, or reverse, at another.

1.10 Summary

  • Spatial data science uses data with locations to answer questions about the world. It combines the spatial (what we study), data skills (how we handle it), and science (how we ask and answer questions).
  • Data become information when they are organized to be useful. Information, accumulated and integrated, becomes knowledge, and knowledge applied with judgment becomes wisdom. This book focuses on turning data into information.
  • Everything happens somewhere, and location matters in planning, environmental science, public health, business, the social sciences, and beyond.
  • A project moves from a question to reliable data, to processing, to finding and communicating results, and often loops back to a new question.
  • Spatial data are rarely independent. Watch for spatial autocorrelation (near things are alike), scale (patterns change with the size and shape of areas), and spatial heterogeneity (relationships change from place to place).
  • Our tools are R and RStudio, with the tidyverse, sf, and tmap packages.

1.11 Exercises

  1. Data to information. Pick a dataset you use or have heard of, such as weather records, sports statistics, or campus enrollment. Describe one example each of data, information, knowledge, and wisdom based on it.
  2. Everything happens somewhere. Find a recent news story whose central question involves location. What is the question? What spatial data would you need to answer it, and where might you get them?
  3. Spatial thinking. For each of the three ideas in Section 1.5, give your own example of how it could affect an analysis of a topic you care about.
  4. Classify questions. For each question in Table 1.4, name one dataset you would need. Which questions need data from more than one time period?
  5. Your question. Write your own spatial data science question from the last Think about it box as one clear sentence. Underline its key word (where, different, factors, change, access, or another), and list the data you would need to answer it.

1.12 Further reading

  • Geocomputation with R by Robin Lovelace, Jakub Nowosad, and Jannes Muenchow, free at https://r.geocompx.org, is an excellent companion to this book for working with spatial data in R.
  • Spatial Data Science: With Applications in R by Edzer Pebesma and Roger Bivand, free at https://r-spatial.org/book/, is a deeper treatment by the authors of the sf package.
  • Waldo Tobler’s short paper that introduced the first law of geography (Tobler 1970) is still worth reading for its clear statement of why location matters.
Openshaw, Stan. 1984. The Modifiable Areal Unit Problem. Concepts and Techniques in Modern Geography 38. Geo Books.
Tobler, Waldo R. 1970. “A Computer Movie Simulating Urban Growth in the Detroit Region.” Economic Geography 46: 234–40. https://doi.org/10.2307/143141.