d3.js墨卡托投影到纽约地图 [英] d3.js mercator projection to NYC map

查看:670
本文介绍了d3.js墨卡托投影到纽约地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在纽约市的地图制作地图,我似乎无法得到投影权:我唯一得到的是一个小地图。

I am making a map of the boroughs in NYC and I can't seem to get the projection right: the only thing I get is a tiny map.

我尝试重新创建示例,这只是让控制台疯狂的错误,我怀疑,因为有一些关于方程的东西。

I tried recreating this example, which only made the console go crazy with errors, I suspect because there was something off about the equation.

当我试图让albers工作,我试过了回答问题,但我仍无法使地图工作。

When I was trying to get albers to work, I tried out the answer to this question, and still I could not get the map to work.

  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]);

现在,我使用一个横向Mercator,下面的代码和topojson我创建使用个文件之一。

Right now, I am using a transverse Mercator, with the code below, and the topojson I created using one of these files.

  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与纽约市区这里。你在WSG84 / Mercator的正确路径,因为这是原始数据,作为快速检查QGIS演示。

I created a bl.ock with the NYC boroughs here. You were on the right path with WSG84/Mercator as that was what the original data was in, as a quick check in QGIS demonstrated.

QGIS 也是一个很好的检查数据的中心,再次出现的是[-73.94,40.70]。请注意,这些是相反的方式,你的坐标是lat和long,但d3需要long和lat,这里讨论的< a href =https://github.com/mbostock/d3/wiki/Geo-Projections#wiki-_projection =nofollow> API 。另一件需要注意的是否定词。是正的,所以北半球的纬度在南半球是正和负的,东半球和西半球的东是正的。当然,这只对全球预测有影响,美国阿尔伯斯不会对美国有负面影响。如果不查看 Jason Davies的工作,就不会完成关于投影的讨论。

QGIS was also good checking the centre of the data, again which came out to be [-73.94, 40.70]. Note that these are the opposite way round to your co-ordinates which were lat and long, but d3 needs long and lat as discussed here in the API. The other thing to look out for is the negatives. North is positive so latitude in the northern hemisphere is positive and negative in the southern hemisphere. For the east and west hemispheres its east that's positive. Of course this only matters for the global projections the USA Albers wouldn't have negatives for the USA. Oh, and no discussion on Projections would be complete without a look at Jason Davies work.

如果你想使用不同的投影到你的数据投影我一般认为最好是预处理你的数据到那个投影和QGIS是一个伟大的工具,但有很多其他如gdal。

If you want to use a different projection to the projection your data is in I generally think it's better to preprocess your data into that projection and QGIS is a great tool for that but there are many others such as gdal.

这篇关于d3.js墨卡托投影到纽约地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆