Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
224 views
in Technique[技术] by (71.8m points)

javascript - Large geojson to topojson

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...