简体   繁体   中英

How can I store Geojson response into Postgres Database using node-express?

NOTE: Geojson response contains coordinates datatype, which needs to be stored in Postgres as geometry datatype.

I don't want to use any 3rd party software like Qgis or ArcGIS, or command line tool such as geojson2psql in Postgis.

Use a jsonb column.

It's simple to query a jsonb column for specific attributes, using the -> operator. For example, assuming a column name of "geodata", this query:

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

...would return [-104.99404, 39.75621] from this GeoJSON example I grabbed from Leaflet :

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

Here's a SQL Fiddle showing a couple examples.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM