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-mask fails #837

Closed
2 tasks done
andrewharvey opened this issue Jul 12, 2017 · 3 comments
Closed
2 tasks done

turf-mask fails #837

andrewharvey opened this issue Jul 12, 2017 · 3 comments
Milestone

Comments

@andrewharvey
Copy link
Contributor

andrewharvey commented Jul 12, 2017

In the above data/example app, turf-mask fails with:

Uncaught Error: Each LinearRing of a Polygon must have 4 or more Positions.
    at Object.polygon (npmcdn.com/@turf/turf@4.5.2/turf.js:599)
    at buildMask (npmcdn.com/@turf/turf@4.5.2/turf.js:20252)
    at Object.module.exports [as mask] (npmcdn.com/@turf/turf@4.5.2/turf.js:20228)
    at e.<anonymous> (<anonymous>:516:23)
    at e.Evented.fire (mapbox-gl.js:411)
    at e._render (mapbox-gl.js:385)

From what I could tell it's the unionPolygons step where it returns a MultiPolygon but the spec at https://github.com/Turfjs/turf/blob/master/packages/turf-mask/index.js#L137 says it should only return Polygon: @returns {FeatureCollection<Polygon>} polygons only apply union if they collide

I don't have the time to investigate further and I'll workaround this issue so it's not a critical issues.

/cc @rowanwins just flagging you as you did the original implementation.

@DenisCarriere
Copy link
Member

Internally this library is using union from jsts which outputs Polygon|MultiPolygon, however the MultiPolygon output isn't get handled properly.

Solution: We could use flattenEach from @turf/meta to process the unioned outputs into simple polygons.

@DenisCarriere DenisCarriere added this to the 4.6.0 milestone Jul 12, 2017
@thiagoxvo
Copy link
Contributor

I am having the same issue here, I can try to fix and send a PR :)

@rowanwins
Copy link
Member

That would be great thanks @thiagoxvo , sing out if you need a hand!

thiagoxvo added a commit to thiagoxvo/turf that referenced this issue Jul 26, 2017
Change from featureEach to flattenEach will output simple Polygons.
Fix Turfjs#837
thiagoxvo added a commit to thiagoxvo/turf that referenced this issue Jul 26, 2017
Change from featureEach to flattenEach will output simple Polygons.
Fix Turfjs#837
DenisCarriere pushed a commit that referenced this issue Jul 26, 2017
* Update Typescript definition

* Handle MultiPolygon properly when building a mask

Change from featureEach to flattenEach will output simple Polygons.
Fix #837

* Remove unused code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants