-
Notifications
You must be signed in to change notification settings - Fork 981
Open
Description
Hello team! Thank you for your hard work!
There is an issue adding extra point to result of turn.difference
when one polygon is on the edge of another polygon.
Trying to find the difference for these 2 shapes:

Actual result:

Expected result:

Code to reproduce:
const initialArea = turf.polygon([
[
[-72.696428, 41.797527],
[-72.712274, 41.785347],
[-72.66441, 41.751403],
[-72.635534, 41.778325],
[-72.696428, 41.797527]
]
]);
const subtractArea = turf.polygon([
[
[
-72.700578,
41.794337
],
[
-72.692501,
41.791197
],
[
-72.699563,
41.785815
],
[
-72.692501,
41.782889
],
[
-72.681386,
41.792784
],
[
-72.696428,
41.797527
],
[
-72.700578,
41.794337
]
]
]);
const featureCollection = turf.featureCollection([
initialArea,
subtractArea,
]);
const difference = turf.difference(featureCollection);
console.log(">>>difference", JSON.stringify(difference));
Actual result of difference
:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-72.712274,
41.785347
],
[
-72.66441,
41.751403
],
[
-72.635534,
41.778325
],
[
-72.68138622124394,
41.79278380304014
],
[
-72.692501,
41.782889
],
[
-72.699563,
41.785815
],
[
-72.692501,
41.791197
],
[
-72.700578,
41.794337
],
[
-72.696428,
41.797527
],
[
-72.712274,
41.785347
]
]
]
}
}
]
}
Expected result
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-72.712274,
41.785347
],
[
-72.66441,
41.751403
],
[
-72.635534,
41.778325
],
[
-72.68138622124394,
41.79278380304014
],
[
-72.692501,
41.782889
],
[
-72.699563,
41.785815
],
[
-72.692501,
41.791197
],
[
-72.700578,
41.794337
],
// Wrong one.
// [
// -72.696428,
// 41.797527
// ],
[
-72.712274,
41.785347
]
]
]
}
}
]
}
When doing it multiple times it may have more artifacts:

Link to playground: https://jsfiddle.net/9d1baeno/1/
Looking forward for your reply!
Best regards.
Metadata
Metadata
Assignees
Labels
No labels