Geojson to node.js中的Topojson

我有一个形状文件在我的postGIS数据库。我已经通过使用下面的代码检索到node.js中的geojson。

var moisql = 'SELECT *, (ST_AsGeoJSON(geom)) from xxx;' 

工作正常..但我的要求是我必须将这个geojson文件转换为“ TOPOJSON ”。

所以我有这个代码:

 topojsonOutput = topojson.topology({'collection': geojsonString}); 

但仍然我检索geojson文件作为输出。请指导我做到这一点..预先感谢。

另外当我GOOGLE了我得到这个代码:

 var collection = {type: "FeatureCollection", features: […]}; // GeoJSON var topology = topojson.topology({collection: collection}); // convert to TopoJSON console.log(topology.objects.collection); // inspect TopoJSON 

但完全我不明白这个..我必须给予什么,以取代function[..]和collections..

PostGIS 2.1.0及更高版本提供PostGIS AsTopoJSONfunction。 另外,还有postgis2geojson转换工具。 你可能想看看它是如何包装ST_AsGeoJSON返回的片段的。

从这里举例。

 var topology = topojson.topology({ collection: { type: "FeatureCollection", features: [ {type: "Feature", geometry: {type: "LineString", coordinates: [[.1, .2], [.3, .4]]}}, {type: "Feature", geometry: {type: "Polygon", coordinates: [[[.5, .6], [.7, .8]]]}} ] } });