Large geojson to topojson

百般思念 提交于 2020-01-17 06:41:52

问题


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

and also the following command for simplification:

geo2topo test.json > test.topojson -q 10000

Both of them produce the same following error:

buffer.js:503 throw new Error('"toString()" failed'); ^

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)

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.


回答1:


Unaware of the actual errors being thrown I do have suggestions:

Maybe you can make use of ndjson? Like ndjson-split 'd.features' < test.json > test.ndjson. That way you could break down your file to smaller parts or get rid of unnecessary features via ndjson-filter.




回答2:


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.

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

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

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



来源:https://stackoverflow.com/questions/43514816/large-geojson-to-topojson

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!