d3.js - topojson 安装疑难解答

标签 d3.js shapefile

我是这方面的新手,基本上对自己在做什么一无所知。 (仅供引用,我正在完成本教程: http://bost.ocks.org/mike/map/ )

我正在尝试让 topojson 工作。 我已经成功安装了自制软件和节点。 我已经完成了 “npm install -g topojson”部分也是如此。

然后,在那之后,当我尝试输入“which ogr2ogr”等时——只是,没有任何反应。 他说如果在编辑路径变量环境时遇到问题。我对这意味着什么只有一个模糊的想法,不确定这是否是我的问题。

让我知道您还需要什么其他信息。我真的只想制作一张 map 。全局安装似乎确实有效。我只是不知道从这里开始做什么。

最佳答案

您链接到的教程是一个很好的起点。我希望我在尝试自己解决所有问题之前看到它。 :)

据我了解,您可能错过了安装 gdal 的步骤。如果您看到其他一些错误,请将它们张贴在您的问题中。

你可以通过运行 ogr2ogr 来工作:

brew install gdal

这里为您提供一些背景信息,以便您更好地了解那里发生的事情。

topojsonogr2ogr 是两个不同的实用程序。 ogr2ogrgdal 的一部分包,在我们的例子中用于从 shapefile 生成 GeoJSON。

GDAL is a translator library for raster geospatial data formats that is released under an X/MIT style Open Source license by the Open Source Geospatial Foundation. As a library, it presents a single abstract data model to the calling application for all supported formats. It also comes with a variety of useful commandline utilities for data translation and processing.

TopoJSON 用于压缩先前 GDAL 转换的相当大的 GeoJSON 输出。它通过用弧而不是离散点指定路径来减少冗余。实际上,它非常简洁:

TopoJSON is an extension of GeoJSON that encodes topology. Rather than representing geometries discretely, geometries in TopoJSON files are stitched together from shared line segments called arcs. TopoJSON eliminates redundancy, offering much more compact representations of geometry than with GeoJSON; typical TopoJSON files are 80% smaller than their GeoJSON equivalents. In addition, TopoJSON facilitates applications that use topology, such as topology-preserving shape simplification, automatic map coloring, and cartograms.

这两个步骤(shapefile -> GeoJSON -> TopoJSON)的输出将是一个 JSON 字符串,它很容易被 JavaScript 解释。您需要在绘图代码中使用 topojson 以转换回 GeoJSON 以实际绘制 map 。

Recall from earlier the two closely-related JSON geographic data formats: GeoJSON and TopoJSON. While our data can be stored more efficiently in TopoJSON, we must convert back to GeoJSON for display. Breaking this step out to make it explicit:

var subunits = topojson.object(uk, uk.objects.subunits);

关于d3.js - topojson 安装疑难解答,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14173853/

相关文章:

javascript - JSON 无法正确加载

node.js - 如何使用nodejs、d3和jsdom修改基于svg的dom的内容?

java - 使用 WhirlyGlobe 显示 ShapeFiles

java - Geotools 解决方案读取 EPSG3035 中的 shapefile 以在 WGS84 中获取长/纬度?

geojson - GDAL,ogr2ogr "Cannot find proj.db"错误

python - 使用networkx.algorithms.approximation.steinertree.steiner_tree提取斯坦纳树时出错

r - 将数据框附加到 shapefile 并绘制它

javascript - D3Js 圆环图,避免标签文本叠加

javascript - 在动态创建的 div 上绘制多个 NVD3.js 图表的问题

javascript - D3 强制布局节点属性未正确更新