Point, line and polygon relationships
Quick answer
This tutorial maps predicates to geometry pairs: booleanPointInPolygon, booleanPointOnLine, booleanContains, booleanWithin, booleanIntersects, booleanDisjoint, booleanTouches and booleanOverlap. It highlights the boundary rule, where edge points count as inside unless ignoreBoundary: true is passed, and the strict all-or-nothing semantics of contains and within. You will be able to choose the correct predicate and speed up bulk tests.
Key points
- Pass { ignoreBoundary: true } when points on the polygon edge must be excluded from counts.
- Use booleanPointOnLine with ignoreEndPoint for point-to-line checks instead of polygon predicates.
- Pre-filter with turf.bbox before running thousands of booleanPointInPolygon calls on one polygon.
Example
var poly = turf.polygon([[[116.35, 39.86], [116.45, 39.86], [116.45, 39.94],
[116.35, 39.94], [116.35, 39.86]]]);
var onEdge = turf.point([116.35, 39.90]);
console.log(turf.booleanPointInPolygon(onEdge, poly)); // true
console.log(turf.booleanPointInPolygon(onEdge, poly, { ignoreBoundary: true })); // falsevar x = turf.polygon([[[116.40, 39.88], [116.48, 39.88], [116.48, 39.96],
[116.40, 39.96], [116.40, 39.88]]]);
console.log(turf.booleanIntersects(poly, x)); // true,有重叠
console.log(turf.booleanDisjoint(poly, x)); // false
console.log(turf.booleanTouches(poly, x)); // false,重叠不在边界
Notes
- booleanWithin(line, polygon) returns false when any single vertex falls outside, which is stricter than most business rules expect.
- Axis order mismatches return a stable false that looks like a data problem rather than a [lat, lng] mistake.
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Atlaslog (2026). Point, line and polygon relationships. https://www.jingweizhi.com/en/turf/tutorials/relations.html (accessed 2026-11-03).