如何使用node-express将Geojson响应存储到Postgres数据库中?

时间:2018-03-02 04:37:02

标签: node.js postgresql express postgis geojson

注意: Geojson响应包含坐标数据类型,需要将其作为几何数据类型存储在Postgres中。

我不想在Postgis中使用任何第三方软件,如Qgis或ArcGIS,或命令行工具,如geojson2psql。

1 个答案:

答案 0 :(得分:0)

使用jsonb列。

使用->运算符查询特定属性的jsonb列很简单。例如,假设列名为“地理数据”,此查询:

SELECT geodata->'geometry'->'coordinates' AS coords FROM geo_example;

...将从我从Leaflet抓取的GeoJSON示例中返回 [ - 104.99404,39.75621]

{
    "type": "Feature",
    "properties": {
        "name": "Coors Field",
        "amenity": "Baseball Stadium",
        "popupContent": "This is where the Rockies play!"
    },
    "geometry": {
        "type": "Point",
        "coordinates": [-104.99404, 39.75621]
    }
};

这是一个显示几个例子的SQL Fiddle