Vector processing

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.

Intermediate2 min read

You will learn

  • Count points per polygon.
  • Join polygon attributes to points by location.
  • Summarise joined data with Aggregate.

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.

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

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

  1. Add Wards and Facilities from the tutorial data.
  1. 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.

    Wards coloured by the number of facilities they contain after Count points in polygon
    Facilities counted in every ward.
  1. The new ward layer has a NUMPOINTS field. Style it with Graduated classes to map it.

Copy ward attributes to the facilities

  1. 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.
  1. Every facility now also has the fields of its ward (ward_id, ward_name, zone, …).
  1. Summarise: run Aggregate (group and summarize) on the joined layer, grouped by zone and category, 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:

zonecategorycount
peri-urbaneducation15
peri-urbanhealth4
ruraleducation5
urbaneducation42
urbanhealth31

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.