block by fil ccd7c00f6ee97f388503c7ebaae07384

Extract a band from a Contour Plot [UNLISTED]

Full Screen

Contour plots generated by d3-contour overlay shapes (Multipolygons) of increasing value. To obtain the shape that is between two values a < b, we need to substract the shape B = contour(b) from the shape A = contour(a).

The substraction algorithm for this case is then much simpler than a generic Multipolygon intersection/substraction:

For each polygon in multipolygon B, take a point from its outer ring. Then find the polygon of A that contains this point, and add that ring as a hole (which implies a reversal of its coordinates). Plus, add holes of B as polygons to A.

But I’m not sure this covers all cases, that is, what happens when a hole of A is inside a hole of B?

A simpler method works OK if one wants to extract 1 band (http://bl.ocks.org/Fil/94d4df7520ffc8434c40fe9b82ebd536), but it is useless if you need to extract several contiguous bands, as it does not give an exact boundary (there are gaps and overlaps, cf http://bl.ocks.org/Fil/3f866e2e90c3e019bfe3fd9e0d43fe14).

Forked from mbostock‘s block: Contour Plot

index.html