0

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.

1
  • 1
    What's your table look like? Do you have a geom column? Do you have PostGIS installed? Do you know about the PostGIS method ST_GeomFromGeoJSON? This is actually a better question to ask on gis.stackexchange.com Commented Mar 5, 2018 at 4:49

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you. This may work. But I need to store data in Postgres DB only of type geometry, instead of jsonb. I cannot alter my table now. Need node implementation if possible.
Can you update your question and include your table's definition? At least the column you're looking to insert into.
is there any documentation, example anything for inserting data in to a Point type column in postgress with a rest API. I mean something I could test with postman ??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.