问题
Is it possible to draw a buffer (another feature) around a geographic feature in d3.js as a fixed distance unit (kilometers or miles)?
For instance, how would I draw a path around a point that extends 25 miles from that point in every direction. I've tried using d3.geo.circle and passing a fraction of degree (25 miles / approximately 69 miles per latitudinal degree or 25 / 69) but realize that although d3.geo.circle handles the reprojection of degrees, it does not accommodate for the differing lengths of each longitudinal degrees.
buffer = d3.geo.circle().angle(25/69).origin(function(x, y) { return [x, y]; })
I'm borrowing from this:
http://bl.ocks.org/mbostock/5628479
Update:
It looks like what I'd like to do is create a geodesic buffer.
Update:
I was able to create the buffer by drawing a path from a series of destination points given a distance and bearing from a start point.
See http://www.movable-type.co.uk/scripts/latlong.html for JavaScript implementation
Like this:
function drawBuffer(lat, long, distance){
var intervals = 18;
var intervalAngle = (360 / intervals);
var pointsData = [];
for(var i = 0; i < intervals; i++){
pointsData.push(getDestinationPoint(lat, long, i * intervalAngle, distance));
}
// Draw path using pointsData;
}
回答1:
AFAIK doing this in D3 itself would be quite painful, as it's not really meant to create/modify features. I would recommend doing this as a preprocessing step in a GIS program such as QGIS, which allows you to buffer features in a number of ways. From there, you can export as GeoJSON and use with D3 in the usual way.
回答2:
I was able to create a buffer around a point by drawing a path from a series of destination points given a distance and bearing from a start point.
See http://www.movable-type.co.uk/scripts/latlong.html for JavaScript implementation
Like this:
function drawBuffer(lat, long, distance){
var intervals = 18;
var intervalAngle = (360 / intervals);
var pointsData = [];
for(var i = 0; i < intervals; i++){
pointsData.push(getDestinationPoint(lat, long, i * intervalAngle, distance)); // See link
}
// Draw path using pointsData;
}
来源:https://stackoverflow.com/questions/20130186/d3-geo-buffer-around-a-feature