Studio Matrx Monthly · Volume 1 · Issue 3 · August 2026
Amogh N P
 In loving memory of Amogh N P — Architect · Designer · Visionary 
Spatial Queries & Select by LocationLesson 4.3
GIS for Architecture, Planning & Urban Design/Module 4 · Vector Spatial Analysis

Lesson 4.3 · Vector Spatial Analysis

Spatial Queries & Select by Location

Asking the map a precise question and getting exactly those features back

12 min Interactive lessonFree · open lessonByAmogh N P· Architect & interior designer
The hook

You do not want the whole layer. You want the forty plots that break the rule.

The authority's brief is exact: find every commercial plot within 100 m of a school, because a new licence rule applies to them. Your data has forty thousand plots and three hundred schools. You are not going to click through them - you are going to ask. A spatial query is how you turn a sentence like that into a selection the GIS makes for you in seconds, and it is the skill that separates browsing a map from interrogating one.

A query is a sentence. If you can say it in plain words, you can build it.

Attribute queries: selecting by what a feature is

The first way to select is by the attribute table - by the facts in the columns, ignoring geography entirely. You write a condition and the GIS highlights every row (and its shape) that satisfies it. The language is essentially SQL's WHERE clause: land_use = 'commercial', or population > 20000, or road_class = 'arterial' AND lanes >= 4.

This is the fastest, cheapest kind of query, and often the first move even in a spatial problem - narrow the layer to the features worth testing before you do any geometry. Two habits save grief: quote text values ('commercial') but not numbers, and be deliberate with AND versus OR. A AND B returns only rows meeting both; A OR B returns rows meeting either, which is almost always a bigger set than beginners expect. An attribute query is a question about the table; it does not know or care where anything is.

Attribute query (by the table)iduse1resi2park3commuse = 'park'Spatial query (by location)schoolselect plots WITHIN 500 m of a school
Zoom
Two ways to select: an attribute query works from the table (use = 'park'); a spatial query works from location (plots within 500 m of a school).

Text in quotes, numbers bare. Half of all broken queries are a missing quote mark.

Select by location: selecting by where a feature sits

The second way is what makes GIS special: select by location picks features in one layer based on their spatial relationship to features in another. Select plots that fall inside a ward. Select bus stops that lie on an arterial road. Select buildings that touch a flood polygon. No shared ID, no common column - the relationship is pure geometry.

This is different from overlay (Lesson 4.2) in an important way: select by location does not create new geometry. It leaves both layers untouched and simply flags the features in the target layer that satisfy the relationship. You get a selection you can then export, count, or refine - not a cut-up new layer. When your question is 'which existing features qualify?', select by location is lighter and cleaner than an intersect.

Attribute query (by the table)iduse1resi2park3commuse = 'park'Spatial query (by location)schoolselect plots WITHIN 500 m of a school
Zoom
Two ways to select: an attribute query works from the table (use = 'park'); a spatial query works from location (plots within 500 m of a school).

The predicates: the exact words for 'related in space'

'Where they sit' has to be made precise, and GIS does it with a small vocabulary of spatial predicates - the exact relationship you are testing:

- Intersects - the two features touch or overlap in any way at all. The most permissive, and a safe default when you are unsure. - Within - feature A lies entirely inside feature B (a plot within a ward). - Contains - the mirror of within: feature B holds A inside it (a ward contains a plot). - Touches - they share only a boundary, no interior (two adjacent plots). - Crosses / Overlaps - partial passage or partial overlap.

Within and contains are the same relationship read from opposite ends, which is a frequent source of confusion - keep straight which layer is your target. Choosing the wrong predicate is how you end up with a selection that looks plausible but is quietly wrong: 'intersects a ward boundary' catches plots straddling the edge that 'within a ward' correctly excludes.

Spatial predicates: the words behind the queryINTERSECTSthey touch or overlap at allWITHINA lies fully inside BCONTAINSB holds the point inside it
Zoom
The predicates behind select-by-location: intersects (touch or overlap), within (A fully inside B), contains (B holds the point).

Within and contains are the same fact told from opposite ends. Mind which end you're standing at.

Building a query, and combining the two kinds

Real questions usually need both kinds of query, chained. Take the brief from the hook - commercial plots within 100 m of a school. You build it in steps: first an attribute query on plots (land_use = 'commercial') to narrow the field; then a select-by-location using the predicate 'within a distance of 100 m' against the schools layer; the two combine with AND. Read back to front, the selection is a plain English sentence: select plots that are commercial AND within 100 m of a school.

Most tools let you refine a selection incrementally - add to, subtract from, or select within the current selection - which lets you assemble a complex condition without one monstrous expression. And when the data lives in a spatial database, the same logic becomes a single SQL statement with functions like STWithin and STDWithin. The mental model never changes: name the target, name the relationship, name the reference. Query built.

Two things separate a query that runs in a second from one that hangs for minutes. The first is a spatial index - a structure the software builds so it can skip features that are nowhere near your reference, instead of testing every one of forty thousand plots against every school. Desktop tools index automatically for most operations; in PostGIS you create it once and every spatial query gets faster. The second is doing the cheap work first: a permissive predicate like intersects is faster than an exact one, so narrow with an attribute query, then apply the spatial test to the small survivor set. On city-scale data these habits are the difference between analysis you can iterate and analysis you dread re-running.

Building a select-by-location querytarget layerplotspredicateare withinreference500 m of schoolsresult42 plotsread it as a sentence: select plots that are within 500 m of schools
Zoom
A select-by-location query reads like a sentence: target layer, predicate, reference layer - and out comes a counted selection.
Data & standards you will meet in this lesson

OGC API - Features

Modern RESTful/JSON API for querying vector features

The successor to WFS; lets you filter and fetch just the features meeting a condition from a server, rather than downloading a whole layer to query locally.

PostgreSQL + PostGIS

Spatial database with SQL geoprocessing

Where select-by-location becomes a single SQL statement (ST_Within, ST_Intersects, ST_DWithin). The professional home for querying large spatial datasets - free and open-source.

OpenStreetMap (OSM)

Global vector map - schools, plots, roads, wards

Free under the ODbL. The target and reference layers for practising attribute and spatial queries in any Indian city.

Census of India

Population and administrative-boundary data

Free public data; join it to ward polygons so an attribute query like population greater than 20000 becomes possible before you add a spatial condition.

Hands-on workshop

Workshop - commercial plots within 100 m of a school

You will chain an attribute query and a select-by-location to reproduce the exact brief from the hook, then export the result. This is the everyday rhythm of vector analysis.

QGIS 3.44 or ArcGIS Pro 3.7; a plots layer with an attribute column + a schools layer; a common metre CRS.

Given & goal
Given: a plots layer (with a land_use column) + a schools points layer
CRS: both in a common metre CRS (e.g. EPSG:32643) so a 100 m distance is real
Goal: an exported layer of commercial plots within 100 m of any school
  1. 1Attribute query first. In QGIS: open the plots attribute table, Select by Expression, and enter landuse = 'commercial'. In ArcGIS Pro: Map, Select By Attributes, build landuse = 'commercial'. Note the count.
  2. 2Now query by location. In QGIS: Processing, Select by Location (or Vector, Research Tools), target = the selected plots, predicate = are within distance, distance 100 m, reference = schools. In ArcGIS Pro: Map, Select By Location, Relationship = Within a distance, Search Distance 100 Meters, selecting from the current selection.
  3. 3Combine correctly. Make sure the second selection is applied to the already-selected commercial plots (an AND), not to the whole layer - both tools let you 'select within current selection'.
  4. 4Check a predicate alternative. Re-run using 'intersects' the schools' own 100 m buffer instead, and confirm you get the same set - proof you understand what the predicate is doing.
  5. 5Export the result. In QGIS: right-click, Export, Save Selected Features As, GeoPackage. In ArcGIS Pro: right-click, Data, Export Features. You now have a standalone, shareable answer layer.

You’ll walk away with
A saved layer of exactly the commercial plots within 100 m of a school, plus the confidence that you can turn any 'find features that are X and near Y' brief into a two-step query.

The worked example

Three altitudes on the same idea

Read the band that fits you — or all three.

For the architectSite, form & environment

Queries pull just the context your site drawing needs. Select the buildings within 200 m of the plot to build a context model; select the trees inside the setback to flag what must be retained; select the parcels sharing a boundary with yours to know your neighbours. You extract the relevant slice of a huge dataset instead of importing and hand-tidying the whole city.

For the plannerLand use, zoning & infrastructure

Select by location is how you enforce and audit a plan. Which built parcels fall inside a no-development zone? Which wards contain no school at all? Which industrial units sit within a residential buffer? Each is a predicate query that turns a policy into a defensible list of parcels - the routine analytical work of plan monitoring and violation detection.

For the urban designerStreets, blocks & public realm

Queries measure who and what a place actually holds. Select the frontages that face a park; select the junctions within a 5-minute walk of a metro entrance; select the plots with active ground-floor use along a high street. Spatial selection is how a felt quality of the public realm becomes a counted, mapped set you can argue from.

Misconception check

Select by location and an intersect overlay do the same job, so use whichever you know.

They answer related questions but behave differently. Select by location leaves your layers untouched and simply flags which existing features meet a spatial relationship - a selection you count or export. Intersect builds a whole new layer of cut geometry carrying both attribute tables. If you only need to know 'which features qualify?', selection is faster and non-destructive; reach for intersect only when you actually need the new sliced geometry and the combined attributes. Using intersect where a selection would do leaves you cleaning slivers you never needed.
Try it

Do it yourself

No software needed - just translate sentences into queries.

  1. 1Write these as query conditions: (a) wards with more than 20,000 people; (b) plots that are residential OR institutional; (c) roads that are arterial AND have four or more lanes.
  2. 2For 'plots that fall entirely inside the old-city ward', which predicate is correct - intersects, within, or contains? Why not intersects?
  3. 3You select 'buildings that intersect a flood polygon' and get more than you expected. Name one reason a permissive predicate over-selects at boundaries.
  4. 4Rewrite 'find hospitals reachable within 500 m of a metro station' as target + predicate + reference in plain words.
Take this with you

The one line to carry out

Every spatial query is target + relationship + reference: name the layer you want back, the predicate that defines 'related', and the layer to relate it to. Attribute queries ask what a feature is; select-by-location asks where it sits; chain them and you can ask the map almost anything.
Take it further
References & further reading

Peer-reviewed journals & authoritative standards

  1. 01Longley, P.A., Goodchild, M.F., Maguire, D.J. & Rhind, D.W. - Geographic Information Science and Systems, 4th ed.Wiley, 2015.
  2. 02de Smith, M.J., Goodchild, M.F. & Longley, P.A. - Geospatial Analysis: A Comprehensive Guide, 7th ed.Winchelsea Press, 2025.
  3. 03Bolstad, P. & Manson, S. - GIS Fundamentals: A First Text on Geographic Information Systems, 7th ed.Eider Press, 2022.
  4. 04Burrough, P.A., McDonnell, R.A. & Lloyd, C.D. - Principles of Geographical Information Systems, 3rd ed.Oxford University Press, 2015.
Related lessons
Recap
Attribute queries select by the columns; select-by-location selects by spatial relationship without creating new geometry; the predicates - intersects, within, contains, touches - make 'related in space' precise; and complex briefs are just these chained with AND/OR.
Carry forward →

Distance so far has meant straight-line - but people walk along streets, not through walls. To measure real reach we treat the road system as a network, which is next.

A

The author

Amogh N P

Architect, interior designer, and creative polymath. Studio Matrx began in his notebooks — his vision of design made honest, useful, and open to everyone. Its Academy is written and taught in his memory, and free, forever.

More about Amogh →