d3 / d3-geo-projection

Extended geographic projections for d3-geo.
https://observablehq.com/collection/@d3/d3-geo-projection
Other
1.1k stars 201 forks source link

Problem with projection and geoJSON? #116

Closed gbazin-eso closed 7 years ago

gbazin-eso commented 7 years ago

Hi,

I have an issue with the representation of a geoJSON file. It seems that the contours are, in some cases (depending on the rotation), misinterpreted and inner/outer regions are mixed up. See the attached screenshots and the codepen https://codepen.io/anon/pen/wdYmqL where you can manually rotate the projection.

Do you think it is an intrinsic problem of geoJSON, a projection-related problem, or a anything wrong in my example? Thanks!

mw_nopb mw_pb

mbostock commented 7 years ago

Hmm. Well, partly this is expected when you have an orthographic projection where the clip angle is not 90° so the back hemisphere is visible:

untitled 6

If you want to display the whole earth, I think you want to set the clip angle to 180° rather than using antimeridian clipping, if you aren’t already, since you won’t want a cut along the antimeridian.

var projection = d3.geoOrthographic()
    .scale(radius)
    .clipAngle(180);

That seems to fix some of the transient winding order issues, but, it looks like there are other winding order issues, probably because the topology is more interesting with the milky way shape than typical continents.

untitled 7

See the winding order bl.ock for details. You probably need to reverse one (or more) of the rings in the GeoJSON to fix the winding order problem, but I think you’ll have to figure that out by hand. I might look later if I have time.

mbostock commented 7 years ago

Here’s a fixed-ish version:

https://bl.ocks.org/mbostock/15a373ce034cbc4ad604767c0eac05cb

image

gbazin-eso commented 7 years ago

Hi,

Indeed. Thank you very much for your help!

Regards, G.

gbazin-eso commented 7 years ago

Hi Mike,

Sorry to re-open that. In your example, you use a canvas and it seems that it is not so convenient to use with d3.js. In particular, we want to manipulate many svg elements on top of the milky way. Would you have a solution which works without the canvas? Thanks ;)

Best regards, G.

P.S. BTW, d3-celestial https://github.com/ofrohn/d3-celestial (e.g. http://armchairastronautics.blogspot.de/p/skymap.html) shows the same problem with the milky way in orthographic projection.

mbostock commented 7 years ago

Please use Stack Overflow tag d3.js to ask for help. Although I make an effort to assist everyone that asks, I am not always available to provide help promptly or directly. Stack Overflow provides a better collaborative forum for self-help: tens of thousands of D3-related questions have already been asked there, and some answered questions may be relevant to you.

When asking for help, please include a link to a live example that demonstrates the issue, preferably on bl.ocks.org. It is often impossible to debug from code snippets alone. Isolate the issue and reduce your code as much as possible before asking for help. The less code you post, the easier it is for someone to debug, and the more likely you are to get a helpful response.

If you have a question about D3’s behavior and want to discuss it with other users, also consider the d3-js Google Group or joining the d3-js Slack.

Thank you! 🤗