Vector processing

Selecting features by their location

Select features using spatial relationships with another layer: within, intersecting, touching or disjoint from it, and combine the result with attribute selections.

Intermediate2 min read

You will learn

  • Use spatial predicates to select features.
  • Combine selection modes.
  • Turn a selection into a new layer.

Prerequisites

Data for this tutorial

Wards (synthetic) Download wards.geojson

Format
GeoJSON
Geometry
Polygon
CRS
EPSG:32643 (WGS 84 / UTM zone 43N)
Content
84 wards (31 peri-urban, 19 rural, 34 urban), 333,497 residents
In Orbis
Browser panel ▸ Tutorial sample data (synthetic) ▸ Wards, or Load complete tutorial pack.
Fields used in the tutorials
FieldTypeDescription
ward_idtextWard code W01 to W84.
ward_nametextWard name.
zonetexturban, peri-urban or rural.
populationintegerResidents.
householdsintegerHouseholds.
area_km2realEllipsoidal area in km².
density_km2realPersons per km².
literacy_raterealLiterate share, per cent.

Roads (synthetic) Download roads.geojson

Format
GeoJSON
Geometry
LineString
CRS
EPSG:32643 (WGS 84 / UTM zone 43N)
Content
23 roads: 2 primary, 5 secondary, 16 local
In Orbis
Browser panel ▸ Tutorial sample data (synthetic) ▸ Roads, or Load complete tutorial pack.
Fields used in the tutorials
FieldTypeDescription
road_idtextRoad identifier.
nametextRoad name.
classtextprimary, secondary or local.
lanesintegerNumber of lanes.
surfacetextpaved or unpaved.

Facilities (synthetic) Download facilities.geojson

Format
GeoJSON
Geometry
Point
CRS
EPSG:32643 (WGS 84 / UTM zone 43N)
Content
97 points: 3 hospitals, 6 health centres, 26 clinics, 58 schools, 4 colleges
In Orbis
Browser panel ▸ Tutorial sample data (synthetic) ▸ Facilities, or Load complete tutorial pack.
Fields used in the tutorials
FieldTypeDescription
facility_idtextF001 to F097.
nametextFacility name.
categorytexthealth or education.
typetexthospital, health_centre, clinic, school or college.
ownershiptextpublic or private.
capacityintegerBeds or students.
openedintegerYear opened.

Licence: CC0 1.0. All tutorial data is synthetic and generated by Orbis. About the datasets

The task

You want the wards crossed by a primary road, and then only those that are urban.

Steps

  1. Add Wards and Roads from the tutorial data. Select the two primary roads: Select by attribute on Roads with class = primary.
  1. In the Toolbox, open Select by location. Choose:

    • Input layer: Wards (synthetic).
    • Comparison layer: Roads (synthetic) with Selected features only ticked.
    • Where the features: intersect.
    • Selection mode: Create new selection.
    Select by location with the wards as input, the selected primary roads as comparison layer and the intersect predicate
    Selecting the wards crossed by the primary roads.
  1. Click Run. The wards crossed by the primary roads are selected.
  1. To keep only urban ones, run Select by attribute on Wards with zone = urban and Selection mode Select within current selection.

The predicates

Where the features …Selects input features that
intersectshare any point with a comparison feature
containcompletely contain a comparison feature
are withinlie completely inside a comparison feature
are disjoint fromshare no point with any comparison feature
touchshare only boundary points
crosscross a comparison feature (for example a line through a polygon)
overlappartly overlap a comparison feature of the same type
are equal tohave the same geometry

Expected result

The urban wards that a primary road passes through are selected. Extract by location with the same settings creates a new layer instead of a selection.

Common mistakes

  • Using Select by location in a workflow. Selection tools change the selection of a project layer; in the Workflow Builder use Extract by location.
  • Disjoint is slow. are disjoint from has to compare each feature with every comparison feature.

Troubleshooting

  • Nothing is selected. Check that the comparison features are selected when Selected features only is ticked, and that both layers overlap on the map.