Count Points in Polygons
Test your point file against district, zone or parcel boundaries: count the points and summarise values per polygon, and add the containing polygon's attributes to every point.
1 Points
2 Polygons
Files are processed in the browser and their contents are not sent to a server. Only map tiles (Esri, OpenStreetMap) and libraries (jsDelivr) are downloaded.
Point columns
Polygon attributes
Map
Preparing files
The first row of a point table should hold the column names. Polygons can be WGS84 GeoJSON, a shapefile zip with a .prj file, or KML. For point coordinates in metres, choose the coordinate system.
Related Tools
What counting points in polygons is for
Many organisations keep records by address or coordinate, while decisions are made per neighbourhood, district, sales territory, parcel or service area. A spatial join connects the two: it finds the polygon that contains each point and makes the result usable in both directions. Municipal teams count service requests per neighbourhood, retail teams assign customers to territories and logistics teams group delivery stops by distribution area.
The tool produces three results. The first is a summary per polygon: point count, points per km² and, for a numeric column of your choice, the sum, mean, minimum and maximum. The second is the point table itself, with the name and selected attributes of the containing polygon added to every row; this is the answer to "which district is each row in" for a spreadsheet. The third is a list of points that fall in no polygon, a quick way to find wrong coordinates or records outside the service area.
How to use it
- Load the point file: CSV, Excel, GeoJSON or KML. In tables the latitude and longitude columns are recognised by name; correct them in the lists if needed. If the coordinates are in metres, pick the coordinate system.
- Load the polygon file: GeoJSON, a zipped shapefile or KML. As soon as both files are ready, the analysis runs on its own.
- For sums and means, choose a column in "Numeric value field" (amount, duration, quantity and so on).
- "Polygon name field" sets the name shown in the tables and on the map. Tick only the attributes you want to add to the points to keep the output lean.
- Polygons are coloured by the value you choose. Click a polygon to see its summary, or use "Show" in the table to jump to it. Red points are the ones outside every polygon.
- Download the results: polygons as GeoJSON and CSV summary, points as CSV and GeoJSON, and the points outside as CSV. The points CSV keeps the delimiter of the original file.
Data and method
Points are tested against polygons with the booleanPointInPolygon function of Turf.js 7.2.0 (MIT licence); polygons with holes and multipart polygons are supported. So that each point is not tested against thousands of polygons one by one, the polygons' bounding boxes are stored in an RBush 3.0.1 (MIT) R-tree index, and a point is only compared with polygons whose box contains it. A point exactly on a boundary counts as inside. Polygon area comes from Turf's spherical area calculation, and density is the count divided by that area.
Files are read in the browser: CSV with PapaParse 5.4.1 (MIT), Excel with SheetJS xlsx 0.18.5 (Apache-2.0), shapefiles with shpjs 6.1.0 (MIT), KML with @tmcw/togeojson 5.8.0 (BSD-2-Clause) and KMZ with JSZip 3.10.1 (MIT). Point coordinates in metres are converted to WGS84 with proj4js 2.9.0 (MIT); for ED50 the tool uses EPSG:1784 (ED50 to WGS 84 (30)), the transformation defined for Turkey. Basemaps belong to Esri and OpenStreetMap contributors. File contents are never sent to a server; only map tiles and these libraries are downloaded. If you have accepted analytics cookies, only event names such as "analysis completed" are counted anonymously. Open-source libraries used and their licences: Data Sources.
Accuracy limits
- The result is only as reliable as the point coordinates and the boundaries. If a geocoded coordinate snaps to a street or neighbourhood centre, records near a boundary can be assigned to the neighbouring polygon.
- Boundary data from different sources can leave small gaps or overlaps between neighbouring polygons. A point in a gap stays outside, a point in an overlap is counted twice; the pip_matches column shows these cases.
- If the wrong coordinate system is selected for the points, they land far from the polygons. The tool warns you when no point matches at all.
- In our test on a desktop computer with 50,000 points and 400 polygons, the comparison took less than 0.1 seconds and about 1 second including reading and drawing. Phones and complex boundaries with thousands of vertices take longer.
For organisations
Address management, geocoding and the large-scale matching of address lists to boundaries are among the topics Rodosto works on. You can read more at rodostoteknoloji.com or send a question through the contact page.
Frequently Asked Questions
How do I find which district each address in my spreadsheet is in?
You first need a latitude and longitude for each address; addresses without coordinates are converted with geocoding. Then load the spreadsheet as the point file and the district boundaries (GeoJSON, shapefile or KML) as the polygon file. The tool adds the name and other attributes of the containing district to every row.
How are points on a polygon boundary counted?
A point exactly on the boundary is treated as inside that polygon. A point on the shared edge of two neighbouring polygons can therefore be counted in both; the pip_matches column then shows 2 and the point receives the attributes of the first polygon in file order.
What should I check when loading a shapefile?
Load the shapefile as a single zip containing the .shp, .shx, .dbf and .prj files. The .prj file defines the coordinate system and is used to convert the polygons to WGS84; without it, polygons in metres cannot be read.
Are my files uploaded to a server?
No. The point and polygon files are read and compared in your browser and their contents are not sent to any server. Only map tiles (Esri, OpenStreetMap) and open-source libraries (jsDelivr) are downloaded.