On Mon, May 19, 2014 at 06:46:14PM -0300, Gonzalo Bellver wrote:
> Will d3.geom.polygon.area consider clipping? Some of the polygons are
> clipped with a clipPath...
Sorry, I missed that you were using an SVG clipPath.
It’s not that straightforward to do this at the moment for general
clipping paths. D3’s d3.geom.polygon.clip is an implementation of the
Sutherland–Hodgman algorithm, which only supports convex clip polygons,
and thus we can’t use the projected geographic boundary as the clip
polygon at the moment.
Forunately, we can exploit the fact that Voronoi regions are guaranteed
to be convex, and instead we can use each Voronoi region as a clip
polygon in turn, and clip the projected geographic boundary instead.
(Clipping is simply an intersection operation on shapes, so we can swap
the clip and subject polygons easily).
I’ve modified your example here:
http://bl.ocks.org/jasondavies/d70baf034448ef7a52d1
I’m also extracting the projected geographic boundary using a custom
stream to ensure we get any resampled points, but it would work just as
well without this due to the resolution of the data.
Note that we’re computing the projected (mercator) area here. This is
not really an issue for this example due to the scale, which means the
area distortion is very low, but it’s something to be conscious of when
reusing this method in other contexts, in which case an equal-area
projection would be more appropriate.