Spatial joins and counting points in polygons
Transfer attributes between layers by location and count how many points fall in each polygon, for example facilities per ward, then summarise the result.
You will learn
- Count points per polygon.
- Join polygon attributes to points by location.
- Summarise joined data with Aggregate.
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
| Field | Type | Description |
|---|---|---|
ward_id | text | Ward code W01 to W84. |
ward_name | text | Ward name. |
zone | text | urban, peri-urban or rural. |
population | integer | Residents. |
households | integer | Households. |
area_km2 | real | Ellipsoidal area in km². |
density_km2 | real | Persons per km². |
literacy_rate | real | Literate share, per cent. |
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
| Field | Type | Description |
|---|---|---|
facility_id | text | F001 to F097. |
name | text | Facility name. |
category | text | health or education. |
type | text | hospital, health_centre, clinic, school or college. |
ownership | text | public or private. |
capacity | integer | Beds or students. |
opened | integer | Year opened. |
Licence: CC0 1.0. All tutorial data is synthetic and generated by Orbis. About the datasets
The task
Planners ask how many health and education facilities each ward has, and how facilities are distributed between urban, peri-urban and rural zones.
Steps
Count points in each polygon
- Add Wards and Facilities from the tutorial data.
In the Toolbox, open Count points in polygon. Choose Wards (synthetic) as Polygons and Facilities (synthetic) as Points; keep Count field name
NUMPOINTS. Click Run.
Facilities counted in every ward.
- The new ward layer has a
NUMPOINTSfield. Style it with Graduated classes to map it.
Copy ward attributes to the facilities
- Open Join attributes by location. Choose Facilities (synthetic) as Input layer, Wards (synthetic) as Join layer, are within as Where the features, and One-to-one (first match) as Join type. Click Run.
- Every facility now also has the fields of its ward (
ward_id,ward_name,zone, …).
- Summarise: run Aggregate (group and summarize) on the joined layer, grouped by
zoneandcategory, with Count records.
Expected result
The NUMPOINTS values add up to 97 (every facility lies in exactly one ward); 49 wards have no facility and the busiest ward has 9. The summary by zone and category:
| zone | category | count |
|---|---|---|
| peri-urban | education | 15 |
| peri-urban | health | 4 |
| rural | education | 5 |
| urban | education | 42 |
| urban | health | 31 |
Rural wards have no health facility.
Common mistakes
- Swapping the layers. In Join attributes by location, the Input layer receives the attributes. Put the points first to give each point its ward.
- The wrong predicate. are within suits points in polygons. intersect also matches points exactly on a boundary.
Troubleshooting
- All counts are 0. The layers do not overlap, usually because one has a wrong CRS.
- Points on boundaries. A point exactly on a shared boundary may be counted in either neighbour.