【问题标题】:Geojson to Topojson in node.jsnode.js 中的 Geojson 到 Topojson
【发布时间】:2014-01-13 19:16:48
【问题描述】:

我的 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  

但我完全无法理解这一点..我必须提供什么来代替 features[..] 和 collections..

【问题讨论】:

    标签: node.js postgresql-9.1 postgis topojson


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      取自示例here

      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]]]}}
                ]
              }
            });
      

      【讨论】:

        猜你喜欢
        • 2017-09-16
        • 2013-01-22
        • 2015-03-28
        • 2014-09-02
        • 2015-07-29
        • 1970-01-01
        • 2021-02-08
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多