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
fix stitching #1
Conversation
Are we using the same dataset? I can't seem to find the exact same features on my map. However, there are two things to note:
geo computation is always challenging because of topological problems such as these. We have a similar difficulty for geoVoronoi (see d3/d3#1820 and the not-very-satisfying solution at https://github.com/Fil/d3-geo-voronoi). I think it would be very useful to work and adapt d3.contour to create a geoContour algorithm, but I would be surprised if it was straightforward. The solutions presented here feel a bit hack-ish. |
Agree about the not straigtforward algorithm of the stitching and +1 for a geoContour algorithm ! |
Here is a piece of lines to duplicates columns (considering the array as modulo 360). values = nj.array(values).reshape(jsize,isize); // a matrix with n rows and m columns, shape will be [n,m]. values = values.slice([null, null, -1],null); values = nj.concatenate(values.slice(null,[isize-1,isize]), values); values = nj.concatenate(values, values.slice(null,[1,2])); values = values.flatten().tolist(); You have then an array 362, 180 where contours on antimeridian should be smoother since columns at start and end have their neighbour columns. Then comes some cooking to deal only with correct columns that are from 1 to 361. function invert(d) { var shared = {}; var p = { type: "Polygon", coordinates: d3.merge(d.coordinates.map(function(polygon) { return polygon.map(function(ring) { var ring2 = []; for (i = 0; i < ring.length; i++) { if (ring[i][0] < 1) ring2.push([- 180, 90 - ring[i][1] / jsize * 180]); else if (ring[i][0] > 361) ring2.push([180, 90 - ring[i][1] / jsize * 180]); else ring2.push([(ring[i][0]-1) / isize * 360 - 180, 90 - ring[i][1] / jsize * 180]); } return ring2.slice(); }); })) }; That was the direction I was taken before your proposition. |
…at32Array while we're at it.
… of dots near the poles, and give a simpler geojson (for faster interactive rotations). Note: this does _not_ solve the cusps at [9,88] and [10,86].
I think the example is good now. I've also pushed another commit that uses topojson.simplify to remove some dots (especially near the poles where the density is really unnecessarily high). It allows better interactive rotations by making them faster — but it does not solve the cusps at [9,88] and [10,86]. Next step will be to abstract all this code into a d3.geoContour() function. |
I've also worked on an Observable notebook, in which I wrapped the code differently and got rid of numjs. It makes nice images, but it would help if I knew where the data comes from and what it represents :-) Also I'm not always sure of how to read the data. For example datasource 3 is still a mystery. |
netCDF files used in the repo come from http://ferret.pmel.noaa.gov/Ferret/documentation/users-guide/introduction/SAMPLE-DATA-SET (ferret is a very common and easy tool to explore model output and netCDF files).
I have made those extraction because the reading of the netCDF files using netCDFjs is not as flexible as I expected. See cheminfo/netcdfjs#14 |
Thank you for all your input. |
I've added the rotation with d3-inertia in https://beta.observablehq.com/@fil/netcdf |
Any suggestions to display the array with the value for each pixel raster as in http://geoexamples.com/d3-raster-tools-docs/plot/drawing-raster-data.html |
Yes :) I'm currently developing a system for exactly that, based on WebGL.
It's not public yet but soon, I hope.
|
See d3/d3-contour#25