turf.booleanPointInPolygon
What is turf.booleanPointInPolygon?
turf.booleanPointInPolygon tests whether a point lies inside a polygon, correctly handling holes and multi-polygons. It is Turf's fastest point-in-polygon predicate and uses a ray-casting algorithm under the hood.
turf.booleanPointInPolygon(point, polygon, options?) → booleanOptions include:
ignoreBoundary— whentrue, points that lie exactly on the boundary returnfalse(defaultfalse)
When would you use turf.booleanPointInPolygon?
Use turf.booleanPointInPolygon whenever you need to check a single point against one polygon — hit-testing a map click against a district boundary, filtering GPS pings to a geofence, or deciding whether an address sits inside a delivery zone.
For bulk checks (thousands of points), it is faster than the higher-level pointsWithinPolygon when combined with a spatial index such as rbush around the polygon's bounding boxes.
1map.on('click', e => {
2 const pt = turf.point([e.lngLat.lng, e.lngLat.lat]);
3 const inside = turf.booleanPointInPolygon(pt, district);
4 showMessage(inside ? 'In district' : 'Outside');
5});FAQs
How do I install Turf.js to use this function?
Install npm install @turf/boolean-point-in-polygon and import import { booleanPointInPolygon } from '@turf/boolean-point-in-polygon', or use turf.booleanPointInPolygon via @turf/turf.
Does it handle holes?
Yes. A point inside a hole is considered outside the polygon. Arbitrary nesting is supported through MultiPolygon.
What does ignoreBoundary do?
Points that lie exactly on an edge or vertex return true by default. Set ignoreBoundary: true to treat them as outside — useful when you need strict-interior semantics.
When should I use this vs booleanContains?
For a single point and single polygon, prefer booleanPointInPolygon — it is faster and has the ignoreBoundary option. Use booleanContains when either input may be a non-point geometry.