gpt4 book ai didi

map - d3.js 墨卡托投影到纽约 map

转载 作者:行者123 更新时间:2023-12-04 04:40:58 33 4
gpt4 key购买 nike

我正在制作纽约市行政区的 map ,但似乎无法正确投影:我唯一得到的是一张小 map 。

我尝试重新创建 this例如,这只会使控制台因错误而发疯,我怀疑是因为方程式有问题。

当我试图让阿尔伯斯工作时,我尝试了 this 的答案。问题,但我仍然无法使 map 工作。

  With 960/500 height and width, I used: var projection = d3.geo.albers().center([40.71, 73.98]).parallels([29.5, 45.5]).scale(10000).translate([(width) / 2, (height)/2]);

现在,我正在使用横​​向墨卡托,代码如下,以及我使用 these 之一创建的 topojson文件。
  var width = 960,
height = 500;

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

d3.json("nyc-borough.json", function(error, nyb) {

var boroughs = topojson.feature(nyb, nyb.objects["nyc-borough-boundaries-polygon"]).features;

var projection = d3.geo.transverseMercator()
.scale(1600)
.rotate([73 + 58 / 60, -48 - 47 / 60]);

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

var g = svg.append("g");

g.append("g")
.attr("id", "boroughs")
.selectAll(".state")
.data(boroughs)
.enter().append("path")
.attr("class", function(d){ return d.properties.name; })
.attr("d", path);

});

拜托,请停下来:(

提前致谢!

最佳答案

我与纽约市行政区创建了一个 bl.ock here .正如 QGIS 中的快速检查所示,您使用 WSG84/Mercator 走在正确的道路上,因为这就是原始数据所在的位置。

QGIS检查数据的中心也很好,结果还是 [-73.94, 40.70]。请注意,这些与您的 lat 和 long 坐标相反,但 d3 需要 long 和 lat,如 API 中所述。 .另一件需要注意的事情是负面的。北为正,因此北半球的纬度为正,南半球的纬度为负。对于东半球和西半球,其东为正值。当然,这仅适用于美国阿尔伯斯不会对美国产生负面影响的全局预测。哦,如果不查看 Jason Davies work,就没有关于投影的讨论是完整的。 .

如果您想对您的数据所在的投影使用不同的投影,我通常认为最好将您的数据预处理为该投影,而 QGIS 是一个很好的工具,但还有许多其他工具,例如 gdal。

关于map - d3.js 墨卡托投影到纽约 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18920345/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com