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



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

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

使用 jsonb 列。

使用 -> 运算符查询特定属性的 jsonb 列很简单。例如,假设列名为"geodata",则此查询:

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

。将从我从传单中抓取的这个 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 小提琴,展示了几个示例。

最新更新