riatelab/bertin

Feature with self-intersections won't render properly

Closed this issue ยท 15 comments

I'm trying to render topojsons downloaded via the Cartiflette library.

Some of them (here, Normandy) won't render properly with Bertin.js.
image

Once simplified via topojson.simplify, they do render as expected.
image

Plot will also display them as expected:
image

QGIS reports some of the features as having self-intersections, which I guess is what causes the problem in Bertin, but as it's a rather common defect, it would be nice if Bertin could manage to display them anyway.

Minimal repro here: https://observablehq.com/d/01779a4ad998a10b

More examples can be found in this notebook: https://observablehq.com/d/673577af814d80cd

A passage through rewind by @Fil can do the trick.
Maybe Plot.geo do it by default.

mthh commented

Indeed, rewind can do the trick, and I think this is also in the works for Bertin as a rewind function has been added to neocarto/geotoolbox very recently ๐Ÿ‘

Fil commented

Plot does not apply rewind by default. It only works in your Plot example because you've made the projection to fit the mesh.

@Fil oh I see ! I still think it would be nice for Bertin to do it by default, as it's not the first time I encounter the problem, but let's see what @neocarto says.

Fil commented

Two arguments against:

  1. it's a bit slower than fixing the problem in the geojson, so you don't want to run it by default
  2. some geojson shapes are legitimately "larger than a hemisphere" (the typical example being the ocean)
mthh commented

@Fil I don't want to hijack this discussion thread (as the answer I'm looking for is probably in one of your explanations in a notebook or in a d3-geo issue), but is it necessarily a problem to apply rewind to polygons larger than the hemisphere?

In Magrit we apply rewind by default and we have no problem to display the ocean layer of the notebook you linked.

I did the test just to be sure, and rewind does indeed fix the problem: https://observablehq.com/d/e387c527b779b40c

it's a bit slower than fixing the problem in the geojson

I'll try to find the exact source of the problem in this case (the geojson comes from AdminExpress Carto, but by loading directly the source shape file, I don't see self-intersection errors in QGIS, I've got to check what other transformations are done. (cc: @linogaliana))

But the point is, those files do exist, and it's a bit disapointing when you are trying to display them and they just don't render properly, and people won't know what they have to do to make them work.
Maybe a boolean flag would do the job -- Bertin already has 'clip', for a similar issue.

Fil commented

@mthh try with with this one: https://observablehq.com/@fil/ocean/2

Magrit shows the land in grey instead of the ocean.

mthh commented

@Fil I'm still seeing the ocean being colored and the land being representend as hole (as expected)

export(1)

Fil commented

I've tried again and it's not what I get :)

open https://magrit.cnrs.fr/ > new project > add a basemap > layout layer "ocean.json" > wait two minutes > "Layer successfully added to the map" > the land is gray. And when I click on "feature information" the cursor on land shows me "ocean_1".

mthh commented

My bad, I was still using the "ocean.json" from your first ocean notebook !
You're indeed totally right about the ocean.json from your second ocean notebook.

Fil commented

Note that @fil/rewind is "smarter" than mapbox/geojson-rewind, in the sense that if there is a polygon with hole, it checks if the outer ring contains the first point of the hole, and doesn't invert the polygon. So this second ocean.json file would not break. (The only case where it can not decided is a single ring polygon.)

mthh commented

Alright, thanks a lot for explaining the difference between the two !
I'll open an issue on Magrit repository and see how I'll handle it there.

Sorry for the noise on your issue tracker @neocarto ! Hopefully these debates will be useful to you too!

I'm on vacation, thanks for this feedback and discussion. Indeed, I had the intention to improve the imports of geojson with notably the rewind fonction from mapbox. Cf this notebook. https://observablehq.com/d/660137cff3c11502
Maybe we can work together for Bertin and Magrit ? With fil's rewind ?

A solution is proposed in bertin@1.6.5. In each layer, we can use rewind = true. See https://vis.social/@neocarto/110027972115777708