4

我的 postGIS 数据库中有一个形状文件。我已使用以下代码将其检索到 node.js 中的 geojson 中。

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

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

所以我有这个代码:

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

但我仍然在检索geojson文件作为输出..所以请指导我实现这一点..提前致谢。

另外,当我用谷歌搜索时,我得到了这个代码:

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

但我完全无法理解这一点..我必须放弃功能[..]和收藏品..

4

2 回答 2

2

PostGIS AsTopoJSON函数可用于 PostGIS 2.1.0 及更高版本。或者,还有postgis2geojson转换工具;您可能想看看它如何包装ST_AsGeoJSON返回的片段。

于 2013-12-27T05:15:21.163 回答
0

取自这里的例子。

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]]]}}
          ]
        }
      });
于 2013-12-26T05:53:23.863 回答