Turf: bug :intersect returns null although two polygones crosses each other

Created on 10 Apr 2020  路  6Comments  路  Source: Turfjs/turf

var points1 = [[[103.06965947998805, 25.166360955441036],
    [103.06936423825272, 25.16592004745796],
    [103.06997932523149, 25.165407879620716],
    [103.06965947998805, 25.166360955441036]]];
var points2 = [[[103.06882256663783, 25.166667027669433],
    [103.06866395130692, 25.165835431757955],
    [103.06968681685834, 25.165884659624638],
    [103.06972748746756, 25.165870594527007],
    [103.06882256663783, 25.166667027669433]]];
var polygon1 = turf.polygon(points1);
var polygon2 = turf.polygon(points2);

var intersection = turf.intersect(polygon1, polygon2);

turf.intersect returns null but two polygons crosses each other

bug

Most helpful comment

There is a chance to get more precision? I use this on maps and need precision of 2-3 meters

All 6 comments

@zx3236114 it looks like the issue is due to coordinates precision. @turf/intersect uses martinez-polygon-clipping, which apparently does have issues with coordinates with a lot of decimals.

Just FYI the package still works, even though you lose some details on your geometries, if you don't exceed (at least in your case) 4 decimals:

Screen Shot 2020-04-13 at 8 44 17 AM

There is a chance to get more precision? I use this on maps and need precision of 2-3 meters

The version 6.2.0-alpha.2 seems to solve the problem. At least for me it works now.

This is still an issue. One workaround is to do use turf.difference a couple times.
i.e. poly1 - (poly1 - poly2)
This seems to work satisfactorily in my case at the desired precision.

Has this bug been fixed? I still have problems with it,Is there a solution?thank you

Was this page helpful?
0 / 5 - 0 ratings