Skip to content
New issue

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

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

Already on GitHub? # to your account

Unable to complete output ring starting at [...]. Last matching segment found ends at [...]. #140

Open
Tracked by #1
oli-clive-griffin opened this issue Aug 9, 2022 · 2 comments

Comments

@oli-clive-griffin
Copy link

oli-clive-griffin commented Aug 9, 2022

I'm getting this error on trying to intersect these two polygons: (viewer link)

It isn't really clear why this wouldn't be working.

"polygon-clipping": "^0.15.3",
Error: Unable to complete output ring starting at [175.4412230000001, -37.929121]. Last matching segment found ends at [175.441261917386, -37.92871399662434].
    at Function.factory (node_modules/polygon-clipping/dist/polygon-clipping.cjs.js:1252:21)
    at Operation.run (node_modules/polygon-clipping/dist/polygon-clipping.cjs.js:1776:30)
    at Object.intersection (node_modules/polygon-clipping/dist/polygon-clipping.cjs.js:1800:20)
    at Object.intersect (node_modules/@turf/intersect/dist/js/index.js:49:51)

script to validate:
this will throw at turf.intersect

const turf = require('@turf/turf');

const piece1 = {
    "type": "Polygon",
    "coordinates": [
        [
            [
                175.440248,
                -37.927138
            ],
            [
                175.441083,
                -37.927271
            ],
            [
                175.441362,
                -37.928504
            ],
            [
                175.44139,
                -37.928511
            ],
            [
                175.441542,
                -37.929194
            ],
            [
                175.441503,
                -37.929209
            ],
            [
                175.441476,
                -37.929182
            ],
            [
                175.441449,
                -37.929181
            ],
            [
                175.441223,
                -37.929121
            ],
            [
                175.441179,
                -37.928787
            ],
            [
                175.44065,
                -37.928795
            ],
            [
                175.440248,
                -37.927138
            ]
        ]
    ]
}

const piece2 = {
    "type": "Polygon",
    "coordinates": [
        [
            [
                175.4412230000001,
                -37.92912100000001
            ],
            [
                175.44144900000003,
                -37.929181000000035
            ],
            [
                175.441503,
                -37.929209
            ],
            [
                175.44154200000003,
                -37.92919400000002
            ],
            [
                175.44143567050224,
                -37.92871621679616
            ],
            [
                175.441261917386,
                -37.92871399662434
            ],
            [
                175.44117900000003,
                -37.928787000000014
            ],
            [
                175.4412230000001,
                -37.92912100000001
            ]
        ]
    ]
}

const piecesCollection = turf.featureCollection([turf.feature(piece1), turf.feature(piece2)])

// log link to view collection
console.log(`http://geojson.io/#data=data:application/json,${encodeURIComponent(JSON.stringify(piecesCollection))}`)

const intersection = turf.intersect(piece1, piece2).geometry

// log link to view intersection
console.log(`http://geojson.io/#data=data:application/json,${encodeURIComponent(JSON.stringify(intersection))}`)
@oli-clive-griffin
Copy link
Author

the first thing that stands out is very different degrees of accuracy, could that be a factor?

@markstos
Copy link

markstos commented Aug 2, 2023

This issue is fixed in the polygon-ts library:
https://github.com/luizbarboza/polyclip-ts

I recommend using it instead.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants