Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@turf/difference: Maximum call stack size exceeded when using difference function between 2 polygons #2479

Closed
KubiO24 opened this issue Aug 27, 2023 · 1 comment · Fixed by #2729

Comments

@KubiO24
Copy link

KubiO24 commented Aug 27, 2023

I am getting following error:

RangeError: Maximum call stack size exceeded
image

When I use turf difference function between 2 polygons:

    const pol1 = [
        [
            [49.93317115095019, 20.170898437500004],
            [49.93927561914192, 20.16278743743897],
            [49.941126142253154, 20.165448188781742],
            [49.934096538617936, 20.174009799957275],
            [49.93317115095019, 20.170898437500004],
        ],
    ];
    const pol2 = [
        [
            [49.93317115095019, 20.170898437500004],
            [49.933680058500165, 20.170222252607346],
            [49.933758735535065, 20.170222252607346],
            [49.933803934349285, 20.170152112841606],
            [49.933803934349285, 20.170057658905122],
            [49.934306839656294, 20.169389449185992],
            [49.93434632011994, 20.16945071518421],
            [49.93434632011994, 20.16959099471569],
            [49.93448191656261, 20.16980141401291],
            [49.93457231419105, 20.16980141401291],
            [49.93466271181949, 20.16966113448143],
            [49.93484350707638, 20.16966113448143],
            [49.93520509759015, 20.169100016355515],
            [49.93529549521859, 20.169100016355515],
            [49.935928278617695, 20.168118059635166],
            [49.936018676246135, 20.168118059635166],
            [49.93660626083101, 20.167206242680553],
            [49.93660626083101, 20.167065963149074],
            [49.9367870560879, 20.166785404086117],
            [49.9367870560879, 20.166645124554638],
            [49.93714864660167, 20.166084006428722],
            [49.93714864660167, 20.165613543475054],
            [49.93742361679489, 20.16524819088677],
            [49.93755543592966, 20.165452748537067],
            [49.938504611028314, 20.16397981345654],
            [49.938504611028314, 20.163811875057462],
            [49.93927561914192, 20.16278743743897],
            [49.941126142253154, 20.165448188781742],
            [49.93988364085967, 20.16696147663808],
            [49.93981537664073, 20.166855543851856],
            [49.93958938256963, 20.167206242680553],
            [49.93958938256963, 20.167319864563666],
            [49.934096538617936, 20.174009799957275],
            [49.93317115095019, 20.170898437500004],
        ],
    ];
    let polygon1 = turf.polygon(pol1);
    let polygon2 = turf.polygon(pol2);
    polygon1 = turf.difference(polygon1, polygon2);

Here is visualization of these two polygons on map:
polygon 1
polygon 2

Turf version: 6.5.0.

@twelch
Copy link
Collaborator

twelch commented Sep 19, 2023

@KubiO24 you'll find a number of turf issues submitted with a similar error. Try running turf.truncate() on your polygons first. There's known floating point issues with the underlying polygon-clipping library. Please close the ticket if this resolves it.

@JamesLMilner JamesLMilner changed the title Maximum call stack size exceeded when using difference function between 2 polygons @turf/difference: Maximum call stack size exceeded when using difference function between 2 polygons Sep 28, 2023
@KubiO24 KubiO24 closed this as completed Jun 17, 2024
@smallsaucepan smallsaucepan self-assigned this Dec 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

4 participants