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

Dissolve GeoJSON : Please have a talk with w8r/martinez #14

Closed
cyrilchapon opened this issue Jul 12, 2018 · 2 comments
Closed

Dissolve GeoJSON : Please have a talk with w8r/martinez #14

cyrilchapon opened this issue Jul 12, 2018 · 2 comments

Comments

@cyrilchapon
Copy link

cyrilchapon commented Jul 12, 2018

In here we are trying to "dissolve" a huge mass of geojson Polygons / MultiPolygons.

We followed the documentation, and did this :

  const polyboolPolygons = polygons.map(polybool.polygonFromGeoJSON)

  const unionPolyboolPolygon = polyboolPolygons.reduce(
    (polyboolPolygonAcc, polyboolPolygon) => (
      (!polyboolPolygonAcc && polyboolPolygon) ||
      polybool.union(polyboolPolygonAcc, polyboolPolygon)
    ),
    null
  )

  const unionPolygon = polybool.polygonToGeoJSON(unionPolyboolPolygon)

This works perfectly, but it takes like 20 seconds to process the whole stuff...

capture d ecran 2018-07-12 a 11 02 56

On the other side, w8r/martinez process it in less than 400ms... but produces aberrations, like this :

capture d ecran 2018-07-12 a 10 30 47

capture d ecran 2018-07-12 a 10 31 03

(The base "larger" polygon has many holes, and you can see some are respected, others are curiously understood as other polygons, witch comes "over" the first)

I cannot really provide any dataset, because this one is huge, and I could not reproduce on a smaller one.

Sooo, is there a chance we can engage in a discussion between the 2 repos, to come up with a solution fully working, in less than 400ms? 😄

(Note: I duplicated the issue there)

@velipso
Copy link
Owner

velipso commented May 6, 2019

Just re-reading this -- you should be using the core API to calculate a more efficient union. There is an example of literally what you describe in the docs, if you want to union a lot of shapes together.

That will speed things up, not sure by how much.

@velipso velipso closed this as completed May 6, 2019
@bluenote10
Copy link

I've had a brief look at both implementations, and it looks like there are other difference that affect performance:

  • The other repo is based on the 2013 version of the algorithm, this implementation here on the 2008 version (too bad the 2013 is behind a paywall -- I've no idea how different they are conceptually).
  • The other implementation uses splay trees for the sweep status and priority queues for maintaining the events. This implementation here is a bit simpler, because it uses linked lists with insertion sort for both -- so there is probably a O(log N) vs O(N) difference here.
  • It should be mentioned though that the other implementation has quite a lot of open issues in terms of wrong behavior. I have checked many of them, and the polybooljs implementation handles them all correctly. So maybe it is also the more accurate / robust handling of edge cases (or the precision mode).

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

No branches or pull requests

3 participants