Given a large file of line delimited geojson:

"type": "FeatureCollection",
"name": "kitten_locations",
"features": [
{ "type": "Feature", "properties": { ...

I would like to populate the target table:

CREATE TABLE kitten_locations (
   data jsonb

I have tried using ogr2ogr, but that splits it out into many columns. I can remove the feature collection bits and just import the objects. However, I am wondering if there is an easier way to populate the jsonb column with the features of the feature collection.

1 Answer 1

  • First import your data with ogr2ogr into mytable

  • Then, insert the features as GeoJSON objects into kitten_locations :

INSERT INTO kitten_locations(data)
SELECT ST_AsGeoJSON(t)::jsonb FROM mytable t;
  • Finally, delete the imported table (with splitted columns)
DROP mytable;

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.