d3 / d3-geo-polygon

Clipping and geometric operations for spherical polygons.
https://observablehq.com/collection/@d3/d3-geo-polygon
Other
107 stars 22 forks source link

Use clipPolygon for geoInterrupted #17

Closed Fil closed 3 months ago

Fil commented 6 years ago

example code that works (at least in one test case):

var c = projection.lobes().map(d => d3.merge(d.map(q => {
  var centroid = d3.geoCentroid({type:"MultiPoint", coordinates:q});
  return q.map(p => d3.geoInterpolate(p,centroid)(1e-7)); // pull inside each lobe
})));
c = d3.merge([c[0], c[1].reverse()]); // north, south
projection.preclip(d3.geoClipPolygon({ type: "Polygon", coordinates: [c] }));
capture d ecran 2018-04-19 a 09 31 17

the projection was defined by:

    var lobes = [
      [
        [[-180, 0], [-130, 90], [-95, 0]],
        [[-95, 0], [-30, 90], [55, 0]],
        [[55, 0], [120, 90], [180, 0]]
      ],
      [
        [[-180, 0], [-120, -90], [-60, 0]],
        [[-60, 0], [20, -90], [85, 0]],
        [[85, 0], [140, -90], [180, 0]]
      ]
    ];
    projection = d3.geoInterrupt(d3.geoHomolosineRaw, lobes).rotate([-204, 0])
    .fitExtent([[10, 10], [width-10, height-10]], {type: "Sphere"});
Fil commented 6 years ago

Solved in https://observablehq.com/@fil/interrupted-projections-polygon-clipping for all "interrupted" projections of d3-geo-projection, including HEALPix.

Fil commented 6 years ago

Have to think about how to integrate this — I'd rather not duplicate all the code from geo-projection, but for users I want it to be as simple as adding d3-geo-polygon to their sources (like we have for the polyhedral projections).