Turfjs / turf

A modular geospatial engine written in JavaScript and TypeScript

Home Page:https://turfjs.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

booleanIntersects false positive for self-intersecting lines

kajkal opened this issue · comments

The problem occurs in v7 alpha versions, in version 6.5.0 it works fine.

node.js example:

import assert from 'node:assert/strict';
import * as turf from '@turf/turf'; // v7.0.0-alpha.113

const result = turf.booleanIntersects({
    type: 'LineString',
    coordinates: [ [ 0, 1 ], [ 0, 3 ], [ 1, 3 ], [ 1, 2 ], [ 0, 2 ] ],
}, {
    type: 'Polygon',
    coordinates: [ [ [ 2, 3 ], [ 2, 2 ], [ 3, 2 ], [ 3, 3 ], [ 2, 3 ] ] ],
});
assert.equal(result, true);

browser example:

Playground jsfiddle.net

GeoJSON geojson.io

i have same issue, but my problem only happen if i using minify version of geojson, if i use detailed version like 6 digit coordinate precision there no problem, only have this problem when using coordinate precision less than 6

i have same issue, but my problem only happen if i using minify version of geojson, if i use detailed version like 6 digit coordinate precision there no problem, only have this problem when using coordinate precision less than 6

but sometime is work, only spesific MultiPolygon data that not work, example : https://jsfiddle.net/bagusindrayana/69z5xgah/

check if circle intersect with region (there 2, with minify version and detailed one)
image

It appears I've run into this as well with booleanIntersects from Turf v7. There's a self-intersecting ped bridge in Minneapolis:

image

Here's the polygon and self-intersecting LineString which triggered it:

{"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[-93.32782012090661,44.905105886883895],[-93.32813791743847,44.905495304024456],[-93.32877351050222,44.905495304024456],[-93.32909130703408,44.905105886883895],[-93.32877351050222,44.904716469743335],[-93.32813791743847,44.904716469743335],[-93.32782012090661,44.905105886883895]]]}},{"type":"Feature","properties":{},"geometry":{"type":"LineString","coordinates":[[-93.24707484498155,44.95922742420989,0],[-93.2470177076491,44.959221946354994,0],[-93.2469515679869,44.95921560469957,0],[-93.24686192234894,44.95920212195756,0],[-93.24675334176239,44.95917628019178,0],[-93.24665818470078,44.959145692647226,0],[-93.24657713746436,44.959113274639876,0],[-93.24649202555713,44.9590799761926,0],[-93.24641031080519,44.95903683432015,0],[-93.24634065916696,44.95899770649367,0],[-93.24628641867122,44.95896001972235,0],[-93.2462321959612,44.95892234464366,0],[-93.24600199004686,44.9587175157225,0],[-93.24595284762219,44.958683364851,0],[-93.24589122242784,44.95865281702909,0],[-93.24581884544686,44.95863177972644,0],[-93.24574779466329,44.95861740881392,0],[-93.24567269385376,44.95861350937172,0],[-93.24560665192392,44.95861116397575,0],[-93.24553588498935,44.95861429623211,0],[-93.24546840170667,44.958621642587936,0],[-93.2454030437719,44.95863794360808,0],[-93.24533995371814,44.95865977032114,0],[-93.24528490066382,44.958685415586906,0],[-93.24522716008012,44.958712961555406,0],[-93.24517743843721,44.95875289758634,0],[-93.24513846643038,44.95878427689593,0],[-93.24506545250651,44.958861133255496,0],[-93.24500109402959,44.95894544592641,0],[-93.24492282348037,44.95902256486146,0],[-93.2449093927777,44.95903028597081,0],[-93.24489680550242,44.95903562722455,0],[-93.24486996860307,44.95904035551744,0],[-93.24484062592514,44.95904151034663,0],[-93.24481296564886,44.95904028633335,0],[-93.24478532257545,44.95903192060211,0],[-93.24476523248921,44.959019992720535,0],[-93.2447443106149,44.959005087278534,0],[-93.24472675195784,44.95898661550183,0],[-93.2446603300124,44.95888730548265,0],[-93.24456141270548,44.95874815044515,0],[-93.24455719139311,44.95873286126595,0],[-93.2445580734347,44.958715006657734,0],[-93.24457155149092,44.95868764475774,0],[-93.24459675465704,44.958665058867446,0],[-93.24463139246139,44.95865110184888,0],[-93.24467056272843,44.95864848334043,0],[-93.24470827272073,44.95865388568375,0],[-93.2447350664325,44.958667012157576,0],[-93.24475737700762,44.95868934715845,0],[-93.24481764398641,44.958837930035784,0],[-93.24484346844363,44.958905217117774,0],[-93.244861762754,44.958967138531335,0],[-93.2448949870237,44.95909454768209,0],[-93.24489826903135,44.95912419205621,0],[-93.24489150218137,44.95914918125817,0],[-93.24487888908997,44.95916523642615,0],[-93.24486545118512,44.959175933168126,0],[-93.24484613998385,44.95918840888839,0],[-93.2448268400753,44.959196717633986,0],[-93.24468558581273,44.95924039796122,0]]}}]}

Downgrading @turf/boolean-intersects to 6.50 appears to resolve the issue.