如何使用投影使 d3.js 中的绘图点变得平滑?

use*_*855 5 javascript gis dictionary map-projections d3.js

我可以使用以下代码将一些天气数据绘制到地图上。然而这些点是矩形,我想让它们更平滑。

绘制矩形,

我想将它们绘制得更平滑,就像类似的东西理想情节点

我相信我需要研究插值、空间分析和/或等值线图。我认为他们在这样做时使用了不同的算法。我觉得我需要在现有的点之间填写更多点?这样就可以制作类似渐变的点吗?这在D3中可行吗?或者我应该考虑使用 Three.js 或 WebGL 的东西?

var width = 960,
height = 960;

var map = {};
var projection = d3.geo.mercator()
.scale((width + 1) / 2 / Math.PI)
.translate([width / 2, height / 2])
.precision(.1);

var path = d3.geo.path()
.projection(projection);

var graticule = d3.geo.graticule();

var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);

svg.append("path")
.datum(graticule)
.attr("class", "graticule")
.attr("d", path);

d3.json("world-50m.json", function(error, world) {
 svg.insert("path", ".graticule")
  .datum(topojson.feature(world, world.objects.land))
  .attr("class", "land")
  .attr("d", path);

svg.insert("path", ".graticule")
  .datum(topojson.mesh(world, world.objects.countries, function(a, b) { return a !== b; }))
  .attr("class", "boundary")
  .attr("d", path);
});

map.plot_points = [];
map.max = 30;
map.min = -1;
var opacity = d3.scale.linear()
 .domain([map.min, map.max])
 .range([0,1]);  
var rainbow = ["#CE0C82", "#800CCE", "#1F0CCE", "#0C5BCE", "#0C99CE", "#2ECE0C", "#BAE806", "#FEFF00", "#FFCD00", "#FF9A00", "#FF6000", "#FF0000"];
zs.forEach(function(zv,zi){
    zv.forEach(function(zzv, zzi){
        if(zzv != 999)
            {
                map.plot_points.push({lat: ys[zi], long:xs[zzi],value:zzv});
            }

        })
});
console.log(map);
var points = svg.selectAll("rects.points")
 .data(map.plot_points)
 .enter()
 .append("rect")
 .attr("class", "points")
 .style("fill", function(d) {
   var scale = d3.scale.linear().domain([map.min, map.max]).range([1, rainbow.length]);
        return rainbow[Math.round(scale(d.value))]; 
}).attr("width", 8)
.attr("height", 8)
.style("fill-opacity", 1)
.attr("transform", function(d) {
        return "translate(" + projection([d.long, d.lat]) + ")";
})
Run Code Online (Sandbox Code Playgroud)

Lar*_*off 2

听起来你的情况的问题是数据。您需要做的就是获取原始数据并将其插值为更平滑的形式。为此,您可以使用 GIS 程序,例如QGIS。具体如何执行取决于原始数据的格式。

一旦获得更平滑的数据,您可以在 D3 中再次绘制它。我的猜测是,最终结果会有点类似于我在这里所做的,其中绘制的轮廓线与您的目标效果大致相同。