本文介绍了大型geojson到topojson的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将相对较大的geojson文件(383 MB)转换为topojson以与D3.js结合使用.我在Macbook Pro 2016上运行以下命令:

I am trying to convert a relatively large geojson file (383 MB) to topojson to use it with D3.js. I am running the following command on a mac book pro 2016:

geo2topo test.json > test.topojson

以及以下简化命令:

geo2topo test.json > test.topojson -q 10000

它们两个都产生相同的以下错误:

Both of them produce the same following error:

错误:"toString()"失败 在Buffer.toString(buffer.js:503:11) 在JSON.parse() 在ReadStream. (/usr/local/lib/node_modules/topojson/node_modules/topojson-server/bin/geo2topo:107:46) 在emitNone(events.js:91:20) 在ReadStream.emit(events.js:188:7) 在endReadableNT(_stream_visible.js:975:12) 在_combinedTickCallback(内部/进程/next_tick.js:80:11) 在process._tickCallback(internal/process/next_tick.js:104:9)

Error: "toString()" failed at Buffer.toString (buffer.js:503:11) at JSON.parse () at ReadStream. (/usr/local/lib/node_modules/topojson/node_modules/topojson-server/bin/geo2topo:107:46) at emitNone (events.js:91:20) at ReadStream.emit (events.js:188:7) at endReadableNT (_stream_readable.js:975:12) at _combinedTickCallback (internal/process/next_tick.js:80:11) at process._tickCallback (internal/process/next_tick.js:104:9)

我查看了各种线程,例如这一个,但没有找到任何解决方案.请注意,geojson本身的格式正确,可以在d3.js中加载,但是由于其大小无法在Web应用程序中使用.

I looked at various threads like this one but haven't found any solutions. Please note that the geojson itself is properly formatted and can be loaded in d3.js, but due to its size cannot be used in web applications.

推荐答案

我昨天遇到了同样的问题.具体来说,v8引擎无法读取大于256Mb的字符串.由于加载geojson的第一步是将其读取并解析为json,因此无法正常工作.

I hit the same problem yesterday. Specifically, the v8 engine can't read strings larger than 256Mb. Since the first step of loading the geojson is to read and parse it as a json, that doesn't work.

但是,一个好主意将节点实现移植到了python:

However, a good soul ported the node implementation to python:

https://github.com/calvinmetcalf/topojson.py

由于python没有这个限制,因此您可以使用此代码创建topojson,然后对它进行任何操作.

Since python doesn't have that limitation, you can use this code to create the topojson, then do whatever you want with it.

这篇关于大型geojson到topojson的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 07:54