Spatial Filter
Filter features within viewport or a drawn polygon
What Is a Spatial Filter?
A spatial filter is a query that selects features based on their geometric relationship to another geometry, rather than on their attribute values. Where an Attribute Filter Builder answers "which features have population over 100,000," a spatial filter answers "which features fall inside this polygon" or "which features are within 500 meters of this line." Spatial filters are the second pillar of GIS query β together with attribute filters, they cover the vast majority of selection workflows.
The core idea comes from the OGC Simple Features specification, which defines a set of binary spatial predicates: Intersects, Contains, Within, Touches, Crosses, Overlaps, Disjoint, and Equals. Each predicate is a yes/no test between two geometries. A spatial filter uses one of these predicates and a reference geometry to select all features in a layer that satisfy the relationship.
The gis.tools spatial filter lets you draw a polygon directly on the map (or use an existing layer as the reference) and select all features in another layer that intersect, contain, or are within it. The selection runs against the in-memory FeatureCollection using a spatial index (R-tree) to keep performance fast even on large datasets. Everything happens in the browser, so the filter expression never leaves your machine.
Spatial filters are foundational to virtually every GIS workflow. Site selection, environmental impact assessment, customer territory definition, conservation planning, and disaster damage estimation all start with "give me the features in this area."
How Spatial Filtering Works
Spatial predicates
The OGC Simple Features predicates each have a precise mathematical definition based on point-set topology. The most common are:
- Intersects: the two geometries share at least one point.
- Contains: A entirely contains B (B's interior is in A's interior).
- Within: A is entirely within B (the reverse of Contains).
- Touches: the two geometries share boundary points but no interior points.
- Disjoint: the two geometries share no points at all.
- Crosses: the geometries' interiors intersect but neither contains the other.
- Overlaps: same dimension, partial overlap.
Bounding box pre-filter
Naive spatial predicates would test the candidate feature's geometry against the reference for every feature in the dataset, which is O(N) and slow. The spatial filter first builds an R-tree spatial index on the candidate dataset. For each query, it uses the reference geometry's bounding box to find candidate features whose own bounding boxes overlap, then runs the precise predicate only on those candidates. This reduces typical query times from O(N) to O(log N).
Within-distance queries
A proximity filter ("within 500 meters") is a special case implemented by buffering the reference geometry first and then running an Intersects predicate. For accurate distance computation, the buffer is computed in a projected CRS (typically a local UTM zone or an azimuthal equidistant projection centered on the reference).
Key Parameters and Options
Predicate selection
The filter UI lets you pick from Intersects, Contains, Within, and Touches. Intersects is the safest default β it matches anything that overlaps the reference, including features that are entirely inside or that just barely touch the boundary.
Reference geometry source
You can draw the reference polygon directly on the map with a polygon-drawing tool, or pick an existing feature from another layer (for example, a city boundary).
Distance buffer
For proximity queries, set a buffer distance in meters, kilometers, miles, or feet. The filter buffers the reference, then intersects.
Practical Applications
Election geography
A campaign analyst wants to identify all voter precincts inside a proposed congressional district. They draw the district outline (or load it from a shapefile), apply a Within filter to the precinct layer, and export the matched precincts for door-to-door canvassing planning.
Wildfire perimeter analysis
During an active wildfire, an emergency manager loads the latest fire perimeter polygon and applies an Intersects filter to the building footprint layer. The result is the list of structures inside the burn area, which feeds directly into the post-fire damage assessment.
Watershed sampling
A hydrologist studying nutrient loading filters water quality monitoring stations to those that fall within a target watershed boundary. The filtered subset becomes the input for a load duration curve analysis.
Service area definition
A hospital network defines a 30-minute drive-time isochrone around each facility, then uses a spatial filter to find all census block groups whose centroid is within at least one isochrone. The result is the network's service area for accreditation reporting.
Crime hotspot scoping
A police analyst draws a polygon around a high-incident neighborhood and filters the historical incident dataset to only points inside, then runs temporal aggregations to detect time-of-day patterns.
Infrastructure damage assessment
After an earthquake, an engineering firm filters bridge inventory points to only those within 10 kilometers of the epicenter to prioritize structural inspections.
Marine protected area enforcement
A conservation NGO loads vessel AIS tracks and filters to those that pass through a marine protected area polygon. The filtered tracks become evidence in enforcement actions.
Step-by-Step Workflow
- Load both layers (the candidate features and the reference polygon if applicable) into the GeoJSON, KML, Shapefile & GIS File Viewer.
- Open the spatial filter for the candidate layer.
- Pick the reference: draw a polygon on the map, or select a feature from another layer.
- Choose a predicate: Intersects, Within, Contains, Touches.
- Optionally set a buffer distance for proximity queries.
- Apply the filter β the map highlights matching features instantly.
- Combine with an attribute filter (Intersects +
population > 50000) for compound queries. - Export the matches with the Multi-Select & Export tool.
Worked Example
A bicycle infrastructure planner has a citywide point dataset of 12,400 reported road defects (potholes, cracks, debris) and wants to know which defects fall along the proposed protected bike lane corridor. They load the proposed bike lane LineString, buffer it by 2 meters using the GIS Buffer Tool to create a corridor polygon, and then apply a spatial filter with Intersects predicate to the defect layer.
The result is 218 defects inside the corridor. The planner exports the matched points and groups them by defect type using the Column Statistics & Histograms tool. The summary feeds into the bid package for the bike lane construction contract.
Common Pitfalls and Gotchas
- CRS mismatch. If candidate and reference layers are in different coordinate systems, the spatial predicates will return wrong answers. Reproject both to a common CRS (typically WGS84) using the EPSG Reprojector & Coordinate Converter.
- Boundary inclusion ambiguity. Features exactly on the boundary may or may not be included depending on whether you use Intersects or Within. Be explicit about which you want.
- Self-intersecting reference polygons. Drawing a polygon that crosses itself produces undefined behavior. Validate with the GeoJSON Validator & Fixer.
- Distance buffers in lat/lon. Buffering in WGS84 produces ellipses, not circles. Always reproject to a metric CRS first.
- Multi-part geometries. A MultiPolygon reference may include disjoint parts; features in one part but not another still match.
- Performance on dense geometries. Reference polygons with millions of vertices can slow predicate evaluation. Simplify with the GeoJSON Simplifier first.
- Antimeridian crossings. A reference polygon that crosses 180Β° longitude needs special handling.
Tips for Best Results
- Use Intersects as the default predicate and only switch to Within or Contains when you have a reason.
- Build a spatial index on the candidate layer if your viewer does not do it automatically.
- Combine spatial and attribute filters for compound queries β both filters apply on top of each other.
- For proximity queries on large datasets, buffer the reference once and reuse it.
- Verify your reference polygon is closed (first and last coordinates equal).
- For accurate distance buffers, always reproject to a local metric CRS first.
- Save common reference polygons (city boundaries, watersheds) as separate GeoJSON files for reuse.
Comparison with PostGIS and Desktop GIS
PostGIS implements the same OGC predicates via SQL functions like ST_Intersects, ST_Within, and ST_DWithin, with the same R-tree indexing. QGIS uses Select by Location with a similar dropdown of predicates. ArcGIS uses Select by Location too, with a slightly different terminology.
The gis.tools approach is identical in semantics but runs entirely in the browser, with no database to set up. The trade-off is scale: PostGIS handles billions of features, while browser-side filtering is practical up to a few hundred thousand. For larger workloads, pre-filter in a database and load the result into gis.tools.
Performance Considerations
With an R-tree index in place, spatial filters on 100,000 features against a simple reference polygon return in under 200ms. Without an index, the same query can take seconds. Complex reference polygons (thousands of vertices) slow predicate evaluation linearly with vertex count.
Data Privacy and Browser-Based Processing
Spatial filters run entirely in your browser. Sensitive data like health facility locations, witness addresses, or critical infrastructure coordinates can be filtered without ever transmitting the underlying coordinates to a third-party server. This is a hard requirement for many government and humanitarian workflows.
Related GIS Concepts
OGC Simple Features. The standardized model and predicate set for vector geometry, adopted by virtually all modern GIS software.
R-tree spatial index. A tree data structure that organizes bounding rectangles for fast spatial lookup.
Topological relations. The branch of mathematics describing how geometries relate (DE-9IM is the formal model).
Buffer-and-intersect. The standard pattern for proximity queries: buffer the reference, then test for intersection.
Frequently Asked Questions
What is the difference between Intersects and Within?
Intersects matches any overlap; Within requires the candidate to be entirely inside the reference. A point on the boundary intersects but is not strictly within (depending on the implementation).
Can I use a line as a reference geometry?
Yes, but most queries use polygons or buffered lines. A raw line will only match features that geometrically touch it.
How do I find features within X meters?
Use the buffer distance option, or buffer the reference geometry first with the GIS Buffer Tool and then run an Intersects filter.
Why are my results wrong after reprojecting?
Make sure all layers are in the same CRS before applying the spatial filter. Use the CRS Metadata Inspector to confirm.
Can I combine spatial and attribute filters?
Yes. Apply both β the result is the intersection of the two selections.
Related Tools on gis.tools
Related Tools
View All ToolsDe-duplication Tool
Find and remove duplicate features by coordinates or key
Query & FilterColumn Statistics
View distinct values, null counts, and histograms for fields
Query & FilterData Profiling Report
Generate schema analysis and data quality flags
Query & FilterJoin Tool (CSV β Layer)
Join CSV data to a layer by a common key field
Query & FilterFull-Text Search
Search across all attributes with in-browser indexing
Query & FilterSpatial Join
Join layers spatially: points in polygons, nearest features
Query & Filter100% client-side processing - your data stays private and never leaves your device