Turf.jsJoins

turf.pointsWithinPolygon

What is turf.pointsWithinPolygon?

turf.pointsWithinPolygon filters a collection of points to only those lying inside one or more polygons. It accepts either a FeatureCollection of Points/MultiPoints and Polygons/MultiPolygons, and returns a FeatureCollection of the same geometry type containing only the matching features.

JavaScript
turf.pointsWithinPolygon(points, polygons) → FeatureCollection<Point | MultiPoint>

When would you use turf.pointsWithinPolygon?

Use turf.pointsWithinPolygon for point-in-polygon spatial joins — filtering a dataset of GPS pings to those in a selected neighbourhood, isolating POIs within a drawn lasso on the map, or picking orders that fall in a delivery zone before computing a summary. It is the bulk equivalent of looping turf.booleanPointInPolygon and is implemented more efficiently internally.

Properties of matching points are preserved on the output, so you can feed the result straight into aggregation or styling.

JavaScript
1const orders = turf.featureCollection(orderPoints);
2const zone = turf.polygon([zoneRing]);
3const inZone = turf.pointsWithinPolygon(orders, zone);
4console.log(`${inZone.features.length} orders in this zone`);

FAQs

How do I install Turf.js to use this function?

Install npm install @turf/points-within-polygon and import with import { pointsWithinPolygon } from '@turf/points-within-polygon'. It is also on @turf/turf.

Does it work with MultiPoint inputs?

Yes — a MultiPoint is returned whenever at least one of its positions lies inside the polygons. The output geometry type matches the input type.

Are points on the polygon boundary included?

Edge-cases follow the same rules as booleanPointInPolygon: points that lie exactly on an edge or vertex may or may not be counted depending on floating-point precision. Apply a small buffer to the polygon when you need predictable boundary behaviour.

How does it compare to turf.tag?

pointsWithinPolygon filters points. turf.tag transfers a property from the containing polygon onto each point — use tag when you want to know which polygon, not just whether.