Querying based on Spatial Relationships

This tutorial covers selecting features in a dataset based on their location relative to other features.

Included in this tutorial:

  • Select Within Distance

  • Select by Location

Software version in examples: QGIS-LTR 3.40.5-Bratislava

Tutorial Data: The tutorial includes demonstration with sample data available here.

Credits: Sally Kaye and L. Meisterlin (2025)

We include two different tools from Vector Selection: 

  • The Select within Distance tool executes a spatial query based on linear distance between features.

  • The Select by Location tool will execute a spatial query based on several other geographic relationships.

 

Select Within Distance

Access the Select Within Distance tool by clicking the arrow next to the Select by Location icon.

TIP: The dialogue box is designed to be read mostly like a sentence. You want to “Select features from [one layer] by comparing to the features from [another layer], where the features are within [a specific distance].”

This example demonstrates creating a new selection of features within the Points1_Table1_join layer that are within 500 feet of a subway entrance (represented by the layer subway_entrances).

The tool’s parameters and how their use in our demonstration are described below:

  • Using the dropdown menu, choose the layer to Select features from (Points1_Table1_join).

  • Then, choose the layer to compare features to (subway_entrances) from the dropdown menu under By comparing to the features from.

  • Specify the distance and units from the target layer to selecting features under Where the features are within. For this example, type “500” in the text box and select “feet” from the dropdown menu. 

accessing other selection options in the Select by Distance dialogue box

As with Interactive Selection and Selection by Attributes, you have the option to Modify current selection by either creating a new selection (which will clear any existing selections within your layer) or adding to, selecting within, or subtracting from the current selection.

Click Run to complete selection and close the Select Within Distance dialogue box.

accessing and using Select Within Distance


Select by Location 

To select based on other spatial relationships besides distance, access the Select by Location dialogue by clicking the icon in the Selection Toolbar. These spatial relationships available for executing a query include intersect, contain, disjoint, equal, touch, overlap, are within, and cross.

TIP: Again, this dialogue box is designed to be read mostly like a sentence. You want to “Select features from [one layer] where the features [intersect, touch, overlap, are within, etc] the features from [another layer].”

This example demonstrates selecting features from Points1_Table1_join that are within polygons from the Blocks_prj layer.

  • As described above in Select Within Distance, use the dropdown menu to Select features from Points1_Table1_join.

  • The default spatial relationship (or “geometric predicate”) in Select by Location is intersect. Uncheck this option and check “are within.” 

  • Using the dropdown menu, choose to compare points to features from Blocks_prj.

Click Run to complete selection and close the Select by Location dialogue box.

accessing and using Select by Location

In this example, 799 of the 800 points in the Points1_Table1_join layer are selected based on the criteria of falling within polygons from Blocks_prj; 1 point is not within the bounds of the block polygons.

 
Previous
Previous

Querying by Attributes

Next
Next

Creating a New Layer from Selected Features