Turf.jsBooleans

turf.booleanContains

What is turf.booleanContains?

turf.booleanContains tests whether geometry a fully contains geometry b. The predicate follows OGC Simple Features: the interiors of both must intersect, and the interior and boundary of b must not touch the exterior of a. The call is symmetric with turf.booleanWithin(b, a).

JavaScript
turf.booleanContains(feature1, feature2) → boolean

When would you use turf.booleanContains?

Use turf.booleanContains when the question is "does this larger feature fully include this smaller one?" — for example confirming that a polygon boundary encloses all vertices of a proposed route, or asserting that a service region completely covers a customer's address cluster.

Contains is the inverse of Within, so pick based on readability: booleanContains(region, point) reads more naturally than booleanWithin(point, region) in code that thinks from the region's perspective.

JavaScript
turf.booleanContains(serviceArea, customerPolygon); // true if fully inside

FAQs

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

Install npm install @turf/boolean-contains and import import { booleanContains } from '@turf/boolean-contains', or use turf.booleanContains on @turf/turf.

Does boundary-only contact count as contains?

No. The OGC predicate requires b's interior to be strictly inside a's interior — sharing only a boundary is not enough. Use turf.booleanIntersects if any contact counts.

Which geometry type combinations are supported?

The helper supports Point, MultiPoint, LineString, and Polygon combinations in common orientations. Behaviour for exotic combinations (e.g. Point contains Polygon) is false by definition.

When should I use booleanContains vs booleanPointInPolygon?

For a single point inside a polygon, booleanPointInPolygon is faster and has a clearer edge-case option (ignoreBoundary). Reach for booleanContains when either geometry may be something other than a point.