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

Switch to martinez clipper #2

Closed
wants to merge 5 commits into from
Closed

Switch to martinez clipper #2

wants to merge 5 commits into from

Conversation

bhousel
Copy link
Contributor

@bhousel bhousel commented Jan 31, 2020

Ok, so this is promising. It's fast and small, but I am running into some of the unioning issues reported in the martinez repo:

JSTS/Turf

Screenshot 2020-01-31 15 50 54

Martinez

Screenshot 2020-01-31 15 49 33

I have a feeling w8r/martinez#115 might fix this, so I'm going to leave this work on a branch and wait for martinez to get an update. It's great to see that there is active work being done!

@quincylvania
Copy link

Simply the best feeling:

Screen Shot 2020-02-03 at 9 48 24 AM

bhousel added a commit that referenced this pull request Jun 6, 2020
(closes #10, closes #11)

Newer versions of Turf are using a broken clipper, so we're keeping
it pinned to the older version until #1 / #2 shapes up
@bhousel
Copy link
Contributor Author

bhousel commented Aug 14, 2020

I updated this branch to have the latest code from master as well as updating martinez-polygon-clipping to 0.7.0, but still seeing some artifacts. I'm not surprised, as there are open issues upstream for things like this..

Screen Shot 2020-08-14 at 5 50 17 PM

@quincylvania
Copy link

@bhousel Are there tweaks we could make to the data to work around the martinez bugs? Things to avoid? I'd be happy to sacrifice some space efficiency in order to drop JSTS.

@bhousel
Copy link
Contributor Author

bhousel commented Aug 16, 2020

@bhousel Are there tweaks we could make to the data to work around the martinez bugs? Things to avoid? I'd be happy to sacrifice some space efficiency in order to drop JSTS.

I don't think so.. We can probably always invent situations where the country coder geometries will intersect this way.

It looks like w8r/martinez#115 didn't actually merge yet, and there are some related issues in the comment thread that it would also fix, so I wonder if I could spend time on that to finish it up..

@bhousel
Copy link
Contributor Author

bhousel commented Aug 19, 2020

I dug in a bit more today and learned a few things.

The clipping might be ok. The rendering artifacts are probably caused by a mapbox-gl / earcut issue

The locationSet that I'm testing is:
{ include: ['039', '015'] }

This is the "Southern Europe + Northern Africa" example:
https://ideditor.github.io/location-conflation/?locationSet=%7B%20include%3A%20%5B%27039%27%2C%20%27015%27%5D%20%7D

The region around the Canary Islands does this:

Screen Shot 2020-08-19 at 4 34 22 PM

But it looks fine on https://geojson.io:
Screen Shot 2020-08-19 at 4 36 25 PM

So I reduced it to this simpler test case:

{
  "type": "Feature",
  "properties": {},
  "geometry": {
    "type": "MultiPolygon",
    "coordinates": [
      [
        [
          [-15, 40],
          [-15.92339, 29.50503],
          [-8, 32],
          [-7.37282, 36.96896],
          [-15.92339, 29.50503],
          [-25.3475, 27.87574],
          [-17.27295, 21.93519],
          [5.14112, 40],
          [-15, 40]
        ]
      ]
    ]
  }
}

Geojson.io:

Screen Shot 2020-08-19 at 4 38 27 PM

Mapbox GL 1.8:

Screen Shot 2020-08-19 at 4 39 01 PM

Screen Shot 2020-08-19 at 4 38 52 PM

Some more things I want to try

  • Run the result through geojson-rewind ?
  • Do the clipping with integers only (no floating point). I wrote this code today and it's working ok. It's kind of hacky but if it helps I'll leave it in, if not I'll throw it out.

(testing, may revert later)
@bhousel
Copy link
Contributor Author

bhousel commented Aug 20, 2020

ok it's definitely a bad clipping result and not the result of improper winding.

Going to also check out this other alternative library: https://github.com/mfogel/polygon-clipping

@bhousel
Copy link
Contributor Author

bhousel commented Aug 20, 2020

superseded by #20

@bhousel bhousel closed this Aug 20, 2020
@bhousel bhousel deleted the martinez branch September 16, 2020 16:12
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

Successfully merging this pull request may close these issues.

2 participants