'How to get GDAL/ogr2ogr to output GeoJSON as feature-per-line instead of a formatted FeatureCollection?

I'm trying to convert some Very Big Shapefiles into GeoJSON so that I can run them through tippecanoe and create a .mbtiles to upload to Mapbox Studio for hosting and styling.

I can use ogr2ogr to create my GeoJSON file just fine, however it outputs a FeatureCollection with nice formatting. What I want is a .json file with one feature per line, so that I can use the 'Parallel processing of input' feature of Tippecanoe and speed up creation of my .mbtiles.

Question 1: Is there a way to do this simply with ogr2ogr? I can't seem to find a relevant option in the GDAL GeoJSON driver docs.

Question 2: Alternatively, could ogr2ogr output a GeoJSON text sequence instead of a FeatureCollection file?



Solution 1:[1]

If you make an array of the ids or any other attribute in your Shapefile, you could loop through this list and use the ogr2ogr --where option to export features one by one. See also this example https://gis.stackexchange.com/questions/35296/how-to-use-where-sql-in-an-ogr2ogr-loop-in-gdal-ogr-bash#35297

Solution 2:[2]

Q1. Well, you can extract the individual features with the help of a UNIX tool - jq.

    jq --compact-output ".features" input_featurecollection.geojson > output_features_only.geojson

This will have each record as a separate geojson feature

Q2 you can pipe in your input geojson file to this command and echo the output.

Solution 3:[3]

You can use ogr2ogr to output a geojson sequence as you suggested in question 2 @craigsnyders:

ogr2ogr -f GeoJSONSeq -t_srs EPSG:4326 output.json input.shp

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Leonmvd
Solution 2 Shree
Solution 3 Zachary Deziel