Hello! Welcome to the twelfth module of our course. We are now moving into the final and most practical part of our journey: Applied Spatial Analysis with GIS.
In our last lesson, we tackled the crucial concepts of coordinate systems. We learned that a Geographic Coordinate System (GCS) tells us where a feature is on the 3D Earth using latitude and longitude, while a Projected Coordinate System (PCS) tells us how to draw and measure that feature on a 2D map using linear units like meters.
Now that we understand how geographic data is structured, located, and displayed, we can start asking it questions. This is the heart of GIS analysis. Today's lesson is all about learning how to do just that. Our learning outcome is to perform attribute and spatial queries to select and filter geographic data. We will explore the two fundamental ways to interrogate our data: by its characteristics and by its location.
1. The Two Sides of GIS Data: Attributes and Spatial Information
Before we can query data, it's essential to remember that every feature on a GIS map has two components:
- Spatial Data: Its geometry and location on the Earth (a point, line, or polygon).
- Attribute Data: A table of descriptive information linked to that geometry.
Think of a map of world cities. Each city is a point (spatial data). That point is linked to a row in a table containing its name, population, country, and whether it's a capital city (attribute data).

A query is simply a structured question we ask of our data to find and select features that meet specific criteria. In GIS, these questions fall into two main categories: attribute queries and spatial queries.
2. Attribute Queries: Asking "What"
An attribute query selects features based on their values in the attribute table. It's how we ask questions about the characteristics of our data.
Examples:
- "Show me all cities with a population greater than 5 million."
- "Find all countries in the continent of Africa."
- "Select all roads classified as 'highways'."
Most GIS software uses a language called Structured Query Language (SQL) to build these queries. While SQL can be complex, for basic queries we only need to understand a simple structure, much like forming a sentence. The most important part is the WHERE clause, which specifies the condition for selection.
The structure looks like this:SELECT features FROM [Layer] WHERE [Condition]
For example: SELECT * FROM Cities WHERE "population" > 5000000
The following video provides an excellent introduction to the concept of queries and demonstrates how to perform a "Select by Attribute" in a GIS environment.
Spatial Queries, Table Joins, and Relates: A Technical Video Lecture
The video 'Spatial Queries, Table Joins, and Relates' by GIScience introduces the fundamental idea of a query, explains basic SQL statements, and demonstrates how to build an attribute query.
Please watch two segments from this video: 00:00 – 03:55: This part explains what a query is and introduces the concept of SQL and the WHERE clause. 05:01 – 09:47: This is a practical demonstration of an attribute query. Pay attention to how the presenter builds an expression to select all counties in New York State (STATE = 'NY').
To see this process in another popular GIS software (QGIS) and reinforce the steps, the following tutorial walks through the same concept. It shows how you can combine multiple conditions using operators like AND.
Working with Attributes (QGIS3)
The tutorial 'Working with Attributes (QGIS3)' provides a step-by-step guide to building attribute queries. It clearly shows how to combine criteria to ask more complex questions.
Read through the tutorial, focusing on the 'Procedure' section. Follow the steps where the author first selects cities with a population greater than 1 million ("pop_max" > 1000000) and then refines the query to also include only capital cities ("adm0cap" = 1). This demonstrates how to use the AND operator.
3. Spatial Queries: Asking "Where"
A spatial query (or "select by location") selects features based on their geographic relationship to other features. It's how we ask questions about location, proximity, and containment.
Examples:
- "Show me all schools that are within the city of Delhi."
- "Find all rivers that intersect (cross) the state of Punjab."
- "Select all properties that are within 500 meters of a proposed highway."

Spatial queries rely on spatial relationships (sometimes called predicates) to work. The most common ones are:
- Intersect: Selects features that touch, cross, or overlap in any way.
- Contains / Are Within: Selects features that are entirely inside another feature.
Containsis the inverse ofAre Within. (e.g., A state contains its cities; cities are within the state). - Touches: Selects features whose boundaries meet but do not overlap. (e.g., Finding all countries that border France).
- Within a distance of: Selects features that are within a specified distance of another feature. This is a proximity query and is fundamental to buffer analysis, which we'll cover in the next lesson.
This next video gives a fantastic, clear demonstration of performing spatial queries.
Performing a spatial query in ArcGIS Pro
The video 'Performing a spatial query in ArcGIS Pro' from CWU Geography clearly demonstrates two of the most common types of spatial queries.
Please watch the entire video. Notice the two distinct examples: Selecting counties that intersect with highways. Selecting cities that are within a distance of 2 miles from highways.
Just like attribute queries have SQL, spatial queries also have specific commands. While they are often handled by user-friendly tools in GIS software, it's useful to know they exist. This article introduces the concept of "Spatial Predicates," which are the SQL-like functions for spatial queries (e.g., ST_INTERSECTS, ST_CONTAINS).
How to SQL: a Guide for GIS Users
The article 'How to SQL: a Guide for GIS Users' provides a deeper look at the commands behind spatial queries. This will help you understand what the GIS is doing 'under the hood.'
Please read the section titled 'Select/filter by location'. Focus on understanding the list of common spatial predicates (ST_INTERSECTS, ST_CONTAINS, ST_DWITHIN, etc.) and what each one means. You don't need to memorize the code, just grasp the concepts.
Test your understanding!
You are a geographer working for an environmental agency. A new national park has been created. Your manager gives you two tasks:
- From a global dataset of all protected areas, you need to create a layer that contains only the new national park, which is named "Himalayan Nature Reserve".
- Once you have isolated the park's boundary, you need to identify all the villages from a national census dataset that are located inside the park's boundary.
Which type of query would you use for each task?
Show answer
-
Task 1: You would use an attribute query. You would select from the "protected areas" layer
WHERE "name" = 'Himalayan Nature Reserve'. This query filters the data based on a value in the attribute table (the name). -
Task 2: You would use a spatial query. You would select all features from the "villages" layer that are within the boundary of the "Himalayan Nature Reserve" layer you created in the first step. This query filters the data based on the geographic location of the villages relative to the park's polygon.
Conclusion
You have just learned one of the most fundamental skills in GIS. The ability to query and filter massive datasets is the first step in turning raw data into meaningful information. By combining attribute and spatial queries, you can answer complex geographical questions and uncover patterns that would be invisible otherwise.
Key Takeaways:
- Queries are structured questions used to select features from a dataset.
- Attribute Queries filter data based on its descriptive information stored in the attribute table (e.g., name, population, type). They are often built using SQL
WHEREclauses. - Spatial Queries filter data based on its geographic relationship to other data (e.g., intersects, contains, within a distance).
- Mastering both query types is essential for any form of spatial analysis.
Preview of the Next Lesson:
In this lesson, we briefly touched upon the "within a distance of" spatial query. Our next lesson, Apply proximity analysis (buffering) to solve basic spatial problems, will expand on this concept significantly. We will learn how to not just select features within a certain distance, but to create a new polygon feature—a buffer—that represents this proximity zone. This is a powerful tool used in everything from urban planning to ecological conservation.