[boolean-intersects] Ignore parallel overlapping lines (no intersection). Allow polygons side by side.
Ignore parallel overlapping lines (no intersection). Allow polygons side by side.
I tried booleanIntersects and booleanOverlap but both function returns true if a polygon shares the same line. Side by side.
I didn't found a solution in turf.js. What do you think about? It could be fixed or as an optional parameter to allow this case. This is how jsts overlaps works. (I migrated to turf.)
See demo on CodePen or download the demo.geojson. In the demo you see red polygons if turf.booleanIntersects returns true for the two polygons. The polygons are side by side with exact the same points / line.
Expected: I don't want true here. It's not an intersection.
Click to view demo on CodePen.
View demo - click to expand
In case of dead links, here the demo again:
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Demo turf.js issue on GitHub</title>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
<link rel="stylesheet" href="./style.css" />
</head>
<body>
<div id="map"></div>
<script src="https://npmcdn.com/@turf/turf/turf.min.js"></script>
<script src="https://unpkg.com/[email protected]"></script>
<script src="./script.js"></script>
</body>
</html>
style.css
#map {
width: 800px;
height: 600px;
}
script.js
const map = L.map('map').setView([41.08396, -73.43279], 20);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(map);
const polygon1 = {
type: 'Feature',
properties: {},
geometry: {
type: 'Polygon',
coordinates: [
[
[-73.4333239, 41.0843581],
[-73.4327392, 41.0842651],
[-73.4328787, 41.0837556],
[-73.4334648, 41.0838486],
[-73.4333239, 41.0843581],
],
],
},
};
const polygon2 = {
type: 'Feature',
properties: {},
geometry: {
type: 'Polygon',
coordinates: [
[
[-73.4322913, 41.0836575],
[-73.4321491, 41.0841721],
[-73.4327392, 41.0842651],
[-73.4328787, 41.0837556],
[-73.4322913, 41.0836575],
],
],
},
};
const myGeoJson = L.geoJson({
type: 'FeatureCollection',
features: [polygon1, polygon2],
}).addTo(map);
const polygonsIntersects = turf.booleanIntersects(polygon1, polygon2);
myGeoJson.setStyle({
color: polygonsIntersects ? 'red' : 'green',
});
console.log(polygonsIntersects);
Version: "@turf/turf": "6.5.0"
Update: A workaround is to scale the polygons before checking for overlapping:
polygon1 = turf.transformScale(polygon1, 0.999999999);
polygon2 = turf.transformScale(polygon2, 0.999999999);
This is like adding padding to the polygons.
Hi @infacto
You could perhaps try turf.disjoint
Boolean-disjoint returns (TRUE) if the intersection of the two geometries is an empty set.
It's basically the opposite of intersect