自然地球数据铁路地图中的伪像 [英] Artifacts in Natural Earth Data railroad map

查看:111
本文介绍了自然地球数据铁路地图中的伪像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我浏览了Mike Bostock的让我们制作地图教程,我对此感到非常满意结果我决定从自然地球"数据集中添加一些铁路数据.

I ran through Mike Bostock's Let's Make a Map tutorial and I was so pleased with the results I decided to add some railroad data from the Natural Earth data set.

大多数都可以,但是有些疯狂的工件似乎将无关的网格以某种方式连接在一起:

Most of it renders okay, but there are some crazy artifacts where it seems unrelated meshes are somehow being connected together:

https://docs.google.com/file/d/0B6e2rOpUwmtea3d4enNjY3dSbkk/edit?usp = sharing

我将rail数据分为3个文件,看是否有助于解决该问题:

I separated the rail data into 3 files to see if that would help fix the problem:

for country in CAN MEX USA
do
    ogr2ogr -f GeoJSON \
    -where "sov_a3='${country}'" \
    railroads_${country}.json ne_10m_railroads_north_america.shp
done

我正在使用topojson.mesh渲染它们,如下所示:

I'm rendering them using topojson.mesh as follows:

svg.append("path")
  .datum(topojson.mesh(na, na.objects.railroads_USA))
  .attr("d", path)
  .attr("class", "railroad_USA");
svg.append("path")
  .datum(topojson.mesh(na, na.objects.railroads_CAN))
  .attr("d", path)
  .attr("class", "railroad");
svg.append("path")
  .datum(topojson.mesh(na, na.objects.railroads_MEX))
  .attr("d", path)
  .attr("class", "railroad");

否则,我的代码实际上与演示中提供的代码相同.

Otherwise my code is virtually identical to that provided in the demo.

如何摆脱这些直线?

推荐答案

解决方案是为每条铁路创建单独的路径.一个文件就足够了:

The solution is to create a separate path for each railroad. A single file is sufficient:

ogr2ogr -f GeoJSON \
    -where "sov_a3 in ('CAN', 'MEX', 'USA')" \
    railroads.json ne_10m_railroads_north_america.shp

代替创建单个网格,可以如下创建多个路径:

Instead of creating a single mesh, multiple paths can be created as follows:

svg.selectAll(".railroad")
  .data(topojson.feature(na, na.objects.railroads).features)
.enter().append("path")
  .attr("class", function(d) { return "railroad " + d.id; })
  .attr("d", path);

这篇关于自然地球数据铁路地图中的伪像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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