Lesson 4.3Lesson 4.3 · Vector Spatial Analysis
Spatial Queries & Select by Location
Asking the map a precise question and getting exactly those features back
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.
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.
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.
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.
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.
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: 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
- 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.
- 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.
- 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'.
- 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.
- 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.
Three altitudes on the same idea
Read the band that fits you — or all three.
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.
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.
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.
“Select by location and an intersect overlay do the same job, so use whichever you know.”
Do it yourself
No software needed - just translate sentences into queries.
- 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.
- 2For 'plots that fall entirely inside the old-city ward', which predicate is correct - intersects, within, or contains? Why not intersects?
- 3You select 'buildings that intersect a flood polygon' and get more than you expected. Name one reason a permissive predicate over-selects at boundaries.
- 4Rewrite 'find hospitals reachable within 500 m of a metro station' as target + predicate + reference in plain words.
The one line to carry out
Peer-reviewed journals & authoritative standards
- 01Longley, P.A., Goodchild, M.F., Maguire, D.J. & Rhind, D.W. - Geographic Information Science and Systems, 4th ed. — Wiley, 2015.
- 02de Smith, M.J., Goodchild, M.F. & Longley, P.A. - Geospatial Analysis: A Comprehensive Guide, 7th ed. — Winchelsea Press, 2025.
- 03Bolstad, P. & Manson, S. - GIS Fundamentals: A First Text on Geographic Information Systems, 7th ed. — Eider Press, 2022.
- 04Burrough, P.A., McDonnell, R.A. & Lloyd, C.D. - Principles of Geographical Information Systems, 3rd ed. — Oxford University Press, 2015.
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.
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 →