d3-geo-polygon
d3-geo-polygon copied to clipboard
Easier usage with d3.geoProject?
It’d be nice if this library were easier to use when saving spherically-clipped GeoJSON. For example:
https://beta.observablehq.com/d/d706c7f9c6e46907
The tedious parts are:
-
You need to wrap the d3.geoClipPolygon instance with an object that has a stream method.
-
You need to compose the d3.geoClipPolygon instance with streams that transform from degrees to radians and then back again.
Part of me wonders if it’s worth revisiting a more composable geographic projection pipeline…
(Also, I think d3.geoProject sometimes breaks polygon semantics, but that’s a separate issue.)
Yes; it would be nice to have this also for clipAngle — in your notebook it works by using:
{
const clipAngle = d3.geoClipCircle(50/180*Math.PI);
return d3.geoProject(land, {stream: stream => radians(clipAngle(degrees(stream)))});
}
(So maybe an issue to solve in d3-geo-projection rather than d3-geo-polygon.)
We should also account for rotation.
Since your code is working, is it not just a question of defining a syntax?
The polygon issue is similar to https://github.com/d3/d3-geo-projection/pull/146#issuecomment-415946484 : d3.geoProject is not meant to be used to project to spherical coordinates.
Yep, an issue of syntax and abstraction. I would love to revisit the composable geographic projection pipeline idea. I wonder if there is some progress to be made there.