Turf.jsBooleans

turf.booleanCrosses

What is turf.booleanCrosses?

turf.booleanCrosses tests whether two geometries cross each other. Per OGC, the predicate is true when their intersection has dimension one less than the maximum of the inputs and lies interior to both.

JavaScript
turf.booleanCrosses(feature1, feature2) → boolean

Supported combinations: MultiPoint vs Polygon or LineString, LineString vs LineString/Polygon/MultiPolygon.

When would you use turf.booleanCrosses?

Use turf.booleanCrosses for routing checks — does this proposed path cross a river? Does a truck route cross a restricted zone boundary? It is the right predicate when you want to flag a line that passes through another feature rather than merely touching or sharing a segment.

Unlike booleanIntersects, crosses excludes shared-segment cases, making it useful to filter true crossings from tangential contacts.

JavaScript
1const river = turf.lineString(riverCoords);
2const route = turf.lineString(routeCoords);
3turf.booleanCrosses(route, river); // true if it actually crosses

FAQs

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

Install npm install @turf/boolean-crosses and import import { booleanCrosses } from '@turf/boolean-crosses'. It is also on @turf/turf.

Does it work for Polygon vs Polygon?

No — per OGC, two polygons cannot "cross" because their intersection is either empty, lower-dimensional (touches), or the same dimension (overlap). Use turf.booleanOverlap for that case.

Is sharing an endpoint enough for crosses?

No. If two lines only share an endpoint, the intersection is a 0-dimensional point that does not lie interior to either, so crosses returns false. Use turf.booleanIntersects if touching counts.

When should I use crosses vs intersects?

Use booleanIntersects for any non-empty intersection. Use booleanCrosses when you specifically want lines that pass through other geometries — excluding tangent contact.